FileDocCategorySizeDatePackage
FixedLengthInputStream.javaAPI DocAndroid 1.5 API2181Wed May 06 22:42:46 BST 2009com.android.email

FixedLengthInputStream

public 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 intavailable()

        return mLength - mCount;
    
public intread()

        if (mCount < mLength) {
            mCount++;
            return mIn.read();
        } else {
            return -1;
        }
    
public intread(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 intread(byte[] b)

        return read(b, 0, b.length);
    
public java.lang.StringtoString()

        return String.format("FixedLengthInputStream(in=%s, length=%d)", mIn.toString(), mLength);