org.apache.commons.compress.compressors
Class CompressorStreamFactory

java.lang.Object
  extended by org.apache.commons.compress.compressors.CompressorStreamFactory

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("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("bzip2", is);
 IOUtils.copy(in, new FileOutputStream(output));
 in.close();
 


Constructor Summary
CompressorStreamFactory()
           
 
Method Summary
 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 input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompressorStreamFactory

public CompressorStreamFactory()
Method Detail

createCompressorInputStream

public CompressorInputStream createCompressorInputStream(String name,
                                                         InputStream in)
                                                  throws CompressorException
Create a compressor input stream from a compressor name and an input stream.

Parameters:
name - of the compressor, i.e. "gz" or "bzip2"
in - the input stream
Returns:
compressor input stream
Throws:
CompressorException - if the compressor name is not known
IllegalArgumentException - if the name or input stream is null

createCompressorOutputStream

public CompressorOutputStream createCompressorOutputStream(String name,
                                                           OutputStream out)
                                                    throws CompressorException
Create an compressor output stream from an compressor name and an input stream.

Parameters:
name - the compressor name, i.e. "gz" or "bzip2"
out - the output stream
Returns:
the compressor output stream
Throws:
CompressorException - if the archiver name is not known
IllegalArgumentException - if the archiver name or stream is null


Copyright © 2010 Apache Software Foundation. All Rights Reserved.