FileDocCategorySizeDatePackage
Support_ASimpleInputStream.javaAPI DocAndroid 1.5 API1946Wed May 06 22:41:06 BST 2009tests.support

Support_ASimpleInputStream

public class Support_ASimpleInputStream extends InputStream
An implementation of {@code InputStream} that should serve as the underlying stream for classes to be tested. In particular this implementation allows to have IOExecptions thrown on demand. For simplicity of use and understanding all fields are public.

Fields Summary
public static final int
DEFAULT_BUFFER_SIZE
public byte[]
buf
public int
pos
public int
len
public boolean
throwExceptionOnNextUse
Constructors Summary
public Support_ASimpleInputStream()


      
        this("BEGIN Bla bla, some text...END");
    
public Support_ASimpleInputStream(boolean throwException)

        this();
        throwExceptionOnNextUse = throwException;
    
public Support_ASimpleInputStream(String input)

        buf = input.getBytes();
        pos = 0;
        len = buf.length;
    
public Support_ASimpleInputStream(byte[] input)

        pos = 0;
        len = input.length;
        buf = new byte[len];
        System.arraycopy(input, 0, buf, 0, len);
    
Methods Summary
public intavailable()

        if (throwExceptionOnNextUse) {
            throw new IOException("Exception thrown for testing purpose.");
        }
        return len - pos;
    
public voidclose()

        if (throwExceptionOnNextUse) {
            throw new IOException("Exception thrown for testing purpose.");
        }
    
public intread()

        if (throwExceptionOnNextUse) {
            throw new IOException("Exception thrown for testing purpose.");
        }
        if (pos < len) {
            int res = buf[pos];
            pos++;
            return res;

        } else {
            return -1;
        }