java intfilter,java.io.FilterInputStream分析

FilterInputStream

简述

继承自InputStream,实现接口Closeable, AutoCloseable。

成员:InputStream in使用volatile修饰

由于该方法全部会使用类java.io.InputStream,所以推荐先看关于InputStream的api或我写的关于InputStream的介绍

函数

构造函数:FilterInputStream(InputStream in),使用protected修饰

protected FilterInputStream(InputStream in) {

this.in = in;

}

函数:

int read()

在输入流读取指针所指下一个字节,并将指针移动到该字节上。字节值以int形式返回。如果没有可用的字节,因为已经到达了流的末端,则返回值-1。此方法会阻塞数据流,如果检测到阻塞会返回IOException。

public int read() throws IOException {

return in.read();

}

int read(byte b[])

调用函数read(byte b[], int off, int len)

public int read(byte b[]) throws IOException {

return read(b, 0, b.length);

}

int read(byte b[], int off, int len)

从输入流读取数据到字节数组。试图读取尽可能多的len字节,但是可以读取较小的数字。实际上读取的字节数作为一个整数返回。这个方法会阻塞直到输入数据可用,检测到文件的结束,或者抛出异常。

本方法通过read()以bety的形式读取数据。并存入b[]中。off为b起始字符,len为读取长度

public int read(byte b[], int off, int len) throws IOException {

return in.read(b, off, len);

}

long skip(long n)

利用read(byte b[], int off, int len)使指针偏移达到跳转的效果。返回跳过实际字节数。

public long skip(long n) throws IOException {

return in.skip(n);

}

int available()

可以在不阻塞的情况下从这个输入流中读取(或跳过)的字节数的估计值。

public int available() throws IOException {

return in.available();

}

void close()

关闭此数据流

public void close() throws IOException {

in.close();

}

void mark(int readlimit)

由synchronized修饰

标记这个输入流中的当前位置并保存在readlimit中。对重置方法的后续调用将在最后一个标记的位置重新定位该流,以便随后的读取重新读取相同的字节。

public synchronized void mark(int readlimit) {

in.mark(readlimit);

}

void reset()

由synchronized修饰

将此流重新定位到在此输入流上最后调用标记方法时的位置。

public synchronized void reset() throws IOException {

in.reset();

}

boolean markSupported()

是否支持标记和重置是特定输入流实例的不变属性

public boolean markSupported() {

return in.markSupported();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值