Package org.apache.commons.csv
Class ExtendedBufferedReader
- java.lang.Object
-
- java.io.Reader
-
- org.apache.commons.io.input.UnsynchronizedReader
-
- org.apache.commons.io.input.UnsynchronizedBufferedReader
-
- org.apache.commons.csv.ExtendedBufferedReader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Readable
final class ExtendedBufferedReader extends org.apache.commons.io.input.UnsynchronizedBufferedReader
A special buffered reader which supports sophisticated read access.In particular the reader supports a look-ahead option, which allows you to see the next char returned by
read()
. This reader also tracks how many characters have been read withgetPosition()
.
-
-
Field Summary
Fields Modifier and Type Field Description private int
lastChar
The last char returnedprivate int
lastCharMark
private long
lineNumber
The count of EOLs (CR/LF/CRLF) seen so farprivate long
lineNumberMark
private long
position
The position, which is the number of characters read so farprivate long
positionMark
-
Constructor Summary
Constructors Constructor Description ExtendedBufferedReader(java.io.Reader reader)
Constructs a new instance using the default buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the stream.(package private) int
getLastChar()
Returns the last character that was read as an integer (0 to 65535).(package private) long
getLineNumber()
Returns the current line number(package private) long
getPosition()
Gets the character position in the reader.void
mark(int readAheadLimit)
int
read()
int
read(char[] buf, int offset, int length)
java.lang.String
readLine()
Gets the next line, dropping the line terminator(s).void
reset()
-
-
-
Field Detail
-
lastChar
private int lastChar
The last char returned
-
lastCharMark
private int lastCharMark
-
lineNumber
private long lineNumber
The count of EOLs (CR/LF/CRLF) seen so far
-
lineNumberMark
private long lineNumberMark
-
position
private long position
The position, which is the number of characters read so far
-
positionMark
private long positionMark
-
-
Method Detail
-
close
public void close() throws java.io.IOException
Closes the stream.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classorg.apache.commons.io.input.UnsynchronizedBufferedReader
- Throws:
java.io.IOException
- If an I/O error occurs
-
getLastChar
int getLastChar()
Returns the last character that was read as an integer (0 to 65535). This will be the last character returned by any of the read methods. This will not include a character read using theUnsynchronizedBufferedReader.peek()
method. If no character has been read then this will returnConstants.UNDEFINED
. If the end of the stream was reached on the last read then this will returnIOUtils.EOF
.- Returns:
- the last character that was read
-
getLineNumber
long getLineNumber()
Returns the current line number- Returns:
- the current line number
-
getPosition
long getPosition()
Gets the character position in the reader.- Returns:
- the current position in the reader (counting characters, not bytes since this is a Reader)
-
mark
public void mark(int readAheadLimit) throws java.io.IOException
- Overrides:
mark
in classorg.apache.commons.io.input.UnsynchronizedBufferedReader
- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException
- Overrides:
read
in classorg.apache.commons.io.input.UnsynchronizedBufferedReader
- Throws:
java.io.IOException
-
read
public int read(char[] buf, int offset, int length) throws java.io.IOException
- Overrides:
read
in classorg.apache.commons.io.input.UnsynchronizedBufferedReader
- Throws:
java.io.IOException
-
readLine
public java.lang.String readLine() throws java.io.IOException
Gets the next line, dropping the line terminator(s). This method should only be called when processing a comment, otherwise, information can be lost.Increments
lineNumber
and updatesposition
.Sets
lastChar
toConstants.EOF
at EOF, otherwise the last EOL character.- Overrides:
readLine
in classorg.apache.commons.io.input.UnsynchronizedBufferedReader
- Returns:
- the line that was read, or null if reached EOF.
- Throws:
java.io.IOException
-
reset
public void reset() throws java.io.IOException
- Overrides:
reset
in classorg.apache.commons.io.input.UnsynchronizedBufferedReader
- Throws:
java.io.IOException
-
-