FileDocCategorySizeDatePackage
Support_ASimpleOutputStream.javaAPI DocAndroid 1.5 API2848Wed May 06 22:41:06 BST 2009tests.support

Support_ASimpleOutputStream

public class Support_ASimpleOutputStream extends OutputStream
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 byte[]
buf
public int
pos
public int
size
public boolean
throwExceptionOnNextUse
Constructors Summary
public Support_ASimpleOutputStream()


      
        this(DEFAULT_BUFFER_SIZE);
    
public Support_ASimpleOutputStream(boolean throwException)

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

        buf = new byte[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(int oneByte)

        if (throwExceptionOnNextUse) {
            throw new IOException("Exception thrown for testing purpose.");
        }
        if (pos < size) {
            buf[pos] = (byte)(oneByte & 255);
            pos++;
        } else {
            throw new IOException("Internal buffer overflow.");
        }