Package groovy.io

Class LineColumnReader

All Implemented Interfaces:
Closeable, AutoCloseable, Readable

public class LineColumnReader extends BufferedReader
The LineColumnReader is an extension to BufferedReader that keeps track of the line and column information of where the cursor is.
Since:
1.8.0
  • Constructor Details

    • LineColumnReader

      public LineColumnReader(Reader reader)
      Constructor wrapping a Reader (FileReader, FileReader, InputStreamReader, etc.)
      Parameters:
      reader - the reader to wrap
  • Method Details

    • mark

      public void mark(int readAheadLimit) throws IOException
      Marks the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point.
      Overrides:
      mark in class BufferedReader
      Parameters:
      readAheadLimit - Limit on the number of characters that may be read while still preserving the mark. An attempt to reset the stream after reading characters up to this limit or beyond may fail. A limit value larger than the size of the input buffer will cause a new buffer to be allocated whose size is no smaller than limit. Therefore large values should be used with care.
      Throws:
      IOException
    • reset

      public void reset() throws IOException
      Resets the stream to the most recent mark.
      Overrides:
      reset in class BufferedReader
      Throws:
      IOException
    • read

      public int read() throws IOException
      Reads a single character.
      Overrides:
      read in class BufferedReader
      Returns:
      The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached
      Throws:
      IOException
    • read

      public int read(char[] chars, int startOffset, int length) throws IOException
      Reads characters into a portion of an array.
      Overrides:
      read in class BufferedReader
      Parameters:
      chars - Destination array of char
      startOffset - Offset at which to start storing characters
      length - Maximum number of characters to read
      Returns:
      an exception if an error occurs
      Throws:
      IOException
    • 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'), or a carriage return followed immediately by a linefeed.
      Overrides:
      readLine in class BufferedReader
      Returns:
      A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached
      Throws:
      IOException
    • skip

      public long skip(long toSkip) throws IOException
      Skips characters.
      Overrides:
      skip in class BufferedReader
      Parameters:
      toSkip - the number of characters to skip
      Returns:
      The number of characters actually skipped
      Throws:
      IOException
    • read

      public int read(char[] chars) throws IOException
      Reads characters into an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.
      Overrides:
      read in class Reader
      Parameters:
      chars - Destination buffer
      Returns:
      The number of characters read, or -1 if the end of the stream has been reached
      Throws:
      IOException
    • read

      public int read(CharBuffer buffer)
      Not implemented.
      Specified by:
      read in interface Readable
      Overrides:
      read in class Reader
      Parameters:
      buffer - Destination buffer
      Returns:
      The number of characters read, or -1 if the end of the stream has been reached
      Throws:
      UnsupportedOperationException - as the method is not implemented
    • close

      public void close() throws IOException
      Closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(), mark(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class BufferedReader
      Throws:
      IOException
    • getColumn

      public long getColumn()
    • setColumn

      public void setColumn(long column)
    • getColumnMark

      public long getColumnMark()
    • setColumnMark

      public void setColumnMark(long columnMark)
    • getLine

      public long getLine()
    • setLine

      public void setLine(long line)
    • getLineMark

      public long getLineMark()
    • setLineMark

      public void setLineMark(long lineMark)