public class CompressorStreamFactory extends java.lang.Object implements CompressorStreamProvider
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 = 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();
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
BROTLI
Constant (value "br") used to identify the BROTLI compression
algorithm.
|
static java.lang.String |
BZIP2
Constant (value "bzip2") used to identify the BZIP2 compression
algorithm.
|
static java.lang.String |
DEFLATE
Constant (value "deflate") used to identify the Deflate compress method.
|
static java.lang.String |
DEFLATE64
Constant (value "deflate64") used to identify the Deflate64 compress method.
|
static java.lang.String |
GZIP
Constant (value "gz") used to identify the GZIP compression
algorithm.
|
static java.lang.String |
LZ4_BLOCK
Constant (value "lz4-block") used to identify the block LZ4
compression method.
|
static java.lang.String |
LZ4_FRAMED
Constant (value "lz4-framed") used to identify the frame LZ4
compression method.
|
static java.lang.String |
LZMA
Constant (value "lzma") used to identify the LZMA compression method.
|
static java.lang.String |
PACK200
Constant (value "pack200") used to identify the PACK200 compression
algorithm.
|
static java.lang.String |
SNAPPY_FRAMED
Constant (value "snappy-framed") used to identify the "framed" Snappy
compression method.
|
static java.lang.String |
SNAPPY_RAW
Constant (value "snappy-raw") used to identify the "raw" Snappy compression
method.
|
static java.lang.String |
XZ
Constant (value "xz") used to identify the XZ compression method.
|
static java.lang.String |
Z
Constant (value "z") used to identify the traditional Unix compress
method.
|
static java.lang.String |
ZSTANDARD
Constant (value "zstd") used to identify the Zstandard compression
algorithm.
|
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.
|
CompressorStreamFactory(boolean decompressUntilEOF,
int memoryLimitInKb)
Create an instance with the provided decompress Concatenated option.
|
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)
Creates a compressor input stream from a compressor name and an input
stream.
|
CompressorInputStream |
createCompressorInputStream(java.lang.String name,
java.io.InputStream in,
boolean actualDecompressConcatenated)
Creates a compressor input stream from a compressor name and an input
stream.
|
CompressorOutputStream |
createCompressorOutputStream(java.lang.String name,
java.io.OutputStream out)
Creates an compressor output stream from an compressor name and an output
stream.
|
static java.lang.String |
detect(java.io.InputStream in)
Try to detect the type of compressor stream.
|
static java.util.SortedMap<java.lang.String,CompressorStreamProvider> |
findAvailableCompressorInputStreamProviders()
Constructs a new sorted map from input stream provider names to provider
objects.
|
static java.util.SortedMap<java.lang.String,CompressorStreamProvider> |
findAvailableCompressorOutputStreamProviders()
Constructs a new sorted map from output stream provider names to provider
objects.
|
static java.lang.String |
getBrotli() |
static java.lang.String |
getBzip2() |
java.util.SortedMap<java.lang.String,CompressorStreamProvider> |
getCompressorInputStreamProviders() |
java.util.SortedMap<java.lang.String,CompressorStreamProvider> |
getCompressorOutputStreamProviders() |
java.lang.Boolean |
getDecompressUntilEOF() |
static java.lang.String |
getDeflate() |
static java.lang.String |
getDeflate64() |
static java.lang.String |
getGzip() |
java.util.Set<java.lang.String> |
getInputStreamCompressorNames()
Gets all the input stream compressor names for this provider
|
static java.lang.String |
getLZ4Block() |
static java.lang.String |
getLZ4Framed() |
static java.lang.String |
getLzma() |
java.util.Set<java.lang.String> |
getOutputStreamCompressorNames()
Gets all the output stream compressor names for this provider
|
static java.lang.String |
getPack200() |
static CompressorStreamFactory |
getSingleton() |
static java.lang.String |
getSnappyFramed() |
static java.lang.String |
getSnappyRaw() |
static java.lang.String |
getXz() |
static java.lang.String |
getZ() |
static java.lang.String |
getZstandard() |
void |
setDecompressConcatenated(boolean decompressConcatenated)
Deprecated.
1.10 use the
CompressorStreamFactory(boolean)
constructor instead |
public static final java.lang.String BROTLI
public static final java.lang.String BZIP2
public static final java.lang.String GZIP
public static final java.lang.String PACK200
public static final java.lang.String XZ
public static final java.lang.String LZMA
public static final java.lang.String SNAPPY_FRAMED
public static final java.lang.String SNAPPY_RAW
public static final java.lang.String Z
public static final java.lang.String DEFLATE
public static final java.lang.String DEFLATE64
public static final java.lang.String LZ4_BLOCK
public static final java.lang.String LZ4_FRAMED
public static final java.lang.String ZSTANDARD
public CompressorStreamFactory()
public CompressorStreamFactory(boolean decompressUntilEOF, int memoryLimitInKb)
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.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.public static java.util.SortedMap<java.lang.String,CompressorStreamProvider> findAvailableCompressorInputStreamProviders()
The map returned by this method will have one entry for each provider for which support is available in the current Java virtual machine. If two or more supported provider have the same name then the resulting map will contain just one of them; which one it will contain is not specified.
The invocation of this method, and the subsequent use of the resulting map, may cause time-consuming disk or network I/O operations to occur. This method is provided for applications that need to enumerate all of the available providers, for example to allow user provider selection.
This method may return different results at different times if new providers are dynamically made available to the current Java virtual machine.
public static java.util.SortedMap<java.lang.String,CompressorStreamProvider> findAvailableCompressorOutputStreamProviders()
The map returned by this method will have one entry for each provider for which support is available in the current Java virtual machine. If two or more supported provider have the same name then the resulting map will contain just one of them; which one it will contain is not specified.
The invocation of this method, and the subsequent use of the resulting map, may cause time-consuming disk or network I/O operations to occur. This method is provided for applications that need to enumerate all of the available providers, for example to allow user provider selection.
This method may return different results at different times if new providers are dynamically made available to the current Java virtual machine.
public static java.lang.String getBrotli()
public static java.lang.String getBzip2()
public static java.lang.String getDeflate()
public static java.lang.String getDeflate64()
DEFLATE64
public static java.lang.String getGzip()
public static java.lang.String getLzma()
public static java.lang.String getPack200()
public static CompressorStreamFactory getSingleton()
public static java.lang.String getSnappyFramed()
public static java.lang.String getSnappyRaw()
public static java.lang.String getXz()
public static java.lang.String getZ()
public static java.lang.String getLZ4Framed()
public static java.lang.String getLZ4Block()
public static java.lang.String getZstandard()
public static java.lang.String detect(java.io.InputStream in) throws CompressorException
in
- input streamCompressorException
- if no compressor stream type was detected
or if something else went wrongjava.lang.IllegalArgumentException
- if stream is null or does not support markpublic 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", "bzip2",
"xz", "lzma", "pack200",
"snappy-raw", "snappy-framed", "z",
"lz4-block", "lz4-framed", "zstd",
"deflate64"
or "deflate"in
- the input streamCompressorException
- if the compressor name is not known or not available,
or if there's an IOException or MemoryLimitException thrown
during initializationjava.lang.IllegalArgumentException
- if the name or input stream is nullpublic CompressorInputStream createCompressorInputStream(java.lang.String name, java.io.InputStream in, boolean actualDecompressConcatenated) throws CompressorException
CompressorStreamProvider
createCompressorInputStream
in interface CompressorStreamProvider
name
- of the compressor, i.e.
"gz",
"bzip2",
"xz",
"lzma",
"pack200",
"snappy-raw",
"snappy-framed",
"z"
or
"deflate"in
- the input streamactualDecompressConcatenated
- 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.CompressorException
- if the compressor name is not knownpublic CompressorOutputStream createCompressorOutputStream(java.lang.String name, java.io.OutputStream out) throws CompressorException
createCompressorOutputStream
in interface CompressorStreamProvider
name
- the compressor name, i.e. "gz", "bzip2",
"xz", "pack200", "snappy-framed",
"lz4-block", "lz4-framed", "zstd"
or "deflate"out
- the output streamCompressorException
- if the archiver name is not knownjava.lang.IllegalArgumentException
- if the archiver name or stream is nullpublic java.util.SortedMap<java.lang.String,CompressorStreamProvider> getCompressorInputStreamProviders()
public java.util.SortedMap<java.lang.String,CompressorStreamProvider> getCompressorOutputStreamProviders()
public java.lang.Boolean getDecompressUntilEOF()
public java.util.Set<java.lang.String> getInputStreamCompressorNames()
CompressorStreamProvider
getInputStreamCompressorNames
in interface CompressorStreamProvider
public java.util.Set<java.lang.String> getOutputStreamCompressorNames()
CompressorStreamProvider
getOutputStreamCompressorNames
in interface CompressorStreamProvider
@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 streamjava.lang.IllegalStateException
- if the constructor CompressorStreamFactory(boolean)
was used to create the factoryCopyright © 2010 - 2020 Adobe. All Rights Reserved