PeekableInputStreampublic class PeekableInputStream extends InputStream A filtering InputStream that allows single byte "peeks" without consuming the byte. The
client of this stream can call peek() to see the next available byte in the stream
and a subsequent read will still return the peeked byte. |
Fields Summary |
---|
private InputStream | mIn | private boolean | mPeeked | private int | mPeekedByte |
Constructors Summary |
---|
public PeekableInputStream(InputStream in)
this.mIn = in;
|
Methods Summary |
---|
public int | peek()
if (!mPeeked) {
mPeekedByte = read();
mPeeked = true;
}
return mPeekedByte;
| public int | read()
if (!mPeeked) {
return mIn.read();
} else {
mPeeked = false;
return mPeekedByte;
}
| public int | read(byte[] b, int offset, int length)
if (!mPeeked) {
return mIn.read(b, offset, length);
} else {
b[0] = (byte)mPeekedByte;
mPeeked = false;
int r = mIn.read(b, offset + 1, length - 1);
if (r == -1) {
return 1;
} else {
return r + 1;
}
}
| public int | read(byte[] b)
return read(b, 0, b.length);
| public java.lang.String | toString()
return String.format("PeekableInputStream(in=%s, peeked=%b, peekedByte=%d)",
mIn.toString(), mPeeked, mPeekedByte);
|
|