Class NullReader
- All Implemented Interfaces:
- Closeable,- AutoCloseable,- Readable
Reader that emulates
 a reader of a specified size.
 
 This implementation provides a lightweight
 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
          }
      }
  }
 
 This class is not thread-safe.
- Since:
- 1.3
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionConstructs aReaderthat emulates a size 0 reader which supports marking and does not throw EOFException.NullReader(long size) Constructs aReaderthat emulates a specified size which supports marking and does not throw EOFException.NullReader(long size, boolean markSupported, boolean throwEofException) Constructs aReaderthat emulates a specified size with option settings.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()Closes this Reader.longGets the current position.longgetSize()Gets the size thisReaderemulates.voidmark(int readLimit) Marks the current position.booleanTests whether mark is supported.protected intReturns a character value for theread()method.protected voidprocessChars(char[] chars, int offset, int length) Process the characters for theread(char[], offset, length)method.intread()Reads a character.intread(char[] chars) Reads some characters into the specified array.intread(char[] chars, int offset, int length) Reads the specified number characters into an array.voidreset()Resets the stream to the point when mark was last called.longskip(long numberOfChars) Skips a specified number of characters.
- 
Field Details- 
INSTANCEThe singleton instance.- Since:
- 2.12.0
 
 
- 
- 
Constructor Details- 
NullReaderpublic NullReader()Constructs aReaderthat emulates a size 0 reader which supports marking and does not throw EOFException.- Since:
- 2.7
 
- 
NullReaderConstructs aReaderthat emulates a specified size which supports marking and does not throw EOFException.- Parameters:
- size- The size of the reader to emulate.
 
- 
NullReaderConstructs aReaderthat emulates a specified size with option settings.- Parameters:
- size- The size of the reader to emulate.
- markSupported- Whether this instance will support the- mark()functionality.
- throwEofException- Whether this implementation will throw an- EOFExceptionor return -1 when the end of file is reached.
 
 
- 
- 
Method Details- 
closeCloses this Reader. Resets the internal state to the initial values.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Specified by:
- closein class- Reader
- Throws:
- IOException- If an error occurs.
 
- 
getPositionGets the current position.- Returns:
- the current position.
 
- 
getSizeGets the size thisReaderemulates.- Returns:
- The size of the reader to emulate.
 
- 
markMarks the current position.- Overrides:
- markin class- Reader
- Parameters:
- readLimit- The number of characters before this marked position is invalid.
- Throws:
- UnsupportedOperationException- if mark is not supported.
 
- 
markSupportedTests whether mark is supported.- Overrides:
- markSupportedin class- Reader
- Returns:
- Whether mark is supported or not.
 
- 
processCharReturns a character value for theread()method.This implementation returns zero. - Returns:
- This implementation always returns zero.
 
- 
processCharsProcess the characters for theread(char[], offset, length)method.This implementation leaves the character array unchanged. - Parameters:
- chars- The character array
- offset- The offset to start at.
- length- The number of characters.
 
- 
readReads a character.- Overrides:
- readin class- Reader
- Returns:
- Either The character value returned by processChar()or-1if the end of file has been reached andthrowEofExceptionis set tofalse.
- Throws:
- EOFException- if the end of file is reached and- throwEofExceptionis set to- true.
- IOException- if trying to read past the end of file.
 
- 
readReads some characters into the specified array.- Overrides:
- readin class- Reader
- Parameters:
- chars- The character array to read into
- Returns:
- The number of characters read or -1if the end of file has been reached andthrowEofExceptionis set tofalse.
- Throws:
- EOFException- if the end of file is reached and- throwEofExceptionis set to- true.
- IOException- if trying to read past the end of file.
 
- 
readReads the specified number characters into an array.- Specified by:
- readin class- Reader
- Parameters:
- chars- The character array to read into.
- offset- The offset to start reading characters into.
- length- The number of characters to read.
- Returns:
- The number of characters read or -1if the end of file has been reached andthrowEofExceptionis set tofalse.
- Throws:
- EOFException- if the end of file is reached and- throwEofExceptionis set to- true.
- IOException- if trying to read past the end of file.
 
- 
resetResets the stream to the point when mark was last called.- Overrides:
- resetin class- Reader
- Throws:
- UnsupportedOperationException- if mark is not supported.
- IOException- If no position has been marked or the read limit has been exceeded since the last position was marked.
 
- 
skipSkips a specified number of characters.- Overrides:
- skipin class- Reader
- Parameters:
- numberOfChars- The number of characters to skip.
- Returns:
- The number of characters skipped or -1if the end of file has been reached andthrowEofExceptionis set tofalse.
- Throws:
- EOFException- if the end of file is reached and- throwEofExceptionis set to- true.
- IOException- if trying to read past the end of file.
 
 
-