Class LocationReader<D>
- Type Parameters:
D- the type of document identifiers
- All Implemented Interfaces:
Closeable,AutoCloseable,Readable
Characters are obtained from another Reader. For the consistency of the computed location information, it is required that there are no other, concurrent consumers of characters from that source.
For tracking line and column number information, the following
ISO control characters are recognized:
'\n' not preceded by a '\r'
advances the line number and resets the column number.
'\r' and the sequence "\r\n" are normalized
to '\n' and do the same.
This corresponds to the behaviour of LineNumberReader.
'\f' is delivered as a normal character.
This is required for processing Java source texts, see
language specification.
'\t' advances the column number to the next tab stop.
Tab stops are set at multiples of the given tabWidth.
Other ISO "group zero" control
characters must not occur among the input code points, or a IllegalArgumentException is thrown.
- See Also:
-
Field Summary
Fields inherited from class java.io.FilterReader
in -
Constructor Summary
ConstructorsConstructorDescriptionLocationReader(Reader in, D documentId, int firstLine, int firstColumn) Constructor, which sets the tabulator width to one.LocationReader(Reader in, D documentId, int firstLine, int firstColumn, int tabWidth) Constructor with an arbitrary tabulator width>=1. -
Method Summary
Modifier and TypeMethodDescriptiongetPoint()Returns the position immediately before to next-to-read character.Construct a region from the start point (memorized by the last call tosetBeginPoint()) to the current point.voidmark(int readAheadLimit) Additionally the current location is memorized for a laterreset(), and the effect ofsetBeginPoint()is cleared.intread().intread(char[] cbuf, int off, int len) .voidreset().voidMemorize the current location as the start point of a region, later constructed bygetRegion().Methods inherited from class java.io.FilterReader
close, markSupported, ready, skipMethods inherited from class java.io.Reader
nullReader, read, read, transferTo
-
Constructor Details
-
LocationReader
Constructor, which sets the tabulator width to one.- Parameters:
in- the underlying character stream.documentId- the document id for all locations to generate.firstLine- the numeric value>= 0with which the line numbers start, or the special valuesLocation.UNKNOWNorLocation.NOT_APPLICABLE.firstColumn- the numeric value>= 0with which the column numbers start, or the special valuesLocation.UNKNOWNorLocation.NOT_APPLICABLE.
-
LocationReader
Constructor with an arbitrary tabulator width>=1.- Parameters:
in- the underlying character stream.documentId- the document id for all locations to generate.firstLine- the numeric value>= 0with which the line numbers start, or the special valuesLocation.UNKNOWNorLocation.NOT_APPLICABLE.firstColumn- the numeric value>= 0with which the column numbers start, or the special valuesLocation.UNKNOWNorLocation.NOT_APPLICABLE.tabWidth- how to expand tabulator characters =\t=^I. Must be>= 1.
-
-
Method Details
-
getPoint
Returns the position immediately before to next-to-read character.- Returns:
- the current location.
-
setBeginPoint
public void setBeginPoint()Memorize the current location as the start point of a region, later constructed bygetRegion(). -
getRegion
Construct a region from the start point (memorized by the last call tosetBeginPoint()) to the current point.- Returns:
- the constructed region.
- Throws:
IllegalStateException- ifsetBeginPoint()has not been called.
-
read
. Unifies the different CR/LF-strategies: returns "\n" for "\r" and "\r\n". This corresponds to the behaviour ofLineNumberReader. Additionally the current location is updated according to the read characters.- Overrides:
readin classFilterReader- Throws:
IOException
-
read
. Unifies the different CR/LF-strategies: returns "\n" for "\r" and "\r\n". This corresponds to the behaviour ofLineNumberReader. Additionally the current location is updated according to the read characters.- Overrides:
readin classFilterReader- Throws:
IOException
-
mark
Additionally the current location is memorized for a laterreset(), and the effect ofsetBeginPoint()is cleared.- Overrides:
markin classFilterReader- Throws:
IOException
-
reset
. Additionally the current location is reset to the marked state.- Overrides:
resetin classFilterReader- Throws:
IOException
-