日期:2014-05-20 浏览次数:20748 次
import java.io.IOException;
import java.io.InputStream;
public class myOwnStream1
{
public static void main(String[] args) throws Exception
{
byte[] b = new byte[16];
for (int i = 0; i < b.length; i++)
{
b[i] = (byte) i;
}
MyByteArrayInuputStream mbais = new MyByteArrayInuputStream(b);
while (true)
{
int c = mbais.read();
if (c < 0)
{
break;
}
System.out.print(c + " ");
}
mbais.close();
}
}
class MyByteArrayInuputStream extends InputStream
{
protected byte[] data;
protected int ptr = 0;
public MyByteArrayInuputStream(byte[] b)
{
this.data = b;
}
@Override
public int read() throws IOException
{
return (ptr < data.length) ? (data[ptr++]) : -1;
// return (ptr < data.length) ? (data[ptr+1]) : -1;
}
}