Package totalcross.util.zip
Class ZipStream
- java.lang.Object
-
- totalcross.io.Stream
-
- totalcross.util.zip.CompressedStream
-
- totalcross.util.zip.ZipStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class ZipStream extends CompressedStream
This class implements a stream filter for reading and writing files in the ZIP file format. Currently supports only compressed entries.
See the sammple TotalCross3/src/tc/samples/util/zip/zip.- Since:
- TotalCross 1.20
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFLATEDCompression method for compressed (DEFLATED) entries.static intSTOREDCompression method for uncompressed (STORED) entries.-
Fields inherited from class totalcross.util.zip.CompressedStream
compressedStream, DEFLATE, INFLATE, mode
-
Fields inherited from class totalcross.io.Stream
skipBuffer
-
-
Constructor Summary
Constructors Constructor Description ZipStream(RandomAccessStream stream, int mode)Creates a new ZIP stream 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 Concrete Methods Modifier and Type Method Description intavailable()Returns 0 after EOF has reached for the current entry data, otherwise always return 1.
Programs should not count on this method to return the actual number of bytes that could be read without blocking.voidclose()Closes this stream WITHOUT closing the underlying stream, which must be explicitly closed by the user.voidcloseEntry()Closes the current ZIP entry and positions the stream for reading (INFLATE) or writing (DEFLATE) the next entry.protected java.lang.ObjectcreateDeflate(Stream stream)protected java.lang.ObjectcreateInflate(Stream stream)ZipEntrygetNextEntry()Reads the next ZIP file entry and positions the stream at the beginning of the entry data.voidputNextEntry(ZipEntry entry)Begins writing a new ZIP file entry and positions the stream to the start of the entry data.-
Methods inherited from class totalcross.util.zip.CompressedStream
finalize, readBytes, writeBytes
-
Methods inherited from class totalcross.io.Stream
asInputStream, asOutputStream, asStream, asStream, skipBytes, wrapInputStream, wrapInputStreamToStream, write, writeBytes, writeBytes, writeBytes
-
-
-
-
Field Detail
-
STORED
public static final int STORED
Compression method for uncompressed (STORED) entries.- See Also:
- Constant Field Values
-
DEFLATED
public static final int DEFLATED
Compression method for compressed (DEFLATED) entries.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ZipStream
public ZipStream(RandomAccessStream stream, int mode)
Creates a new ZIP stream 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.20
-
-
Method Detail
-
createDeflate
protected java.lang.Object createDeflate(Stream stream)
- Specified by:
createDeflatein classCompressedStream
-
createInflate
protected java.lang.Object createInflate(Stream stream)
- Specified by:
createInflatein classCompressedStream
-
available
public int available() throws IOExceptionReturns 0 after EOF has reached for the current entry data, otherwise always return 1.
Programs should not count on this method to return the actual number of bytes that could be read without blocking.- Returns:
- 1 before EOF and 0 after EOF has reached for current entry.
- Throws:
IOException- if an I/O error occurs.- Since:
- TotalCross 1.20
-
getNextEntry
public ZipEntry getNextEntry() throws IOException
Reads the next ZIP file entry and positions the stream at the beginning of the entry data.- Returns:
- the next ZIP file entry, or null if there are no more entries
- Throws:
IOException- if an I/O error has occurred- Since:
- TotalCross 1.20
-
putNextEntry
public void putNextEntry(ZipEntry entry) throws IOException, ZipException
Begins writing a new ZIP file entry and positions the stream to the start of the entry data. Closes the current entry if still active.- Parameters:
entry- the ZIP entry to be written- Throws:
IOException- if an I/O error has occurredZipException- Since:
- TotalCross 1.20
-
closeEntry
public void closeEntry() throws IOException, ZipExceptionCloses the current ZIP entry and positions the stream for reading (INFLATE) or writing (DEFLATE) the next entry.- Throws:
IOException- if an I/O error has occurredZipException- Since:
- TotalCross 1.20
-
close
public void close() throws IOExceptionDescription copied from class:CompressedStreamCloses 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- Overrides:
closein classCompressedStream- Throws:
IOException- If an I/O error occurs.
-
-