Support_ASimpleWriterpublic 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 void | close()
if (throwExceptionOnNextUse) {
throw new IOException("Exception thrown for testing purpose.");
}
| public void | flush()
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.String | toString()
return new String(buf, 0, pos);
| public void | write(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");
}
|
|