public class CompressorStreamFactory extends Object
Factory to create Compressor[In|Out]putStreams from names. To add other implementations you should extend CompressorStreamFactory and override the appropriate methods (and call their implementation from super of course).
Example (Compressing a file):
final OutputStream out = new FileOutputStream(output);
CompressorOutputStream cos =
new CompressorStreamFactory().createCompressorOutputStream(CompressorStreamFactory.BZIP2, out);
IOUtils.copy(new FileInputStream(input), cos);
cos.close();
Example (Decompressing a file):
final InputStream is = new FileInputStream(input);
CompressorInputStream in =
new CompressorStreamFactory().createCompressorInputStream(CompressorStreamFactory.BZIP2, is);
IOUtils.copy(in, new FileOutputStream(output));
in.close();
| Modifier and Type | Field and Description |
|---|---|
static String |
BZIP2
Constant (value "bzip2") used to identify the BZIP2 compression algorithm.
|
static String |
DEFLATE
Constant (value "deflate") used to identify the Deflate compress method.
|
static String |
GZIP
Constant (value "gz") used to identify the GZIP compression algorithm.
|
static String |
LZMA
Constant (value "lzma") used to identify the LZMA compression method.
|
static String |
PACK200
Constant (value "pack200") used to identify the PACK200 compression algorithm.
|
static String |
SNAPPY_FRAMED
Constant (value "snappy-framed") used to identify the "framed" Snappy compression method.
|
static String |
SNAPPY_RAW
Constant (value "snappy-raw") used to identify the "raw" Snappy compression method.
|
static String |
XZ
Constant (value "xz") used to identify the XZ compression method.
|
static String |
Z
Constant (value "z") used to identify the traditional Unix compress method.
|
| Constructor and Description |
|---|
CompressorStreamFactory()
Create an instance with the decompress Concatenated option set to false.
|
CompressorStreamFactory(boolean decompressUntilEOF)
Create an instance with the provided decompress Concatenated option.
|
| Modifier and Type | Method and Description |
|---|---|
CompressorInputStream |
createCompressorInputStream(InputStream in)
Create an compressor input stream from an input stream, autodetecting
the compressor type from the first few bytes of the stream.
|
CompressorInputStream |
createCompressorInputStream(String name,
InputStream in)
Create a compressor input stream from a compressor name and an input stream.
|
CompressorOutputStream |
createCompressorOutputStream(String name,
OutputStream out)
Create an compressor output stream from an compressor name and an output stream.
|
void |
setDecompressConcatenated(boolean decompressConcatenated)
Deprecated.
1.10 use the
CompressorStreamFactory(boolean) constructor instead |
public static final String BZIP2
public static final String GZIP
public static final String PACK200
public static final String XZ
public static final String LZMA
public static final String SNAPPY_FRAMED
public static final String SNAPPY_RAW
public static final String Z
public static final String DEFLATE
public CompressorStreamFactory()
public CompressorStreamFactory(boolean decompressUntilEOF)
decompressUntilEOF - if true, decompress until the end of the
input; if false, stop after the first
stream and leave the input position to point
to the next byte after the stream.
This setting applies to the gzip, bzip2 and xz formats only.@Deprecated public void setDecompressConcatenated(boolean decompressConcatenated)
CompressorStreamFactory(boolean) constructor insteadThis setting applies to the gzip, bzip2 and xz formats only.
decompressConcatenated - if true, decompress until the end of the
input; if false, stop after the first
stream and leave the input position to point
to the next byte after the streamIllegalStateException - if the constructor CompressorStreamFactory(boolean)
was used to create the factorypublic CompressorInputStream createCompressorInputStream(InputStream in) throws CompressorException
in - the input streamCompressorException - if the compressor name is not knownIllegalArgumentException - if the stream is null or does not support markpublic CompressorInputStream createCompressorInputStream(String name, InputStream in) throws CompressorException
name - of the compressor,
i.e. "gz", "bzip2", "xz", "lzma",
"pack200", "snappy-raw", "snappy-framed",
"z" or "deflate"in - the input streamCompressorException - if the compressor name is not knownIllegalArgumentException - if the name or input stream is nullpublic CompressorOutputStream createCompressorOutputStream(String name, OutputStream out) throws CompressorException
name - the compressor name,
i.e. "gz", "bzip2", "xz",
"pack200" or "deflate"out - the output streamCompressorException - if the archiver name is not knownIllegalArgumentException - if the archiver name or stream is nullCopyright © 2016 The Apache Software Foundation. All rights reserved.