Class LocationAwareReader

  • All Implemented Interfaces:
    ILocationProvider, java.io.Closeable, java.lang.AutoCloseable, java.lang.Readable

    public class LocationAwareReader
    extends java.io.FilterReader
    implements ILocationProvider
    An implementation of ILocationProvider. This class can be "piped" in a reader stream to access the current "pointer" into the data.

    A common pitfall is to read the ILocationProvider via a BufferedReader - this will certainly not provide with a correct character location!

    • Field Summary

      • Fields inherited from class java.io.FilterReader

        in
      • Fields inherited from class java.io.Reader

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      LocationAwareReader​(java.io.Reader in)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void ensureOpen()  
      int getColumn()  
      int getLine()  
      int getPosition()  
      int read()  
      int read​(char[] cbuf, int off, int len)  
      void setColumn​(int column)  
      void setLine​(int line)  
      void setLocation​(int line, int column)
      Offset the current location to a user defined line and column.
      void setPosition​(int position)  
      long skip​(long n)  
      • Methods inherited from class java.io.FilterReader

        mark, markSupported, ready, reset
      • Methods inherited from class java.io.Reader

        nullReader, read, read, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LocationAwareReader

        public LocationAwareReader​(java.io.Reader in)
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.FilterReader
        Throws:
        java.io.IOException
      • ensureOpen

        public void ensureOpen()
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        public int read()
                 throws java.io.IOException
        Overrides:
        read in class java.io.FilterReader
        Throws:
        java.io.IOException
      • read

        public int read​(char[] cbuf,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.FilterReader
        Throws:
        java.io.IOException
      • setColumn

        public void setColumn​(int column)
        Parameters:
        column - The column to set.
      • setLine

        public void setLine​(int line)
        Parameters:
        line - The line to set.
      • setLocation

        public void setLocation​(int line,
                                int column)
        Offset the current location to a user defined line and column.
        Parameters:
        line - The line we want the reader to accept as new location
        column - The column we want the reader to accept as new location
      • setPosition

        public void setPosition​(int position)
        Parameters:
        position - The position to set.
      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Overrides:
        skip in class java.io.FilterReader
        Throws:
        java.io.IOException