public final class StreamCompression extends Object
| Modifier and Type | Field and Description |
|---|---|
static StreamCompression |
GZIP
Gzip compression format.
|
static StreamCompression |
NONE
No compression.
|
static StreamCompression |
ZIP
Zip compression format.
|
| Modifier and Type | Method and Description |
|---|---|
OutputStream |
compress(OutputStream out,
String name)
Compresses the given output stream with this compression format.
|
InputStream |
decompress(InputStream in)
Decompresses the given input stream with this compression format.
|
static StreamCompression |
detectCompressionByExtension(String fileName)
Detects compression format by the extension at the end of the file name.
|
static StreamCompression |
detectCompressionByHeader(InputStream in)
Detects compression format by the magic number in the file header.
|
static InputStream |
detectCompressionByHeaderAndDecompress(InputStream in)
Detects compression format by the magic number in the file header and decompresses
the given input stream.
|
static StreamCompression |
detectCompressionByMimeType(String mimeType)
Detects compression format by the mime type.
|
boolean |
equals(Object o)
Indicates whether some other object is "equal to" this one.
|
String |
getExtension()
Return file name extension of this compression format.
|
String |
getMimeType()
Return mime type of this compression format.
|
int |
hashCode()
Returns a hash code value for the object.
|
boolean |
hasSyncFlush()
Returns true if this compression format can be used for live data streams.
|
String |
stripExtension(String fileName)
Strips extension of this compression format from the end of the file if it matches.
|
String |
toString()
Returns a string representation of the stream compression type.
|
static StreamCompression |
valueOf(String value)
Parses stream compression format description from string.
|
public static final StreamCompression NONE
public static final StreamCompression GZIP
public static final StreamCompression ZIP
public static StreamCompression valueOf(String value)
NONE,
"gzip" for GZIP, or
"zip" for ZIP.
The last two can be optionally followed by "[level=X]", where X is a number from 0 to 9 (inclusive) specifying
desired compression level which takes effect during compression.
This method can reverse the result oftoString() method.
NullPointerException - if value is null.InvalidFormatException - if value is not a supported compression type string.public static StreamCompression detectCompressionByMimeType(String mimeType)
mimeType - the mime type.NONE is the mime type is not recognized.NullPointerException - if mimeType is null.public static StreamCompression detectCompressionByExtension(String fileName)
fileName - the file name.NONE is the file name extension is not recognized.NullPointerException - if fileName is null.public static StreamCompression detectCompressionByHeader(InputStream in) throws IOException
marks the stream, read first 4 bytes, and
resets the stream to an original state.in - the input stream.NONE is the header is not recognized.IOException - if an I/O error occurs.IllegalArgumentException - if in does not support mark.public static InputStream detectCompressionByHeaderAndDecompress(InputStream in) throws IOException
BufferedInputStream if
the original stream does not support mark before using
detectCompressionByHeader method.in - the input stream.IOException - if an I/O error occurs.public String getMimeType()
null for NONE,
"application/gzip" for GZIP, and
"application/zip" for ZIP.public String getExtension()
NONE,
".gz" for GZIP, and
".zip" for ZIP.public String stripExtension(String fileName)
fileName - the file name.NullPointerException - if fileName is null.public boolean hasSyncFlush()
public InputStream decompress(InputStream in) throws IOException
in - the input stream.NONE.IOException - if an I/O error occurs.public OutputStream compress(OutputStream out, String name) throws IOException
out - the output stream.name - the name of the file that is being compressed. It is used by ZIP compression format.NONE.IOException - if an I/O error occurs.public String toString()
public boolean equals(Object o)
Copyright © 2002–2025 Devexperts LLC. All rights reserved.