org.apache.commons.compress.compressors

## Class CompressorStreamFactory

- java.lang.Object
- - 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(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();

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `BZIP2` Constant used to identify the BZIP2 compression algorithm.
    `static String` | `GZIP` Constant used to identify the GZIP compression algorithm.
    `static String` | `LZMA` Constant used to identify the LZMA compression method.
    `static String` | `PACK200` Constant used to identify the PACK200 compression algorithm.
    `static String` | `SNAPPY_FRAMED` Constant used to identify the "framed" Snappy compression method.
    `static String` | `SNAPPY_RAW` Constant used to identify the "raw" Snappy compression method.
    `static String` | `XZ` Constant used to identify the XZ compression method.
    `static String` | `Z` Constant used to identify the traditional Unix compress method.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CompressorStreamFactory()`

  - ### Method Summary

    Methods
    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 input stream.
    `void` | `setDecompressConcatenated(boolean decompressConcatenated)` Whether to decompress the full input or only the first stream in formats supporting multiple concatenated input streams.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### BZIP2

          public static final String BZIP2

      Constant used to identify the BZIP2 compression algorithm.
      Since:
        1.1
      See Also:
        Constant Field Values

    - #### GZIP

          public static final String GZIP

      Constant used to identify the GZIP compression algorithm.
      Since:
        1.1
      See Also:
        Constant Field Values

    - #### PACK200

          public static final String PACK200

      Constant used to identify the PACK200 compression algorithm.
      Since:
        1.3
      See Also:
        Constant Field Values

    - #### XZ

          public static final String XZ

      Constant used to identify the XZ compression method.
      Since:
        1.4
      See Also:
        Constant Field Values

    - #### LZMA

          public static final String LZMA

      Constant used to identify the LZMA compression method.
      Since:
        1.6
      See Also:
        Constant Field Values

    - #### SNAPPY_FRAMED

          public static final String SNAPPY_FRAMED

      Constant used to identify the "framed" Snappy compression method.
      Since:
        1.7
      See Also:
        Constant Field Values

    - #### SNAPPY_RAW

          public static final String SNAPPY_RAW

      Constant used to identify the "raw" Snappy compression method.
      Since:
        1.7
      See Also:
        Constant Field Values

    - #### Z

          public static final String Z

      Constant used to identify the traditional Unix compress method.
      Since:
        1.7
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### CompressorStreamFactory

          public CompressorStreamFactory()

  - ### Method Detail

    - #### setDecompressConcatenated

          public void setDecompressConcatenated(boolean decompressConcatenated)

      Whether to decompress the full input or only the first stream in formats supporting multiple concatenated input streams.

      This setting applies to the gzip, bzip2 and xz formats only.

      Parameters:
        `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 stream
      Since:
        1.5

    - #### createCompressorInputStream

          public CompressorInputStream createCompressorInputStream(InputStream in)
                                                            throws CompressorException

      Create an compressor input stream from an input stream, autodetecting the compressor type from the first few bytes of the stream. The InputStream must support marks, like BufferedInputStream.
      Parameters:
        `in` - the input stream
      Returns:
        the compressor input stream
      Throws:
        `CompressorException` - if the compressor name is not known
        `IllegalArgumentException` - if the stream is null or does not support mark
      Since:
        1.1

    - #### 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", "bzip2", "xz", "lzma", "snappy-raw", "snappy-framed", "pack200", "z"
        `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", "bzip2", "xz", or "pack200"
        `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 © 2014 The Apache Software Foundation. All rights reserved.