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:
Closeable,AutoCloseable,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 with getPosition().
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intThe last char returnedprivate intprivate longThe count of EOLs (CR/LF/CRLF) seen so farprivate longprivate longThe position, which is the number of characters read so farprivate long -
Constructor Summary
ConstructorsConstructorDescriptionExtendedBufferedReader(Reader reader) Constructs a new instance using the default buffer size. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the stream.(package private) intReturns the last character that was read as an integer (0 to 65535).(package private) longReturns the current line number(package private) longGets the character position in the reader.voidmark(int readAheadLimit) intread()intread(char[] buf, int offset, int length) readLine()Gets the next line, dropping the line terminator(s).voidreset()Methods inherited from class org.apache.commons.io.input.UnsynchronizedBufferedReader
markSupported, peek, peek, ready, skipMethods inherited from class org.apache.commons.io.input.UnsynchronizedReader
isClosed, setClosed
-
Field Details
-
lastChar
private int lastCharThe last char returned -
lastCharMark
private int lastCharMark -
lineNumber
private long lineNumberThe count of EOLs (CR/LF/CRLF) seen so far -
lineNumberMark
private long lineNumberMark -
position
private long positionThe position, which is the number of characters read so far -
positionMark
private long positionMark
-
-
Constructor Details
-
ExtendedBufferedReader
ExtendedBufferedReader(Reader reader) Constructs a new instance using the default buffer size.
-
-
Method Details
-
close
Closes the stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classorg.apache.commons.io.input.UnsynchronizedBufferedReader- Throws:
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
- Overrides:
markin classorg.apache.commons.io.input.UnsynchronizedBufferedReader- Throws:
IOException
-
read
- Overrides:
readin classorg.apache.commons.io.input.UnsynchronizedBufferedReader- Throws:
IOException
-
read
- Overrides:
readin classorg.apache.commons.io.input.UnsynchronizedBufferedReader- Throws:
IOException
-
readLine
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
lineNumberand updatesposition.Sets
lastChartoConstants.EOFat EOF, otherwise the last EOL character.- Overrides:
readLinein classorg.apache.commons.io.input.UnsynchronizedBufferedReader- Returns:
- the line that was read, or null if reached EOF.
- Throws:
IOException
-
reset
- Overrides:
resetin classorg.apache.commons.io.input.UnsynchronizedBufferedReader- Throws:
IOException
-