FileDocCategorySizeDatePackage
Support_ASimpleReader.javaAPI DocAndroid 1.5 API1917Wed May 06 22:41:06 BST 2009tests.support

Support_ASimpleReader

public class Support_ASimpleReader extends Reader
An implementation of {@code Reader} that should serve as the underlying writer 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 char[]
buf
public int
pos
public int
len
public boolean
throwExceptionOnNextUse
Constructors Summary
public Support_ASimpleReader()


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

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

        buf = input.toCharArray();
        pos = 0;
        len = buf.length;
    
Methods Summary
public voidclose()

        if (throwExceptionOnNextUse) {
            throw new IOException("Exception thrown for testing purpose.");
        }
    
public intread(char[] dest, int offset, int count)

        if (throwExceptionOnNextUse) {
            throw new IOException("Exception thrown for testing purpose.");
        }
        int available = len - pos;
        if (available > 0) {
            int readable = (available < count ? available : count);
            System.arraycopy(buf, pos, dest, offset, readable);
            pos += readable;
            return readable;
        } else {
            return -1;
        }
    
public booleanready()

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