-------android培训、java培训、期待与您交流! ----------
public class MyBufferedInputStream
{
private InputStream in;
private int bufferedSize = 1024;
private byte[] bufb = new byte[bufferedSize];
private int p = 0;
public MyBufferedInputStream(InputStream in)
{
this.in = in;
}
public int read() throws IOException
{
int b = -1;
if(p == 0)
{
bufferedSize = in.read(bufb);
if(-1 == bufferedSize)
return -1;//读到-1时会停止
b = bufb[p];
p = (p+1)%bufferedSize;
}
else
{
b = bufb[p];
p = (p+1)%bufferedSize;
}
return b & 0xff; //扩展成int后,取低8位有效位
}
public void close() throws IOException
{
in.close();
}
}