本帖最后由 李南江 于 2012-5-10 00:44 编辑
自定义字节流缓冲区~看了几遍了还是有一步不是很明白 求详解
class myBufferedInputStream{
private InputStream in;
private int pos = 0,count =0;
private byte[] by = new byte[1024];
myBufferedInputStream(InputStream in){
this.in=in;
}
public int myRead() throws Exception{
if(count==0){
count = in.read(by);
if(count<0)//一直读不懂这里什么情况count会小于0,感觉应该只能等于0
{
return -1;
}
pos=0;
byte b = by[pos];
count--;
pos++;
return b&255;
}
else if(count>0){
byte b = by[pos];
count--;
pos++;
return b&255;
}
return -1;
}
} |
|