Class CompressorStreamFactory

java.lang.Object
org.apache.commons.compress.compressors.CompressorStreamFactory
All Implemented Interfaces:
CompressorStreamProvider

Creates a 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 = Files.newOutputStream(output.toPath());
 CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream(CompressorStreamFactory.BZIP2, out);
 IOUtils.copy(Files.newInputStream(input.toPath()), cos);
 cos.close();
 
Example (Decompressing a file):
 final InputStream is = Files.newInputStream(input.toPath());
 CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream(CompressorStreamFactory.BZIP2, is);
 IOUtils.copy(in, Files.newOutputStream(output.toPath()));
 in.close();
 
This class is immutable
provided that the deprecated method setDecompressConcatenated is not used.
This class is thread-safe
even if the deprecated method setDecompressConcatenated is used
  • Field Details Link icon

    • BROTLI Link icon

      public static final String BROTLI
      Constant (value "br") used to identify the BROTLI compression algorithm.
      Since:
      1.14
      See Also:
    • BZIP2 Link icon

      public static final String BZIP2
      Constant (value "bzip2") used to identify the BZIP2 compression algorithm.
      Since:
      1.1
      See Also:
    • GZIP Link icon

      public static final String GZIP
      Constant (value "gz") used to identify the GZIP compression algorithm.
      Since:
      1.1
      See Also:
    • PACK200 Link icon

      public static final String PACK200
      Constant (value "pack200") used to identify the PACK200 compression algorithm.
      Since:
      1.3
      See Also:
    • XZ Link icon

      public static final String XZ
      Constant (value "xz") used to identify the XZ compression method.
      Since:
      1.4
      See Also:
    • LZMA Link icon

      public static final String LZMA
      Constant (value "lzma") used to identify the LZMA compression method.
      Since:
      1.6
      See Also:
    • SNAPPY_FRAMED Link icon

      public static final String SNAPPY_FRAMED
      Constant (value "snappy-framed") used to identify the "framed" Snappy compression method.
      Since:
      1.7
      See Also:
    • SNAPPY_RAW Link icon

      public static final String SNAPPY_RAW
      Constant (value "snappy-raw") used to identify the "raw" Snappy compression method. Not supported as an output stream type.
      Since:
      1.7
      See Also:
    • Z Link icon

      public static final String Z
      Constant (value "z") used to identify the traditional Unix compress method. Not supported as an output stream type.
      Since:
      1.7
      See Also:
    • DEFLATE Link icon

      public static final String DEFLATE
      Constant (value "deflate") used to identify the Deflate compress method.
      Since:
      1.9
      See Also:
    • DEFLATE64 Link icon

      public static final String DEFLATE64
      Constant (value "deflate64") used to identify the Deflate64 compress method.
      Since:
      1.16
      See Also:
    • LZ4_BLOCK Link icon

      public static final String LZ4_BLOCK
      Constant (value "lz4-block") used to identify the block LZ4 compression method.
      Since:
      1.14
      See Also:
    • LZ4_FRAMED Link icon

      public static final String LZ4_FRAMED
      Constant (value "lz4-framed") used to identify the frame LZ4 compression method.
      Since:
      1.14
      See Also:
    • ZSTANDARD Link icon

      public static final String ZSTANDARD
      Constant (value "zstd") used to identify the Zstandard compression algorithm. Not supported as an output stream type.
      Since:
      1.16
      See Also:
  • Constructor Details Link icon

    • CompressorStreamFactory Link icon

      Constructs an instance with the decompress Concatenated option set to false.
    • CompressorStreamFactory Link icon

      public CompressorStreamFactory(boolean decompressUntilEOF)
      Constructs an instance with the provided decompress Concatenated option.
      Parameters:
      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.
      Since:
      1.10
    • CompressorStreamFactory Link icon

      public CompressorStreamFactory(boolean decompressUntilEOF, int memoryLimitInKb)
      Constructs an instance with the provided decompress Concatenated option.
      Parameters:
      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.
      memoryLimitInKb - Some streams require allocation of potentially significant byte arrays/tables, and they can offer checks to prevent OOMs on corrupt files. Set the maximum allowed memory allocation in KBs.
      Since:
      1.14
  • Method Details Link icon