| java.lang.Object java.io.Reader org.apache.commons.io.input.NullReader
NullReader | public class NullReader extends Reader (Code) | | A functional, light weight
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
}
}
}
since: Commons IO 1.3 version: $Revision: 463529 $ |
Constructor Summary | |
public | NullReader(long size) Create a
Reader that emulates a specified size
which supports marking and does not throw EOFException. | public | NullReader(long size, boolean markSupported, boolean throwEofException) Create a
Reader that emulates a specified
size with option settings. |
Method Summary | |
public void | close() Close this Reader - resets the internal state to
the initial values. | public long | getPosition() Return the current position. | public long | getSize() Return the size this
Reader emulates. | public synchronized void | mark(int readlimit) Mark the current position. | public boolean | markSupported() Indicates whether mark is supported. | protected int | processChar() Return a character value for the read() method. | protected void | processChars(char[] chars, int offset, int length) Process the characters for the read(char[], offset, length)
method. | public int | read() Read a character. | public int | read(char[] chars) Read some characters into the specified array. | public int | read(char[] chars, int offset, int length) Read the specified number characters into an array.
Parameters: chars - The character array to read into. Parameters: offset - The offset to start reading characters into. Parameters: length - The number of characters to read. | public synchronized void | reset() Reset the stream to the point when mark was last called. | public long | skip(long numberOfChars) Skip a specified number of characters.
Parameters: numberOfChars - The number of characters to skip. |
NullReader | public NullReader(long size)(Code) | | Create a
Reader that emulates a specified size
which supports marking and does not throw EOFException.
Parameters: size - The size of the reader to emulate. |
NullReader | public NullReader(long size, boolean markSupported, boolean throwEofException)(Code) | | Create a
Reader that emulates a specified
size with option settings.
Parameters: size - The size of the reader to emulate. Parameters: markSupported - Whether this instance will supportthe mark() functionality. Parameters: throwEofException - Whether this implementationwill throw an EOFException or return -1 when theend of file is reached. |
close | public void close() throws IOException(Code) | | Close this Reader - resets the internal state to
the initial values.
throws: IOException - If an error occurs. |
getPosition | public long getPosition()(Code) | | Return the current position.
the current position. |
getSize | public long getSize()(Code) | | Return the size this
Reader emulates.
The size of the reader to emulate. |
mark | public synchronized void mark(int readlimit)(Code) | | Mark the current position.
Parameters: readlimit - The number of characters before this marked positionis invalid. throws: UnsupportedOperationException - if mark is not supported. |
markSupported | public boolean markSupported()(Code) | | Indicates whether mark is supported.
Whether mark is supported or not. |
processChar | protected int processChar()(Code) | | Return a character value for the read() method.
This implementation returns zero.
This implementation always returns zero. |
processChars | protected void processChars(char[] chars, int offset, int length)(Code) | | Process the characters for the read(char[], offset, length)
method.
This implementation leaves the character array unchanged.
Parameters: chars - The character array Parameters: offset - The offset to start at. Parameters: length - The number of characters. |
read | public int read() throws IOException(Code) | | Read a character.
Either The character value returned by processChar() or -1 if the end of file has been reached andthrowEofException is set to false . throws: EOFException - if the end of file is reached andthrowEofException is set to true . throws: IOException - if trying to read past the end of file. |
read | public int read(char[] chars) throws IOException(Code) | | Read some characters into the specified array.
Parameters: chars - The character array to read into The number of characters read or -1 if the end of file has been reached andthrowEofException is set to false . throws: EOFException - if the end of file is reached andthrowEofException is set to true . throws: IOException - if trying to read past the end of file. |
read | public int read(char[] chars, int offset, int length) throws IOException(Code) | | Read the specified number characters into an array.
Parameters: chars - The character array to read into. Parameters: offset - The offset to start reading characters into. Parameters: length - The number of characters to read. The number of characters read or -1 if the end of file has been reached andthrowEofException is set to false . throws: EOFException - if the end of file is reached andthrowEofException is set to true . throws: IOException - if trying to read past the end of file. |
reset | public synchronized void reset() throws IOException(Code) | | Reset the stream to the point when mark was last called.
throws: UnsupportedOperationException - if mark is not supported. throws: IOException - If no position has been markedor the read limit has been exceed since the last position wasmarked. |
skip | public long skip(long numberOfChars) throws IOException(Code) | | Skip a specified number of characters.
Parameters: numberOfChars - The number of characters to skip. The number of characters skipped or -1 if the end of file has been reached andthrowEofException is set to false . throws: EOFException - if the end of file is reached andthrowEofException is set to true . throws: IOException - if trying to read past the end of file. |
|
|