JAVAutil。拉链Java中的InflateInputStream类

此类实现了一个流过滤器,用于以“deflate”压缩格式解压缩数据。它还用作其他解压缩过滤器的基础,例如GZIPInputStream。 建设者

null
  • 充气输入流(输入流输入): 创建具有默认解压器和缓冲区大小的新输入流。
  • 充气器输入流(输入流输入,充气器输入): 使用指定的解压器和默认缓冲区大小创建新的输入流。
  • 充气器输入流(输入流输入、充气器输入、整数大小): 创建具有指定解压器和缓冲区大小的新输入流。

方法:

  • int available(): 达到EOF后返回0,否则始终返回1。
    Syntax : public int available()
                  throws IOException
    Returns:
    1 before EOF and 0 after EOF.
    Throws:
    IOException
    
  • void close(): 关闭此输入流并释放与该流关联的所有系统资源。
    Syntax : public void close()
               throws IOException
    Throws:
    IOException 
    
  • 受保护的空白填充() 用更多要解压缩的数据填充输入缓冲区。
    Syntax : protected void fill()
                 throws IOException
    Throws:
    IOException
    
  • 无效标记(int readlimit): 标记此输入流中的当前位置。
    Syntax : public void mark(int readlimit)
    Parameters:
    readlimit - the maximum limit of bytes that can be read
    before the mark position becomes invalid.
  • 支持布尔标记() 测试此输入流是否支持标记和重置方法。
    Syntax : public boolean markSupported()
    Returns:
    a boolean indicating if this stream type supports the mark and reset methods.
    
  • int read(): 读取一个字节的未压缩数据。
    Syntax : public int read()
             throws IOException
    Returns:
    the byte read, or -1 if end of compressed input is reached
    Throws:
    IOException
  • int read(字节[]b,int off,int len): 将未压缩的数据读入字节数组。
    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(): 将此流重新定位到上次在此输入流上调用mark方法时的位置。
    Syntax : public void reset()
               throws IOException
    Throws:
    IOException
    
  • 长跳跃(长n): 跳过未压缩数据的指定字节数。
    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 

节目:

//Java program to demonstrate InflaterInputStream
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
class InflaterInputStreamDemo
{
public static void main(String[] args) throws IOException
{
FileOutputStream fos = new FileOutputStream( "file.txt" );
//Assign FileOutputStream to DeflaterOutputStream
DeflaterOutputStream dos = new DeflaterOutputStream(fos);
//write it into DeflaterOutputStream
for ( int i = 0 ; i < 10 ; i++)
{
dos.write(i);
}
dos.flush();
dos.close();
FileInputStream fis = new FileInputStream( "file.txt" );
InflaterInputStream iis = new InflaterInputStream(fis);
//illustrating available() method
System.out.println(iis.available());
//illustrating mark and markSupported()
if (iis.markSupported())
iis.mark( 15 );
else
System.out.println( false );
//illustrating skip() method
iis.skip( 3 );
//illustrating read()
for ( int i = 0 ; i < 3 ; i++)
{
System.out.print(iis.read());
}
//illustrating read(byte[] b,int off,int len)
byte b[]= new byte [ 4 ];
for ( int i = 0 ; i < 4 ; i++)
{
iis.read(b, 0 , 4 );
}
for ( int i = 0 ; i < 4 ; i++)
{
System.out.print(b[i]);
}
}
}


输出:

1
false
3456789

下一篇文章: JAVAutil。拉链Java中的InflaterOutputStream类

本文由 尼森特·夏尔马 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。

如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享