Denne klasse implementerer et inputstrømfilter til læsning af filer i ZIP-filformatet. Inkluderer understøttelse af både komprimerede og ukomprimerede poster. Konstruktører:
ZipInputStream(InputStream in):
Opretter en ny ZIP-inputstrøm.
ZipInputStream(InputStream i Charset-tegnsæt):
Opretter en ny ZIP-inputstrøm Metoder:
int tilgængelig():
Returns 0 after EOF has reached for the current entry data otherwise always return . Programs should not count on this method to return the actual number of bytes that could be read without blocking.
Syntax : public int available() throws IOException Overrides: available in class InflaterInputStream Returns: 1 before EOF and 0 after EOF has reached for current entry. Programs should not count on this method to return the actual number of bytes that could be read without blocking. Throws: IOException
void close():
Closes this input stream and releases any system resources associated with the stream.
Syntax : public void close() throws IOException Overrides: close in class InflaterInputStream Throws: IOException
void closeEntry() :
Closes the current ZIP entry and positions the stream for reading the next entry.
Syntax : public void closeEntry() throws IOException Throws: ZipException IOException
beskyttet ZipEntry createZipEntry(strengnavn):
Creates a new ZipEntry object for the specified entry name.
Syntax : protected ZipEntry createZipEntry(String name) Parameters: name - the ZIP file entry name Returns: the ZipEntry just created
ZipEntry getNextEntry() :
Reads the next ZIP file entry and positions the stream at the beginning of the entry data.
Syntax : public ZipEntry getNextEntry() throws IOException Returns: the next ZIP file entry or null if there are no more entries Throws: ZipException IOException
int read(byte[] b int off int len):
Reads from the current ZIP entry into an array of bytes. If len is not zero the method blocks until some input is available; otherwise no bytes are read and 0 is returned.
Syntax : public int read(byte[] b int off int len) throws IOException Parameters: b - the buffer into which the data is read off - the start offset in the destination array b len - the maximum number of bytes read Returns: the actual number of bytes read or -1 if the end of the entry is reached Throws: NullPointerException IndexOutOfBoundsException ZipException IOException
langt spring(langt n):
Skips specified number of bytes in the current ZIP entry.
Syntax : public long skip(long n) throws IOException Parameters: n - the number of bytes to skip Returns: the actual number of bytes skipped Throws: ZipException IOException IllegalArgumentException
Java
//Java program demonstrating ZipInputStream methodsimportjava.io.FileInputStream;importjava.io.IOException;importjava.io.InputStream;importjava.util.Arrays;importjava.util.jar.JarInputStream;importjava.util.zip.ZipEntry;importjava.util.zip.ZipInputStream;classZipInputStreamDemoextendsZipInputStream{publicZipInputStreamDemo(InputStreamin){super(in);}publicstaticvoidmain(String[]args)throwsIOException{FileInputStreamfis=newFileInputStream('Awesome CV.zip');ZipInputStreamzis=newJarInputStream(fis);ZipInputStreamDemoobj=newZipInputStreamDemo(zis);//illustrating createZipEntry()ZipEntryze=obj.createZipEntry('ZipEntry');System.out.println(ze.getName());//illustrating getNextEntry()ZipEntryje=zis.getNextEntry();System.out.println(je.getName());//illustrating skip() methodzis.skip(3);//illustrating closeEntry() methodzis.closeEntry();zis.getNextEntry();byteb[]=newbyte[10];//illustrating available() method//Reads up to byte.length bytes of data from this input streamif(zis.available()==1)zis.read(b);System.out.println(Arrays.toString(b));//closing the streamzis.close();}}