Package net.sf.jazzlib
Class ZipInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- net.sf.jazzlib.InflaterInputStream
-
- net.sf.jazzlib.ZipInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,ZipConstants
public class ZipInputStream extends InflaterInputStream implements ZipConstants
This is a FilterInputStream that reads the files in an zip archive one after another. It has a special method to get the zip entry of the next file. The zip entry contains information about the file name size, compressed size, CRC, etc. It includes support for STORED and DEFLATED entries.
-
-
Field Summary
Fields Modifier and Type Field Description private intavailprivate CRC32crcprivate intcsizeprivate ZipEntryentryprivate booleanentryAtEOFprivate intflagsprivate intmethodprivate intsize-
Fields inherited from class net.sf.jazzlib.InflaterInputStream
buf, inf, len
-
Fields inherited from interface net.sf.jazzlib.ZipConstants
CENATT, CENATX, CENCOM, CENCRC, CENDSK, CENEXT, CENFLG, CENHDR, CENHOW, CENLEN, CENNAM, CENOFF, CENSIG, CENSIZ, CENTIM, CENVEM, CENVER, ENDCOM, ENDDCD, ENDHDR, ENDNRD, ENDOFF, ENDSIG, ENDSIZ, ENDSUB, ENDTOT, EXTCRC, EXTHDR, EXTLEN, EXTSIG, EXTSIZ, LOCCRC, LOCEXT, LOCFLG, LOCHDR, LOCHOW, LOCLEN, LOCNAM, LOCSIG, LOCSIZ, LOCTIM, LOCVER
-
-
Constructor Summary
Constructors Constructor Description ZipInputStream(java.io.InputStream in)Creates a new Zip input stream, reading a zip archive.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns 0 once the end of the stream (EOF) has been reached.voidclose()Closes the zip file.voidcloseEntry()Closes the current zip entry and moves to the next one.protected ZipEntrycreateZipEntry(java.lang.String name)Creates a new zip entry for the given name.private voidfillBuf()ZipEntrygetNextEntry()Open the next entry from the zip archive, and return its description.intread()Reads a byte from the current zip entry.intread(byte[] b, int off, int len)Reads a block of bytes from the current zip entry.private intreadBuf(byte[] out, int offset, int length)private voidreadDataDescr()private voidreadFully(byte[] out)private intreadLeByte()private intreadLeInt()Read an int in little endian byte order.private intreadLeShort()Read an unsigned short in little endian byte order.-
Methods inherited from class net.sf.jazzlib.InflaterInputStream
fill, skip
-
-
-
-
Method Detail
-
fillBuf
private void fillBuf() throws java.io.IOException- Throws:
java.io.IOException
-
readBuf
private int readBuf(byte[] out, int offset, int length) throws java.io.IOException- Throws:
java.io.IOException
-
readFully
private void readFully(byte[] out) throws java.io.IOException- Throws:
java.io.IOException
-
readLeByte
private final int readLeByte() throws java.io.IOException- Throws:
java.io.IOException
-
readLeShort
private final int readLeShort() throws java.io.IOExceptionRead an unsigned short in little endian byte order.- Throws:
java.io.IOException
-
readLeInt
private final int readLeInt() throws java.io.IOExceptionRead an int in little endian byte order.- Throws:
java.io.IOException
-
getNextEntry
public ZipEntry getNextEntry() throws java.io.IOException
Open the next entry from the zip archive, and return its description. If the previous entry wasn't closed, this method will close it.- Throws:
java.io.IOException
-
readDataDescr
private void readDataDescr() throws java.io.IOException- Throws:
java.io.IOException
-
closeEntry
public void closeEntry() throws java.io.IOExceptionCloses the current zip entry and moves to the next one.- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOExceptionDescription copied from class:InflaterInputStreamReturns 0 once the end of the stream (EOF) has been reached. Otherwise returns 1.- Overrides:
availablein classInflaterInputStream- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOExceptionReads a byte from the current zip entry.- Overrides:
readin classInflaterInputStream- Returns:
- the byte or -1 on EOF.
- Throws:
java.io.IOException- if a i/o error occured.ZipException- if the deflated stream is corrupted.
-
read
public int read(byte[] b, int off, int len) throws java.io.IOExceptionReads a block of bytes from the current zip entry.- Overrides:
readin classInflaterInputStream- Parameters:
b- the array to read and decompress data intooff- the offset indicating where the data should be placedlen- the number of bytes to decompress- Returns:
- the number of bytes read (may be smaller, even before EOF), or -1 on EOF.
- Throws:
java.io.IOException- if a i/o error occured.ZipException- if the deflated stream is corrupted.
-
close
public void close() throws java.io.IOExceptionCloses the zip file.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classInflaterInputStream- Throws:
java.io.IOException- if a i/o error occured.
-
createZipEntry
protected ZipEntry createZipEntry(java.lang.String name)
Creates a new zip entry for the given name. This is equivalent to new ZipEntry(name).- Parameters:
name- the name of the zip entry.
-
-