org.apache.commons.compress.compressors
public class CompressorStreamFactory extends java.lang.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 (Compressing 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 java.lang.String |
BZIP2
Constant used to identify the BZIP2 compression algorithm.
|
static java.lang.String |
GZIP
Constant used to identify the GZIP compression algorithm.
|
Constructor and Description |
---|
CompressorStreamFactory() |
Modifier and Type | Method and Description |
---|---|
CompressorInputStream |
createCompressorInputStream(java.io.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(java.lang.String name,
java.io.InputStream in)
Create a compressor input stream from a compressor name and an input stream.
|
CompressorOutputStream |
createCompressorOutputStream(java.lang.String name,
java.io.OutputStream out)
Create an compressor output stream from an compressor name and an input stream.
|
public static final java.lang.String BZIP2
public static final java.lang.String GZIP
public CompressorInputStream createCompressorInputStream(java.io.InputStream in) throws CompressorException
in
- the input streamCompressorException
- if the compressor name is not knownjava.lang.IllegalArgumentException
- if the stream is null or does not support markpublic CompressorInputStream createCompressorInputStream(java.lang.String name, java.io.InputStream in) throws CompressorException
name
- of the compressor, i.e. "gz" or "bzip2"in
- the input streamCompressorException
- if the compressor name is not knownjava.lang.IllegalArgumentException
- if the name or input stream is nullpublic CompressorOutputStream createCompressorOutputStream(java.lang.String name, java.io.OutputStream out) throws CompressorException
name
- the compressor name, i.e. "gz" or "bzip2"out
- the output streamCompressorException
- if the archiver name is not knownjava.lang.IllegalArgumentException
- if the archiver name or stream is null