Package de.intarsys.tools.reader
Class LocationAwareReader
- java.lang.Object
-
- java.io.Reader
-
- java.io.FilterReader
-
- de.intarsys.tools.reader.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!
-
-
Constructor Summary
Constructors Constructor Description LocationAwareReader(java.io.Reader in)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidensureOpen()intgetColumn()intgetLine()intgetPosition()intread()intread(char[] cbuf, int off, int len)voidsetColumn(int column)voidsetLine(int line)voidsetLocation(int line, int column)Offset the current location to a user defined line and column.voidsetPosition(int position)longskip(long n)
-
-
-
Method Detail
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterReader- Throws:
java.io.IOException
-
ensureOpen
public void ensureOpen() throws java.io.IOException- Throws:
java.io.IOException
-
getColumn
public int getColumn()
- Specified by:
getColumnin interfaceILocationProvider
-
getLine
public int getLine()
- Specified by:
getLinein interfaceILocationProvider
-
getPosition
public int getPosition()
- Specified by:
getPositionin interfaceILocationProvider
-
read
public int read() throws java.io.IOException- Overrides:
readin classjava.io.FilterReader- Throws:
java.io.IOException
-
read
public int read(char[] cbuf, int off, int len) throws java.io.IOException- Overrides:
readin classjava.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 locationcolumn- 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:
skipin classjava.io.FilterReader- Throws:
java.io.IOException
-
-