Reader that emulates
a reader of a specified size.
This implementation provides a light weight
object for testing with an Reader
where the contents don't matter.
One use case would be for testing the handling of
large Reader as it can emulate that
scenario without the overhead of actually processing
large numbers of characters - significantly speeding up
test execution times.
This implementation returns a space from the method that
reads a character and leaves the array unchanged in the read
methods that are passed a character array.
If alternative data is required the processChar() and
processChars() methods can be implemented to generate
data, for example:
public class TestReader extends NullReader {
public TestReader(int size) {
super(size);
}
protected char processChar() {
return ... // return required value here
}
protected void processChars(char[] chars, int offset, int length) {
for (int i = offset; i < length; i++) {
chars[i] = ... // set array value here
}
}
}
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private long | |
| private boolean | |
| private long | |
| private long | |
| private long | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public | NullReader(long
The size of the reader to emulate. size)Create a |
| public | NullReader(long
The size of the reader to emulate. size, boolean Whether this instance will support
the markSupported, boolean mark() functionality.Whether this implementation
will throw an throwEofException)EOFException or return -1 when the
end of file is reached.Create a |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Implements abstract java. Implements java. |
| private int | |
| public long | |
| public long | |
| public synchronized void | mark(int
The number of characters before this marked position
is invalid. readlimit)Overrides java. |
| public boolean | Returns: Whether mark is supported or not.Overrides java. |
| protected int | Returns: This implementation always returns zero.Return a character value for the |
| protected void | processChars(char[]
The character array chars, int The offset to start at. offset, int The number of characters. length)Process the characters for the |
| public int | Returns: Either The character value returned byprocessChar()
or -1 if the end of file has been reached and
throwEofException is set to false.Overrides java. |
| public int | Returns: The number of characters read or-1
if the end of file has been reached and
throwEofException is set to false.The character array to read into chars)Overrides java. |
| public int | Returns: The number of characters read or-1
if the end of file has been reached and
throwEofException is set to false.The character array to read into. chars, int The offset to start reading characters into. offset, int The number of characters to read. length)Implements abstract java. |
| public synchronized void | |
| public long | Returns: The number of characters skipped or-1
if the end of file has been reached and
throwEofException is set to false.The number of characters to skip. numberOfChars)Overrides java. |
| eof | back to summary |
|---|---|
| private boolean eof | |
| mark | back to summary |
|---|---|
| private long mark | |
| markSupported | back to summary |
|---|---|
| private boolean markSupported | |
| position | back to summary |
|---|---|
| private long position | |
| readlimit | back to summary |
|---|---|
| private long readlimit | |
| size | back to summary |
|---|---|
| private long size | |
| throwEofException | back to summary |
|---|---|
| private boolean throwEofException | |
| NullReader | back to summary |
|---|---|
| public NullReader(long size) Create a
| |
| NullReader | back to summary |
|---|---|
| public NullReader(long size, boolean markSupported, boolean throwEofException) Create a
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Implements abstract java. Implements java. Close this Reader - resets the internal state to the initial values.
| |
| doEndOfFile | back to summary |
|---|---|
| private int doEndOfFile() throws EOFException Handle End of File.
| |
| getPosition | back to summary |
|---|---|
| public long getPosition() Return the current position.
| |
| getSize | back to summary |
|---|---|
| public long getSize() Return the size this
| |
| mark | back to summary |
|---|---|
| public synchronized void mark(int readlimit) Overrides java. Mark the current position.
| |
| markSupported | back to summary |
|---|---|
| public boolean markSupported() Overrides java. Indicates whether mark is supported.
| |
| processChar | back to summary |
|---|---|
| protected int processChar() Return a character value for the This implementation returns zero.
| |
| processChars | back to summary |
|---|---|
| protected void processChars(char[] chars, int offset, int length) Process the characters for the This implementation leaves the character array unchanged.
| |
| read | back to summary |
|---|---|
| public int read() throws IOException Overrides java. Read a character.
| |
| read | back to summary |
|---|---|
| public int read(char[] chars) throws IOException Overrides java. Read some characters into the specified array.
| |
| read | back to summary |
|---|---|
| public int read(char[] chars, int offset, int length) throws IOException Implements abstract java. Read the specified number characters into an array.
| |
| reset | back to summary |
|---|---|
| public synchronized void reset() throws IOException Overrides java. Reset the stream to the point when mark was last called.
| |
| skip | back to summary |
|---|---|
| public long skip(long numberOfChars) throws IOException Overrides java. Skip a specified number of characters.
| |