Package totalcross.util.zip
Class CompressedStream
- java.lang.Object
-
- totalcross.io.Stream
-
- totalcross.util.zip.CompressedStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
GZipStream,ZipStream,ZLibStream
public abstract class CompressedStream extends Stream
Base class for stream filters that perform data compression and decompression.- Since:
- TotalCross 1.12
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.ObjectcompressedStreamstatic intDEFLATEUsed to create a stream that will be used for data compression.static intINFLATEUsed to create a stream that will be used for data decompression.protected intmode-
Fields inherited from class totalcross.io.Stream
skipBuffer
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCompressedStream()protectedCompressedStream(Stream stream, int mode)Creates a CompressedStream object that may be used to read compressed data from the given stream, or to write compressed data to the given stream.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this stream WITHOUT closing the underlying stream, which must be explicitly closed by the user.protected abstract java.lang.ObjectcreateDeflate(Stream stream)protected abstract java.lang.ObjectcreateInflate(Stream stream)protected voidfinalize()intreadBytes(byte[] buf, int start, int count)Attempts to read count bytes to the given byte array, starting from offset start.
This method can be used only with CompressedStreams created in INFLATE mode, and should be used only for reading compressed data from the original stream, returning uncompressed data on the give byte array.intwriteBytes(byte[] buf, int start, int count)Attempts to write count bytes from the given byte array, starting from offset start.
This method can be used only with CompressedStreams created in DEFLATE mode, and should be used only for compressing the contents of the given byte array, and writing the compressed data to the original stream.-
Methods inherited from class totalcross.io.Stream
asInputStream, asOutputStream, asStream, asStream, skipBytes, wrapInputStream, wrapInputStreamToStream, write, writeBytes, writeBytes, writeBytes
-
-
-
-
Field Detail
-
compressedStream
protected java.lang.Object compressedStream
-
mode
protected int mode
-
DEFLATE
public static final int DEFLATE
Used to create a stream that will be used for data compression. In this mode, you may NOT use the method readBytes.- See Also:
- Constant Field Values
-
INFLATE
public static final int INFLATE
Used to create a stream that will be used for data decompression. In this mode, you may NOT use the method writeBytes.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CompressedStream
protected CompressedStream()
-
CompressedStream
protected CompressedStream(Stream stream, int mode)
Creates a CompressedStream object that may be used to read compressed data from the given stream, or to write compressed data to the given stream.- Parameters:
stream- input stream.mode- its value must be either DEFLATE or INFLATE.- Since:
- TotalCross 1.12
-
-
Method Detail
-
createDeflate
protected abstract java.lang.Object createDeflate(Stream stream)
-
createInflate
protected abstract java.lang.Object createInflate(Stream stream)
-
readBytes
public int readBytes(byte[] buf, int start, int count) throws IOException, ZipExceptionAttempts to read count bytes to the given byte array, starting from offset start.
This method can be used only with CompressedStreams created in INFLATE mode, and should be used only for reading compressed data from the original stream, returning uncompressed data on the give byte array.- Specified by:
readBytesin classStream- Parameters:
buf- the byte array to read data intostart- the start position in the arraycount- the number of bytes to read- Throws:
IOExceptionZipException- Since:
- TotalCross 1.12
-
writeBytes
public int writeBytes(byte[] buf, int start, int count) throws IOExceptionAttempts to write count bytes from the given byte array, starting from offset start.
This method can be used only with CompressedStreams created in DEFLATE mode, and should be used only for compressing the contents of the given byte array, and writing the compressed data to the original stream.- Specified by:
writeBytesin classStream- Parameters:
buf- the byte array to write data fromstart- the start position in the byte arraycount- the number of bytes to write- Returns:
- the number of bytes actually written
- Throws:
IOException- Since:
- TotalCross 1.12
-
close
public void close() throws IOExceptionCloses this stream WITHOUT closing the underlying stream, which must be explicitly closed by the user.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
IOException- If an I/O error occurs.- Since:
- TotalCross 1.12
-
finalize
protected void finalize()
- Overrides:
finalizein classjava.lang.Object
-
-