java.lang.Object
java.io.InputStream
java.io.FilterInputStream
com.ibm.jzos.ZCompressorInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
A subclass of
InputStream that will expand data from
an enclosed InputStream containing data that was compressed
by the same z/Architecture compression dictionaries. Not thread safe.
The class implements AutoCloseable. It can be used with the AutoCloseable with a try-with-resources
block or without, as shown in the two examples below:
Example 1: Allocate and close a ZFile when a try-with-resources block is not used.
The an explicit call to the close() close the ZFile object and release the
associated resources. The close() method is called in a finally block to
assure that the close is performed after the try block completes.
ZFile zfile = new new ZFile(fileName, options);
try {
byte[] recBuf = new byte[lrecl];
// read the records sequentially
while (zfile.read(recBuf) != -1) {
String record = new String(recBuf);
System.out.println("Record=" + record);
}
}
finally {
zfile.close();
}
Example 2: Allocate a ZFile when a try-with-resources block is used. The method close() is not needed.
Upon exiting a try-with-resources block, the AutoCloseable will automatically call the close()
method which will lose the ZFile object and release the associated resources.
try (ZFile zfile = new new ZFile(fileName, options)) {
byte[] recBuf = new byte[lrecl];
// read the records sequentially
while (zfile.read(recBuf) != -1) {
String record = new String(recBuf);
System.out.println("Record=" + record);
}
}
...
- Since:
- 2.4.4
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionZCompressorInputStream(ZCompressor compressor, InputStream in) Create a new input stream with default buffer size.ZCompressorInputStream(ZCompressor compressor, InputStream in, int buflen) Create a new input stream with the specified buffer size. -
Method Summary
Modifier and TypeMethodDescriptionintReturns an estimate of the number of bytes that can be read.voidclose()longAnswer the total number of bytes expanded so far.longAnswer the total number of compressed bytes read so far.voidmark(int limit) Does nothing, not supported.booleanAlways returns false, mark/reset is not supported.intread()intread(byte[] b) intread(byte[] readBuf, int readBufOff, int readBufLen) voidreleaseZCompressorOnClose(boolean value) Sets a flag that will cause the ZCompressor resources to be released when this OutputStream is closed.voidreset()This method is not supported and always throws an IOException.longskip(long n) This method is not supported and always throws an IOException.Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
ZCompressorInputStream
Create a new input stream with default buffer size.- Parameters:
compressor- the ZCompressor object used to expand datain- the InputStream containing compressed data
-
ZCompressorInputStream
Create a new input stream with the specified buffer size.- Parameters:
compressor- the ZCompressor object used to expand datain- the InputStream containing compressed databuflen- the length of internal compression and expansion buffers
-
-
Method Details
-
releaseZCompressorOnClose
public void releaseZCompressorOnClose(boolean value) Sets a flag that will cause the ZCompressor resources to be released when this OutputStream is closed. Defaults tofalse. -
getTotalSourceBytes
public long getTotalSourceBytes()Answer the total number of compressed bytes read so far.- Returns:
- the total number of compressed bytes read so far
-
getTotalExpandedBytes
public long getTotalExpandedBytes()Answer the total number of bytes expanded so far.- Returns:
- the total number of bytes expanded so far
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterInputStream- Throws:
IOException- See Also:
-
read
- Overrides:
readin classFilterInputStream- Throws:
IOException- See Also:
-
read
- Overrides:
readin classFilterInputStream- Throws:
IOException- See Also:
-
read
- Overrides:
readin classFilterInputStream- Throws:
IOException- See Also:
-
skip
This method is not supported and always throws an IOException.- Overrides:
skipin classFilterInputStream- Throws:
IOException- always throws IOException since skip() is not supported- See Also:
-
available
Returns an estimate of the number of bytes that can be read. Note that this is not in any way an estimate of the amount of expanded data available. A positive integer does indicate, however that more is available.- Overrides:
availablein classFilterInputStream- Throws:
IOException- See Also:
-
markSupported
public boolean markSupported()Always returns false, mark/reset is not supported.- Overrides:
markSupportedin classFilterInputStream- See Also:
-
mark
public void mark(int limit) Does nothing, not supported.- Overrides:
markin classFilterInputStream- See Also:
-
reset
This method is not supported and always throws an IOException.- Overrides:
resetin classFilterInputStream- Throws:
IOException- since mark/reset is not supported- See Also:
-