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

PeekableInputStream

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

        if (!mPeeked) {
            mPeekedByte = read();
            mPeeked = true;
        }
        return mPeekedByte;
    
public intread()

        if (!mPeeked) {
            return mIn.read();
        } else {
            mPeeked = false;
            return mPeekedByte;
        }
    
public intread(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 intread(byte[] b)

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

        return String.format("PeekableInputStream(in=%s, peeked=%b, peekedByte=%d)",
                mIn.toString(), mPeeked, mPeekedByte);