FileDocCategorySizeDatePackage
SizedInputStream.javaAPI DocAndroid 5.1 API1873Thu Mar 12 22:22:10 GMT 2015com.android.internal.util

SizedInputStream

public class SizedInputStream extends InputStream
Reads exact number of bytes from wrapped stream, returning EOF once those bytes have been read.

Fields Summary
private final InputStream
mWrapped
private long
mLength
Constructors Summary
public SizedInputStream(InputStream wrapped, long length)

        mWrapped = wrapped;
        mLength = length;
    
Methods Summary
public voidclose()

        super.close();
        mWrapped.close();
    
public intread()

        return Streams.readSingleByte(this);
    
public intread(byte[] buffer, int byteOffset, int byteCount)

        if (mLength <= 0) {
            return -1;
        } else if (byteCount > mLength) {
            byteCount = (int) mLength;
        }

        final int n = mWrapped.read(buffer, byteOffset, byteCount);
        if (n == -1) {
            if (mLength > 0) {
                throw new IOException("Unexpected EOF; expected " + mLength + " more bytes");
            }
        } else {
            mLength -= n;
        }
        return n;