Tato třída implementuje proudový filtr pro dekomprimaci dat v kompresním formátu 'deflate'. Používá se také jako základ pro další dekompresní filtry, jako je GZIPInputStream. Konstruktéři
InflaterInputStream(InputStream in) :
Vytvoří nový vstupní proud s výchozí dekomprimací a velikostí vyrovnávací paměti.
InflaterInputStream(InputStream v Inflater inf) :
Vytvoří nový vstupní proud se zadaným dekomprimátorem a výchozí velikostí vyrovnávací paměti.
InflaterInputStream(InputStream ve velikosti Inflater inf int) :
Vytvoří nový vstupní datový proud se zadanou dekomprimací a velikostí vyrovnávací paměti. Metody:
int dostupné() :
Returns 0 after EOF has been reached otherwise always return 1.
Syntax : public int available() throws IOException Returns: 1 before EOF and 0 after EOF. Throws: IOException
void close() :
Closes this input stream and releases any system resources associated with the stream.
Syntax : public void close() throws IOException Throws: IOException
Syntax : public void mark(int readlimit) Parameters: readlimit - the maximum limit of bytes that can be read before the mark position becomes invalid.
boolean markSupported() :
Tests if this input stream supports the mark and reset methods.
Syntax : public boolean markSupported() Returns: a boolean indicating if this stream type supports the mark and reset methods.
int read() :
Reads a byte of uncompressed data.
Syntax : public int read() throws IOException Returns: the byte read or -1 if end of compressed input is reached Throws: IOException
int read(byte[] b int off int len) :
Reads uncompressed data into an array of bytes.
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 compressed input is reached. Throws: NullPointerException IndexOutOfBoundsException ZipException IOException
void reset() :
Repositions this stream to the position at the time the mark method was last called on this input stream.
Syntax : public void reset() throws IOException Throws: IOException
dlouhý skok (dlouhé n):
Skips specified number of bytes of uncompressed data.
Syntax : public long skip(long n) throws IOException Parameters: n - the number of bytes to skip Returns: the actual number of bytes skipped. Throws: IOException IllegalArgumentException
Naprogramovat: Java
//Java program to demonstrate InflaterInputStreamimportjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.IOException;importjava.util.zip.DeflaterOutputStream;importjava.util.zip.InflaterInputStream;classInflaterInputStreamDemo{publicstaticvoidmain(String[]args)throwsIOException{FileOutputStreamfos=newFileOutputStream('file.txt');//Assign FileOutputStream to DeflaterOutputStreamDeflaterOutputStreamdos=newDeflaterOutputStream(fos);//write it into DeflaterOutputStreamfor(inti=0;i<10;i++){dos.write(i);}dos.flush();dos.close();FileInputStreamfis=newFileInputStream('file.txt');InflaterInputStreamiis=newInflaterInputStream(fis);//illustrating available() methodSystem.out.println(iis.available());//illustrating mark and markSupported()if(iis.markSupported())iis.mark(15);elseSystem.out.println(false);//illustrating skip() methodiis.skip(3);//illustrating read()for(inti=0;i<3;i++){System.out.print(iis.read());}//illustrating read(byte[] bint offint len)byteb[]=newbyte[4];for(inti=0;i<4;i++){iis.read(b04);}for(inti=0;i<4;i++){System.out.print(b[i]);}}}
výstup:
1 false 3456789
Další článek: Třída Java.util.zip.InflaterOutputStream v jazyce Java Vytvořit kvíz