Class Bz2
- All Implemented Interfaces:
AutoCloseable
Chilkat.Bz2 provides BZip2 compression and decompression for files, memory buffers, and
BinData. It can create standard .bz2 file images, decompress .bz2 content back to its original
bytes, and support abortable long-running operations.
For an extended overview, see Bz2 Class Overview
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 TypeMethodDescriptionvoidcompressBd(BinData bd)Compresses the current contents ofbdin place.voidcompressFile(String inFilename, String toPath)Reads the file atinFilenameand writes its compressed bytes as a standard BZip2 stream to the file attoPath.booleanSet this property toto request cancellation of the compression or decompression operation currently executing on this object.trueintSpecifies the interval, in milliseconds, betweenevent callbacks during supported long-running compression and decompression operations.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.voiduncompressBd(BinData bd)Decompresses the BZip2 stream currently contained inbdin place.voiduncompressFile(String inFilename, String toPath)Reads the BZip2 stream from the file atinFilename, decompresses it, and writes the original uncompressed bytes to the file attoPath.Methods inherited from class com.chilkatsoft.chilkat2.ChilkatObject
close, getDebugLogFilePath, getLastErrorHtml, getLastErrorText, getLastErrorXml, getLastMethodSuccess, getVerboseLogging, getVersion, isClosed, setDebugLogFilePath, setLastMethodSuccess, setVerboseLogging, toString
-
Constructor Details
-
Bz2
public Bz2()Creates a newBz2object.
-
-
Method Details
-
getAbortCurrent
public boolean getAbortCurrent()Set this property toto request cancellation of the compression or decompression operation currently executing on this object. Long-running operations check the request periodically; an operation that finishes quickly may complete before the request is observed.trueA synchronous call can be cancelled by setting this property from another thread. After cancellation is processed, Chilkat resets the property to
. If no operation is running, a previously set value is cleared when the next method begins.falseCancellation is cooperative: Setting this property requests an abort; it does not guarantee immediate termination. Check the method's return value and
LastErrorTextto determine the final outcome.- Returns:
- the value of the
AbortCurrentproperty
-
setAbortCurrent
public void setAbortCurrent(boolean value)Sets theAbortCurrentproperty; seegetAbortCurrent().- Parameters:
value- the new value
-
getHeartbeatMs
public int getHeartbeatMs()Specifies the interval, in milliseconds, betweenevent callbacks during supported long-running compression and decompression operations. The default isAbortCheck0, which disablesAbortCheckcallbacks.Set a positive value, such as
200, when the application needs periodic opportunities to request cancellation. The interval is approximate; callbacks occur only while an operation is at a point where progress events can be delivered.Cancellation workflow: In an
AbortCheckhandler, set the callback's abort value to request termination. A synchronous method may also be cancelled from another thread by settingtogetAbortCurrent().true- Returns:
- the value of the
HeartbeatMsproperty
-
setHeartbeatMs
public void setHeartbeatMs(int value)Sets theHeartbeatMsproperty; seegetHeartbeatMs().- Parameters:
value- the new value
-
compressBd
Compresses the current contents ofbdin place. On success, theBinDatano longer contains the original bytes; it contains the complete standard BZip2 stream that may be saved with a.bz2extension.In-place transformation: Preserve a copy of the original data if it is still needed after this call. A BZip2 stream contains a stream header, one or more compressed blocks with integrity checks, and an end-of-stream marker. It does not contain archive filenames or directory entries.
- Parameters:
bd- thebdargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
compressFile
Reads the file atinFilenameand writes its compressed bytes as a standard BZip2 stream to the file attoPath. The output is conventionally given a.bz2extension.Both arguments must identify files, not directories. They may be absolute or relative paths, for example
data/report.txtanddata/report.txt.bz2.BZip2 is a compressor, not an archive format: A
.bz2file represents one compressed byte stream. It does not store the original filename, directory path, timestamps, permissions, or multiple archive entries. Formats such as.tar.bz2first combine files in a TAR archive and then compress that TAR stream with BZip2.- Parameters:
inFilename- theinFilenameargument (notnull)toPath- thetoPathargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
uncompressBd
Decompresses the BZip2 stream currently contained inbdin place. On success, theBinDatais replaced with the original uncompressed bytes.Input requirement:
bdmust contain a complete, valid BZip2 stream, such as the bytes of a.bz2file or the output of. This method operates on binary data and does not perform character-set conversion.compressBd(BinData)- Parameters:
bd- thebdargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
uncompressFile
Reads the BZip2 stream from the file atinFilename, decompresses it, and writes the original uncompressed bytes to the file attoPath.Both arguments must identify files, not directories. Chilkat does not derive the destination name from the
.bz2filename because the BZip2 stream does not contain the original filename.Terminology: This method decompresses BZip2 data; it does not “unzip” a ZIP archive. A
.bz2file normally contains a single compressed byte stream rather than a collection of named files.- Parameters:
inFilename- theinFilenameargument (notnull)toPath- thetoPathargument (notnull)- 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
-