FileDocCategorySizeDatePackage
Support_ASimpleWriter.javaAPI DocAndroid 1.5 API2235Wed May 06 22:41:06 BST 2009tests.support

Support_ASimpleWriter

public class Support_ASimpleWriter extends Writer
An implementation of {@code OutputStream} 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 char[]
buf
public int
pos
public int
size
public boolean
throwExceptionOnNextUse
Constructors Summary
public Support_ASimpleWriter()


      
        this(DEFAULT_BUFFER_SIZE);
    
public Support_ASimpleWriter(boolean throwException)

        this(DEFAULT_BUFFER_SIZE);
        throwExceptionOnNextUse = throwException;
    
public Support_ASimpleWriter(int bufferSize)

        buf = new char[bufferSize];
        pos = 0;
        size = bufferSize;
    
Methods Summary
public voidclose()

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

        if (throwExceptionOnNextUse) {
            throw new IOException("Exception thrown for testing purpose.");
        }
    
public byte[]toByteArray()

        byte[] toReturn = new byte[pos];
        System.arraycopy(buf, 0, toReturn, 0, pos);
        return toReturn;
    
public java.lang.StringtoString()

        return new String(buf, 0, pos);
    
public voidwrite(char[] src, int offset, int count)

        if (throwExceptionOnNextUse) {
            throw new IOException("Exception thrown for testing purpose.");
        }
        if (offset < 0 || count < 0 || (offset + count) > buf.length) {
            throw new IndexOutOfBoundsException(); //$NON-NLS-1$
        }
        try {
            System.arraycopy(src, offset, buf, pos, count);
            pos += count;
        } catch (IndexOutOfBoundsException e) {
            pos = size;
            throw new IOException("Internal Buffer Overflow");
        }