intarsys runtime library

de.intarsys.tools.reader
Class LocationAwareReader

java.lang.Object
  extended by java.io.Reader
      extended by java.io.FilterReader
          extended by de.intarsys.tools.reader.LocationAwareReader
All Implemented Interfaces:
ILocationProvider, Closeable, Readable

public class LocationAwareReader
extends 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!


Constructor Summary
LocationAwareReader(Reader in)
           
 
Method Summary
 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
read, read
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocationAwareReader

public LocationAwareReader(Reader in)
Method Detail

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class FilterReader
Throws:
IOException

ensureOpen

public void ensureOpen()
                throws IOException
Throws:
IOException

getColumn

public int getColumn()
Specified by:
getColumn in interface ILocationProvider

getLine

public int getLine()
Specified by:
getLine in interface ILocationProvider

getPosition

public int getPosition()
Specified by:
getPosition in interface ILocationProvider

read

public int read()
         throws IOException
Overrides:
read in class FilterReader
Throws:
IOException

read

public int read(char[] cbuf,
                int off,
                int len)
         throws IOException
Overrides:
read in class FilterReader
Throws:
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 IOException
Overrides:
skip in class FilterReader
Throws:
IOException

intarsys runtime library

Copyright © 2008 intarsys consulting GmbH. All Rights Reserved.