- java.lang.Object
-
- com.ibm.jzos.CompressionFactory
-
public class CompressionFactory extends java.lang.Object
An abstract compression factory that can be used with different compression algorithms such as GZIP compression, INFLATE/DEFLATE, and z/Architecture CMPSC compression.
A CompressionFactory may be used to construct one of the following:- An
OutputStream
which can be used to compress a stream of data - An
InputStream
which can be used to expand a stream of compressed data - A
BufferCompressor
which can be used to compress or expand discrete buffers of data
A Java system property may be used to configure a default CompressionFactory with one of the following compression algorithms:- z/Architecture CMPSC instruction (see
ZCompressor
) - GZIP (see
GZIPInputStream
andGZIPOutputStream
) -
DEFLATE (see
Deflater
,Inflater
,DeflaterOutputStream
andInflaterInputStream
)
The syntax of this property is:-Dcom.ibm.jzos.compression.type=<algorithm>[:parm1[:parm2]]
Examples:-
-Dcom.ibm.jzos.compression.type=zcmpsc:12://HLQ.MYDICT.DATA
z/Architecture CMPSC compression using, in this example, a CMPSC dictionary with 12-bit symbols in a z/OS data set.
In this file/data set, the compression dictionary must be followed by the expansion dictionary.
Both parameters forzcmpsc
are required. -
-Dcom.ibm.jzos.compression.type=gzip
GZIP compression (the default if not specified). No additional parameters are required. -
-Dcom.ibm.jzos.compression.type=deflate:9
Deflate/Inflate with compression level 0-9, with 0 meaning no compression and 9 meaning maximum compression.
The compression level is an optional parameter. If not specified, default compression level will be used.
Note: This property is case sensitive.
Usage examples:
In addition, changes to this property after creating the default factory are not applied to the (cached) default factory. SeereleaseDefault()
.
-
Use a compressing OutputStream with the default CompressionFactory
CompressionFactory factory = CompressionFactory.getDefault(); FileOutputStream fout = new FileOutputStream("compressed.dat"); OutputStream compOut = factory.getCompressingOutputStream(fout); compOut.write(buf); ... compOut.close(); factory.release(); // release any cached resources
-
Obtain a BufferCompressor from the default CompressionFactory and use
it to compress and expand a buffer:
CompressionFactory factory = CompressionFactory.getDefault(); BufferCompressor bc = factory.getBufferCompressor(); int nCompressed = bc.compressBuffer(cbuf, 0, inbuf, 0, inbuf.length); byte[] buf2 = new byte[inbuf.length]; int nExpanded = bc.expandBuffer(buf2, 0, cbuf, 0, nCompressed); assert nExpanded = inbuf.length; assert Arrays.equals(inbuf, buf2); factory.release(); // release any cached resources
-
CompressionFactories may be constructed explicitly for a specific
algorithm and parameters:
CompressionFactory factory = CompressionFactory.getFactory( CompressionFactory.Algorithm.zcmpsc, "12:/data/zcmpsc.dicts"); ... CompressionFactory factory = CompressionFactory.getFactory( CompressionFactory.Algorithm.deflate, "9"); ... CompressionFactory factory = CompressionFactory.getFactory( CompressionFactory.Algorithm.gzip, null); ...
- Since:
- 2.4.4
- See Also:
ZCompressor
,ZCompressorInputStream
,ZCompressorOutputStream
,Deflater
,Inflater
,DeflaterOutputStream
,InflaterInputStream
,GZIPInputStream
,GZIPOutputStream
- An
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CompressionFactory.Algorithm
An enumeration of the algorithms currently supported
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_COMPRESSION_TYPE
The default algorithm isgzip
if System propertyPROPERTY_COMPRESSION_TYPE
is not setstatic java.lang.String
PROPERTY_COMPRESSION_TYPE
This property may be used to set the default algorithm and its parameters, separated by ':
'
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CompressionFactory.Algorithm
getAlgorithm()
Answer the compression algorithm used by this CompressionFactory instance.java.lang.String[]
getAlgorithmParms()
Answer the algorithm parameters used by this CompressionFactory instance.BufferCompressor
getBufferCompressor()
Construct and return aBufferCompressor
that may be used to compress or expand a discrete block of data.java.io.OutputStream
getCompressingOutputStream(java.io.OutputStream out)
Construct and return anOutputStream
that can be used to compress data to another OutputStream.java.io.OutputStream
getCompressingOutputStream(java.io.OutputStream out, int bufsize)
Construct and return anOutputStream
that can be used to compress data to another OutputStream.static CompressionFactory
getDefault()
Return a default CompressionFactory.java.io.InputStream
getExpandingInputStream(java.io.InputStream in)
Construct and return anInputStream
that can be used to expand compressed data from another InputStream.java.io.InputStream
getExpandingInputStream(java.io.InputStream in, int bufsize)
Construct and return anInputStream
that can be used to expand compressed data from another InputStream.static CompressionFactory
getFactory(CompressionFactory.Algorithm algorithm, java.lang.String parms)
Construct and return a new CompressionFactory for a givenCompressionFactory.Algorithm
and optional parms.void
release()
Release any resources that are cached by this CompressionFactory.static void
releaseDefault()
Release the current default factory instance.
-
-
-
Field Detail
-
PROPERTY_COMPRESSION_TYPE
public static final java.lang.String PROPERTY_COMPRESSION_TYPE
This property may be used to set the default algorithm and its parameters, separated by ':
'- See Also:
- Constant Field Values
-
DEFAULT_COMPRESSION_TYPE
public static final java.lang.String DEFAULT_COMPRESSION_TYPE
The default algorithm isgzip
if System propertyPROPERTY_COMPRESSION_TYPE
is not set
-
-
Method Detail
-
getDefault
public static CompressionFactory getDefault()
Return a default CompressionFactory. ThePROPERTY_COMPRESSION_TYPE
System property may be used to configure the algorithm and its parameters. If this System property is not specified, theDEFAULT_COMPRESSION_TYPE
value is used.- Returns:
- a default CompressionFactory
-
releaseDefault
public static void releaseDefault()
Release the current default factory instance. This allows for changes to thePROPERTY_COMPRESSION_TYPE
System property to be reflected in the creation of a new default cached factory.
-
getFactory
public static CompressionFactory getFactory(CompressionFactory.Algorithm algorithm, java.lang.String parms)
Construct and return a new CompressionFactory for a givenCompressionFactory.Algorithm
and optional parms.- Parameters:
algorithm
- the type of compression algorithmparms
- zero or more algorithm specific parameters separated by ':
', may be null- Returns:
- a CompressionFactory
-
getAlgorithm
public CompressionFactory.Algorithm getAlgorithm()
Answer the compression algorithm used by this CompressionFactory instance.- Returns:
- the compression algorithm
-
getAlgorithmParms
public java.lang.String[] getAlgorithmParms()
Answer the algorithm parameters used by this CompressionFactory instance.- Returns:
- a String array with zero or more algorithm parameters
-
getCompressingOutputStream
public java.io.OutputStream getCompressingOutputStream(java.io.OutputStream out) throws java.io.IOException
Construct and return anOutputStream
that can be used to compress data to another OutputStream. TheCompressionFactory.Algorithm
and parameters configured for this CompressionFactory will determine which OutputStream implementation will be used. Streams are not thread safe.- Parameters:
out
- the OutputStream where compressed data will be written- Returns:
- OutputStream to which data may be written to be compressed
- Throws:
java.io.IOException
-
getCompressingOutputStream
public java.io.OutputStream getCompressingOutputStream(java.io.OutputStream out, int bufsize) throws java.io.IOException
Construct and return anOutputStream
that can be used to compress data to another OutputStream. TheCompressionFactory.Algorithm
and parameters configured for this CompressionFactory will determine which OutputStream implementation will be used. Streams are not thread safe.- Parameters:
out
- the OutputStream where compressed data will be writtenbufsize
- the buffer size used (if any) by the OutputStream- Returns:
- OutputStream to which data may be written to be compressed
- Throws:
java.io.IOException
-
getExpandingInputStream
public java.io.InputStream getExpandingInputStream(java.io.InputStream in) throws java.io.IOException
Construct and return anInputStream
that can be used to expand compressed data from another InputStream. TheCompressionFactory.Algorithm
and parameters configured for this CompressionFactory will determine which InputStream implementation will be used. Streams are not thread safe.- Parameters:
in
- the InputStream where compressed data will be read- Returns:
- InputStream from which expanded data may be read
- Throws:
java.io.IOException
-
getExpandingInputStream
public java.io.InputStream getExpandingInputStream(java.io.InputStream in, int bufsize) throws java.io.IOException
Construct and return anInputStream
that can be used to expand compressed data from another InputStream. TheCompressionFactory.Algorithm
and parameters configured for this CompressionFactory will determine which InputStream implementation will be used. Streams are not thread safe.- Parameters:
in
- the InputStream where compressed data will be readbufsize
- bufsize the buffer size (if any) used by the InputStream- Returns:
- InputStream from which expanded data may be read
- Throws:
java.io.IOException
- if an I/O error has occurred
-
getBufferCompressor
public BufferCompressor getBufferCompressor() throws java.io.IOException
Construct and return aBufferCompressor
that may be used to compress or expand a discrete block of data.- Throws:
java.io.IOException
- in the case that constructing the configured algorithm's compressor encounters an IOException, e.g. when reading dictionaries for a z/Architecture CMPSC compressor.- See Also:
BufferCompressor
-
release
public void release()
Release any resources that are cached by this CompressionFactory.
The default (cached) factory may choose to do nothing, but it is recommended that the programmer always call this method when finished using resources that were created by this factory instance.
-
-