Package nxt.util

Class CountingInputReader

All Implemented Interfaces:
Closeable, AutoCloseable, Readable

public class CountingInputReader extends FilterReader
CountingInputReader extends Reader to count the number of characters read
  • Constructor Details

    • CountingInputReader

      public CountingInputReader(Reader reader, long limit)
      Create a CountingInputReader for the supplied Reader
      Parameters:
      reader - Input reader
      limit - Maximum number of characters to be read
  • Method Details

    • read

      public int read() throws IOException
      Read a single character
      Overrides:
      read in class FilterReader
      Returns:
      Character or -1 if end of stream reached
      Throws:
      IOException - I/O error occurred
    • read

      public int read(char[] cbuf, int off, int len) throws IOException
      Read characters into an array starting at the specified offset
      Overrides:
      read in class FilterReader
      Parameters:
      cbuf - Character array
      off - Starting offset
      len - Number of characters to be read
      Returns:
      Number of characters read or -1 if end of stream reached
      Throws:
      IOException - I/O error occurred
    • skip

      public long skip(long n) throws IOException
      Skip characters in the input stream
      Overrides:
      skip in class FilterReader
      Parameters:
      n - Number of characters to skip
      Returns:
      Number of characters skipped or -1 if end of stream reached
      Throws:
      IOException - I/O error occurred
    • getCount

      public long getCount()
      Return the total number of characters read
      Returns:
      Character count