public class CompressionFactory
extends java.lang.Object
OutputStream
which can be used to compress a stream of dataInputStream
which can be used to expand a stream of compressed dataBufferCompressor
which can be used to compress or expand discrete buffers of dataZCompressor
)GZIPInputStream
and GZIPOutputStream
)Deflater
,
Inflater
,
DeflaterOutputStream
and
InflaterInputStream
)
-Dcom.ibm.jzos.compression.type=<algorithm>[:parm1[:parm2]]
-Dcom.ibm.jzos.compression.type=zcmpsc:12://HLQ.MYDICT.DATA
zcmpsc
are required.
-Dcom.ibm.jzos.compression.type=gzip
-Dcom.ibm.jzos.compression.type=deflate:9
Note: This property is case sensitive.
In addition, changes to this property
after creating the default factory are not applied to the (cached) default factory.
See releaseDefault()
.
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
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
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);
...
ZCompressor
,
ZCompressorInputStream
,
ZCompressorOutputStream
,
Deflater
,
Inflater
,
DeflaterOutputStream
,
InflaterInputStream
,
GZIPInputStream
,
GZIPOutputStream
Modifier and Type | Class and Description |
---|---|
static class |
CompressionFactory.Algorithm
An enumeration of the algorithms currently supported
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_COMPRESSION_TYPE
The default algorithm is
gzip if System property PROPERTY_COMPRESSION_TYPE is not set |
static java.lang.String |
PROPERTY_COMPRESSION_TYPE
This property may be used to set the default algorithm and its parameters, separated by '
: ' |
Modifier and Type | Method and 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 a
BufferCompressor that may be used to compress or
expand a discrete block of data. |
java.io.OutputStream |
getCompressingOutputStream(java.io.OutputStream out)
Construct and return an
OutputStream that can be used to compress data to
another OutputStream. |
java.io.OutputStream |
getCompressingOutputStream(java.io.OutputStream out,
int bufsize)
Construct and return an
OutputStream 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 an
InputStream that can be used to expand compressed data from
another InputStream. |
java.io.InputStream |
getExpandingInputStream(java.io.InputStream in,
int bufsize)
Construct and return an
InputStream 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 given
CompressionFactory.Algorithm and optional parms. |
void |
release()
Release any resources that are cached by this CompressionFactory.
|
static void |
releaseDefault()
Release the current default factory instance.
|
public static final java.lang.String PROPERTY_COMPRESSION_TYPE
:
'public static final java.lang.String DEFAULT_COMPRESSION_TYPE
gzip
if System property PROPERTY_COMPRESSION_TYPE
is not setpublic static CompressionFactory getDefault()
PROPERTY_COMPRESSION_TYPE
System property may be used to configure
the algorithm and its parameters. If this System property is not specified,
the DEFAULT_COMPRESSION_TYPE
value is used.public static void releaseDefault()
PROPERTY_COMPRESSION_TYPE
System property to be reflected in the
creation of a new default cached factory.public static CompressionFactory getFactory(CompressionFactory.Algorithm algorithm, java.lang.String parms)
CompressionFactory.Algorithm
and optional parms.algorithm
- the type of compression algorithmparms
- zero or more algorithm specific parameters separated by ':
', may be nullpublic CompressionFactory.Algorithm getAlgorithm()
public java.lang.String[] getAlgorithmParms()
public java.io.OutputStream getCompressingOutputStream(java.io.OutputStream out) throws java.io.IOException
OutputStream
that can be used to compress data to
another OutputStream. The CompressionFactory.Algorithm
and parameters configured for this
CompressionFactory will determine which OutputStream implementation will be used.
Streams are not thread safe.out
- the OutputStream where compressed data will be writtenjava.io.IOException
public java.io.OutputStream getCompressingOutputStream(java.io.OutputStream out, int bufsize) throws java.io.IOException
OutputStream
that can be used to compress data to
another OutputStream. The CompressionFactory.Algorithm
and parameters configured for this
CompressionFactory will determine which OutputStream implementation will be used.
Streams are not thread safe.out
- the OutputStream where compressed data will be writtenbufsize
- the buffer size used (if any) by the OutputStreamjava.io.IOException
public java.io.InputStream getExpandingInputStream(java.io.InputStream in) throws java.io.IOException
InputStream
that can be used to expand compressed data from
another InputStream. The CompressionFactory.Algorithm
and parameters configured for this
CompressionFactory will determine which InputStream implementation will be used. Streams
are not thread safe.in
- the InputStream where compressed data will be readjava.io.IOException
public java.io.InputStream getExpandingInputStream(java.io.InputStream in, int bufsize) throws java.io.IOException
InputStream
that can be used to expand compressed data from
another InputStream. The CompressionFactory.Algorithm
and parameters configured for this
CompressionFactory will determine which InputStream implementation will be used. Streams
are not thread safe.in
- the InputStream where compressed data will be readbufsize
- bufsize the buffer size (if any) used by the InputStreamjava.io.IOException
- if an I/O error has occurredpublic BufferCompressor getBufferCompressor() throws java.io.IOException
BufferCompressor
that may be used to compress or
expand a discrete block of data.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.BufferCompressor
public void release()