FixedLengthInputStreampublic class FixedLengthInputStream extends InputStream A filtering InputStream that stops allowing reads after the given length has been read. This
is used to allow a client to read directly from an underlying protocol stream without reading
past where the protocol handler intended the client to read. |
Fields Summary |
---|
private InputStream | mIn | private int | mLength | private int | mCount |
Constructors Summary |
---|
public FixedLengthInputStream(InputStream in, int length)
this.mIn = in;
this.mLength = length;
|
Methods Summary |
---|
public int | available()
return mLength - mCount;
| public int | read()
if (mCount < mLength) {
mCount++;
return mIn.read();
} else {
return -1;
}
| public int | read(byte[] b, int offset, int length)
if (mCount < mLength) {
int d = mIn.read(b, offset, Math.min(mLength - mCount, length));
if (d == -1) {
return -1;
} else {
mCount += d;
return d;
}
} else {
return -1;
}
| public int | read(byte[] b)
return read(b, 0, b.length);
| public java.lang.String | toString()
return String.format("FixedLengthInputStream(in=%s, length=%d)", mIn.toString(), mLength);
|
|