Class UnixCompress

java.lang.Object
com.chilkatsoft.chilkat2.ChilkatObject
com.chilkatsoft.chilkat2.UnixCompress
All Implemented Interfaces:
AutoCloseable

public class UnixCompress extends ChilkatObject
<section class="unixcompress-summary">

Compress, uncompress, and unpack legacy UNIX .Z files.

Chilkat.UnixCompress provides UNIX compress and uncompress functionality for legacy .Z files. It supports file-based, memory-based, and string-based workflows, uses LZW compression, can unpack .tar.Z archives, and includes abort and progress-related support for longer-running operations.

Compress to .Z

Compress files, memory data, or strings into UNIX .Z format using LZW compression.

Uncompress .Z data

Expand UNIX-compressed data back to files, memory, byte arrays, or text depending on the application workflow.

File workflows

Compress and uncompress directly between input and output files when working with existing filesystem data.

Memory workflows

Work with compressed or uncompressed byte data in memory when temporary files are not desired.

String workflows

Compress and uncompress text using an explicit character set so string data round-trips correctly.

Unpack tar.Z archives

Use UnTarZ to decompress and extract legacy .tar.Z archives in a single workflow.

Common pattern: Use UnixCompress when the data is in classic UNIX .Z format or when a .tar.Z archive must be unpacked. Use Chilkat.Gzip for .gz and .tar.gz files, Chilkat.Bz2 for .bz2 files, and Chilkat.Compression for raw compression algorithms and general-purpose compression workflows.

For an extended overview, see UnixCompress Class Overview.

</section>

Event-capable: long-running methods report progress through a ProgressListener installed with setProgressListener(ProgressListener), onAbortCheck(BooleanSupplier), onPercentDone(IntPredicate) or onProgressInfo(BiConsumer).

Instances hold a native Chilkat object: close them with ChilkatObject.close() (try-with-resources) when done; an unclosed instance is freed when it becomes unreachable.

See Also:
Online reference
  • Constructor Details

    • UnixCompress

      public UnixCompress()
      Creates a new UnixCompress object.
  • Method Details

    • getAbortCurrent

      public boolean getAbortCurrent()
      When set to true, causes the currently running method to abort. Methods that always finish quickly (i.e.have no length file operations or network communications) are not affected. If no method is running, then this property is automatically reset to false when the next method is called. When the abort occurs, this property is reset to false. Both synchronous and asynchronous method calls can be aborted. (A synchronous method call could be aborted by setting this property from a separate thread.)
      Returns:
      the value of the AbortCurrent property
    • setAbortCurrent

      public void setAbortCurrent​(boolean value)
      Sets the AbortCurrent property; see getAbortCurrent().
      Parameters:
      value - the new value
    • getHeartbeatMs

      public int getHeartbeatMs()
      The interval in milliseconds between each AbortCheck event callback, which enables an application to abort certain method calls before they complete. By default, HeartbeatMs is set to 0, meaning no AbortCheck event callbacks will trigger.
      Returns:
      the value of the HeartbeatMs property
    • setHeartbeatMs

      public void setHeartbeatMs​(int value)
      Sets the HeartbeatMs property; see getHeartbeatMs().
      Parameters:
      value - the new value
    • compressFile

      public void compressFile​(String inFilename, String destPath)
      Compresses a file to create a UNIX compressed file (.Z). This compression uses the LZW (Lempel-Ziv-Welch) compression algorithm.
      Parameters:
      inFilename - the inFilename argument (not null)
      destPath - the destPath argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • compressStringToFile

      public void compressStringToFile​(String inStr, String charset, String destPath)
      Unix compresses and creates a .Z file from string data. The charset specifies the character encoding used for the byte representation of the characters when compressed. The charset can be any one of a large number of character encodings, such as utf-8, iso-8859-1, Windows-1252, ucs-2, etc.
      Parameters:
      inStr - the inStr argument (not null)
      charset - the charset argument (not null)
      destPath - the destPath argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • unTarZ

      public void unTarZ​(String zFilename, String destDir, boolean bNoAbsolute)
      Unpacks a .tar.Z file. The decompress and untar occur in streaming mode. There are no temporary files and the memory footprint is constant (and small) while untarring.
      Parameters:
      zFilename - the zFilename argument (not null)
      destDir - the destDir argument (not null)
      bNoAbsolute - the bNoAbsolute argument
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • uncompressFile

      public void uncompressFile​(String inFilename, String destPath)
      Uncompresses a .Z file. (This compression uses the LZW (Lempel-Ziv-Welch) compression algorithm.)
      Parameters:
      inFilename - the inFilename argument (not null)
      destPath - the destPath argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • uncompressFileToString

      public String uncompressFileToString​(String zFilename, String charset)
      Uncompresses a .Z file that contains a text file. The contents of the text file are returned as a string. The character encoding of the text file is specified by charset. Typical charsets are iso-8859-1, utf-8, windows-1252, shift_JIS, big5, etc.
      Parameters:
      zFilename - the zFilename argument (not null)
      charset - the charset argument (not null)
      Returns:
      the result (never null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • setProgressListener

      public void setProgressListener​(ProgressListener listener)
      Installs the listener that receives this object's progress events (abortCheck, percentDone, progressInfo) during its long-running methods; replaces any listener or lambda installed before; null removes it.
      Parameters:
      listener - the listener, or null
      Throws:
      IllegalStateException - if called from inside one of this object's own callbacks
    • getProgressListener

      public ProgressListener getProgressListener()
      Returns the installed listener, or null.
      Returns:
      the listener installed with setProgressListener(ProgressListener) or one of the on... methods
    • onAbortCheck

      public void onAbortCheck​(BooleanSupplier callback)
      Installs a listener whose only callback is abortCheck: called every HeartbeatMs milliseconds during a long-running method; return true to abort it. Replaces any listener installed before.
      Parameters:
      callback - the callback, or null to remove the listener
    • onPercentDone

      public void onPercentDone​(IntPredicate callback)
      Installs a listener whose only callback is percentDone: called with the completion percentage (0..100) as a long-running method progresses; return true to abort it. Replaces any listener installed before.
      Parameters:
      callback - the callback, or null to remove the listener
    • onProgressInfo

      public void onProgressInfo​(BiConsumer<String,​String> callback)
      Installs a listener whose only callback is progressInfo: called with a name/value pair of progress information as a long-running method proceeds. Replaces any listener installed before.
      Parameters:
      callback - the callback, or null to remove the listener