Package totalcross.util.zip
Class ZLib
- java.lang.Object
-
- totalcross.util.zip.ZLib
-
public final class ZLib extends java.lang.ObjectThis class implements stream compression with the ZLib library.zlib is designed to be a free, general-purpose, legally unencumbered - that is, not covered by any patents -- lossless data-compression library for use on virtually any computer hardware and operating system. The zlib data format is itself portable across platforms.
-
-
Field Summary
Fields Modifier and Type Field Description static intBEST_COMPRESSIONCompression level for best compression, which is 9 in a scale from 0 (no compression) to 9 (best compression).static intBEST_SPEEDCompression level for fastest compression, which is 1 in a scale from 0 (no compression) to 9 (best compression).static intDEFAULT_COMPRESSIONDefault compression level.static intDEFAULT_STRATEGYDefault compression strategy.static intDEFLATEDCompression method for the deflate algorithm (the only one currently supported).static intFILTEREDCompression strategy best used for data consisting mostly of small values with a somewhat random distribution.static intHUFFMAN_ONLYCompression strategy for Huffman coding only.static intNO_COMPRESSIONCompression level for no compression, which is 0 in a scale from 0 (no compression) to 9 (best compression)
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static intdeflate(int compressionLevel, Stream in, Stream out)Deprecated.use #deflate(Stream, Stream, int) insteadstatic intdeflate(Stream in, Stream out)Deflates the given stream 'in' with the specified compression level, writing the result to the given stream 'out'.static intdeflate(Stream in, Stream out, int compressionLevel)Deflates the given stream 'in' with the specified compression level, writing the result to the given stream 'out'.static intdeflate(Stream in, Stream out, int compressionLevel, int strategy, boolean noWrap)Deflates the given stream 'in' using the specified strategy and compression level, writing the result to the given stream 'out'.static intinflate(Stream in, Stream out)Attempts to fully read the given stream 'in', inflating and writing to the given stream 'out'.static intinflate(Stream in, Stream out, int sizeIn)Attempts to read the number of bytes specified by 'sizeIn' from the the given stream 'in', inflating and writing to the given stream 'out'.static intinflate(Stream in, Stream out, int sizeIn, boolean noWrap)Attempts to read the number of bytes specified by 'sizeIn' from the the given stream 'in', inflating and writing to the given stream 'out'.
-
-
-
Field Detail
-
NO_COMPRESSION
public static final int NO_COMPRESSION
Compression level for no compression, which is 0 in a scale from 0 (no compression) to 9 (best compression)- See Also:
- Constant Field Values
-
BEST_SPEED
public static final int BEST_SPEED
Compression level for fastest compression, which is 1 in a scale from 0 (no compression) to 9 (best compression).- See Also:
- Constant Field Values
-
BEST_COMPRESSION
public static final int BEST_COMPRESSION
Compression level for best compression, which is 9 in a scale from 0 (no compression) to 9 (best compression).- See Also:
- Constant Field Values
-
DEFAULT_COMPRESSION
public static final int DEFAULT_COMPRESSION
Default compression level.- See Also:
- Constant Field Values
-
DEFAULT_STRATEGY
public static final int DEFAULT_STRATEGY
Default compression strategy.- See Also:
- Constant Field Values
-
DEFLATED
public static final int DEFLATED
Compression method for the deflate algorithm (the only one currently supported).- See Also:
- Constant Field Values
-
FILTERED
public static final int FILTERED
Compression strategy best used for data consisting mostly of small values with a somewhat random distribution.- See Also:
- Constant Field Values
-
HUFFMAN_ONLY
public static final int HUFFMAN_ONLY
Compression strategy for Huffman coding only.- See Also:
- Constant Field Values
-
-
Method Detail
-
deflate
public static int deflate(Stream in, Stream out) throws IOException
Deflates the given stream 'in' with the specified compression level, writing the result to the given stream 'out'. Compressed data will be generated in ZLIB format using the default strategy and the default compression level.- Parameters:
in- Stream to be deflatedout- Deflated stream.- Returns:
- Size of the deflated stream
- Throws:
IOException- See Also:
DEFAULT_COMPRESSION
-
deflate
public static int deflate(Stream in, Stream out, int compressionLevel) throws IOException
Deflates the given stream 'in' with the specified compression level, writing the result to the given stream 'out'. Compressed data will be generated in ZLIB format using the default strategy.- Parameters:
in- Stream to be deflatedout- Deflated stream.compressionLevel- Desired compression level, which must be between 0 and 9, or -1 for the default compression level- Returns:
- Size of the deflated stream
- Throws:
IOException- See Also:
NO_COMPRESSION,BEST_SPEED,BEST_COMPRESSION
-
deflate
@Deprecated public static int deflate(int compressionLevel, Stream in, Stream out) throws IOExceptionDeprecated.use #deflate(Stream, Stream, int) insteadDeflates the given stream 'in' with the specified compression level, writing the result to the given stream 'out'. Compressed data will be generated in ZLIB format using the default strategy.- Parameters:
compressionLevel- Desired compression level, which must be between 0 and 9, or -1 for the default compression levelin- Stream to be deflatedout- Deflated stream.- Returns:
- Size of the deflated stream
- Throws:
IOException- See Also:
NO_COMPRESSION,BEST_SPEED,BEST_COMPRESSION
-
deflate
public static int deflate(Stream in, Stream out, int compressionLevel, int strategy, boolean noWrap) throws IOException
Deflates the given stream 'in' using the specified strategy and compression level, writing the result to the given stream 'out'. If 'nowrap' is true then the ZLIB header and checksum fields will not be used in order to support the compression format used in both GZIP and PKZIP.- Parameters:
in- Stream to be deflatedout- Deflated stream.compressionLevel- compression level, which must be between 0 and 9, or -1 for the default compression levelstrategy- the compression strategynoWrap- if true then use GZIP compatible compression- Returns:
- Size of the deflated stream
- Throws:
IOException- See Also:
NO_COMPRESSION,BEST_SPEED,BEST_COMPRESSION
-
inflate
public static int inflate(Stream in, Stream out) throws IOException, ZipException
Attempts to fully read the given stream 'in', inflating and writing to the given stream 'out'.- Parameters:
in- Deflated input streamout- Inflated output stream- Returns:
- Size of the inflated stream
- Throws:
IOExceptionZipException
-
inflate
public static int inflate(Stream in, Stream out, int sizeIn) throws IOException, ZipException
Attempts to read the number of bytes specified by 'sizeIn' from the the given stream 'in', inflating and writing to the given stream 'out'. If 'sizeIn' is -1, it will attempt to fully read the stream.- Parameters:
in- Deflated input streamout- Inflated output streamsizeIn- How many bytes to read, or -1 to read untilin's end- Returns:
- Size of the inflated stream
- Throws:
ZipExceptionIOException
-
inflate
public static int inflate(Stream in, Stream out, int sizeIn, boolean noWrap) throws IOException, ZipException
Attempts to read the number of bytes specified by 'sizeIn' from the the given stream 'in', inflating and writing to the given stream 'out'. If 'sizeIn' is -1, it will attempt to fully read the stream. If the parameter 'noWrap' is true then the ZLIB header and checksum fields will not be used. This provides compatibility with the compression format used by both GZIP and PKZIP.
Note: When using the 'noWrap' option it is also necessary to provide an extra "dummy" byte as input. This is required by the ZLIB native library in order to support certain optimizations.- Parameters:
in- Deflated input streamout- Inflated output streamsizeIn- How many bytes to read, or -1 to read untilin's endnoWrap- if true then support GZIP compatible compression- Returns:
- Size of the inflated stream
- Throws:
ZipExceptionIOException
-
-