Class BoundedLineReader

java.lang.Object
java.io.Reader
java.io.BufferedReader
org.deltafi.common.reader.BoundedLineReader
All Implemented Interfaces:
Closeable, AutoCloseable, Readable

public class BoundedLineReader extends BufferedReader
Buffered reader that tracks the number of bytes read and bounds the readLine method by the maxLineSize setting to limit the characters read into memory.
  • Constructor Details

    • BoundedLineReader

      public BoundedLineReader(Reader in, long maxLineSize)
    • BoundedLineReader

      public BoundedLineReader(Reader in, int sz, long maxLineSize)
  • Method Details

    • countBytesInNextLine

      public long countBytesInNextLine() throws IOException
      Counts the number of bytes in the next line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), a carriage return followed immediately by a line feed, or by reaching the end-of-file (EOF).
      Returns:
      the number of bytes in the next line of data including the terminating characters
      Throws:
      IOException - If an I/O error occurs or the line is not terminated before reading the maximum number bytes as set by maxLineSize
    • readLine

      public String readLine() throws IOException
      Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), a carriage return followed immediately by a line feed, or by reaching the end-of-file (EOF).
      Overrides:
      readLine in class BufferedReader
      Returns:
      A String containing the contents of the line, including any line-termination characters, or null if the end of the stream has been reached without reading any characters
      Throws:
      IOException - If an I/O error occurs or the line is not terminated before reading the maximum number bytes as set by maxLineSize
    • setMaxLineSize

      public void setMaxLineSize(long maxLineSize)
      Set the maxLineSize to a new value
      Parameters:
      maxLineSize - new maxLineSize to use