Class UnixCompress
- All Implemented Interfaces:
AutoCloseable
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcompressFile(String inFilename, String destPath)Compresses a file to create a UNIX compressed file (.Z).voidcompressStringToFile(String inStr, String charset, String destPath)Unix compresses and creates a .Z file from string data.booleanWhen set totrue, causes the currently running method to abort.intThe interval in milliseconds between eachevent callback, which enables an application to abort certain method calls before they complete.AbortCheckReturns the installed listener, ornull.voidonAbortCheck(BooleanSupplier callback)Installs a listener whose only callback isabortCheck: called everyHeartbeatMsmilliseconds during a long-running method; returntrueto abort it.voidonPercentDone(IntPredicate callback)Installs a listener whose only callback ispercentDone: called with the completion percentage (0..100) as a long-running method progresses; returntrueto abort it.voidonProgressInfo(BiConsumer<String,String> callback)Installs a listener whose only callback isprogressInfo: called with a name/value pair of progress information as a long-running method proceeds.voidsetAbortCurrent(boolean value)Sets theAbortCurrentproperty; seegetAbortCurrent().voidsetHeartbeatMs(int value)Sets theHeartbeatMsproperty; seegetHeartbeatMs().voidsetProgressListener(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;nullremoves it.voiduncompressFile(String inFilename, String destPath)Uncompresses a .Z file.uncompressFileToString(String zFilename, String charset)Uncompresses a .Z file that contains a text file.voidUnpacks a .tar.Z file.Methods inherited from class com.chilkatsoft.chilkat2.ChilkatObject
close, getDebugLogFilePath, getLastErrorHtml, getLastErrorText, getLastErrorXml, getLastMethodSuccess, getVerboseLogging, getVersion, isClosed, setDebugLogFilePath, setLastMethodSuccess, setVerboseLogging, toString
-
Constructor Details
-
UnixCompress
public UnixCompress()Creates a newUnixCompressobject.
-
-
Method Details
-
getAbortCurrent
public boolean getAbortCurrent()When set totrue, 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 tofalsewhen the next method is called. When the abort occurs, this property is reset tofalse. 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
AbortCurrentproperty
-
setAbortCurrent
public void setAbortCurrent(boolean value)Sets theAbortCurrentproperty; seegetAbortCurrent().- Parameters:
value- the new value
-
getHeartbeatMs
public int getHeartbeatMs()The interval in milliseconds between eachevent callback, which enables an application to abort certain method calls before they complete. By default, HeartbeatMs is set toAbortCheck0, meaning no AbortCheck event callbacks will trigger.- Returns:
- the value of the
HeartbeatMsproperty
-
setHeartbeatMs
public void setHeartbeatMs(int value)Sets theHeartbeatMsproperty; seegetHeartbeatMs().- Parameters:
value- the new value
-
compressFile
Compresses a file to create a UNIX compressed file (.Z). This compression uses the LZW (Lempel-Ziv-Welch) compression algorithm.- Parameters:
inFilename- theinFilenameargument (notnull)destPath- thedestPathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
compressStringToFile
Unix compresses and creates a .Z file from string data. Thecharsetspecifies the character encoding used for the byte representation of the characters when compressed. Thecharsetcan be any one of a large number of character encodings, such asutf-8,iso-8859-1,Windows-1252,ucs-2, etc.- Parameters:
inStr- theinStrargument (notnull)charset- thecharsetargument (notnull)destPath- thedestPathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
unTarZ
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- thezFilenameargument (notnull)destDir- thedestDirargument (notnull)bNoAbsolute- thebNoAbsoluteargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
uncompressFile
Uncompresses a .Z file. (This compression uses the LZW (Lempel-Ziv-Welch) compression algorithm.)- Parameters:
inFilename- theinFilenameargument (notnull)destPath- thedestPathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
uncompressFileToString
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 bycharset. Typical charsets areiso-8859-1,utf-8,windows-1252,shift_JIS,big5, etc.- Parameters:
zFilename- thezFilenameargument (notnull)charset- thecharsetargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setProgressListener
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;nullremoves it.- Parameters:
listener- the listener, ornull- Throws:
IllegalStateException- if called from inside one of this object's own callbacks
-
getProgressListener
Returns the installed listener, ornull.- Returns:
- the listener installed with
setProgressListener(ProgressListener)or one of theon...methods
-
onAbortCheck
Installs a listener whose only callback isabortCheck: called everyHeartbeatMsmilliseconds during a long-running method; returntrueto abort it. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-
onPercentDone
Installs a listener whose only callback ispercentDone: called with the completion percentage (0..100) as a long-running method progresses; returntrueto abort it. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-
onProgressInfo
Installs a listener whose only callback isprogressInfo: called with a name/value pair of progress information as a long-running method proceeds. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-