org.apache.commons.csv

Class ExtendedBufferedReader


public class ExtendedBufferedReader
extends BufferedReader

ExtendedBufferedReader A special reader decorater which supports more sophisticated access to the underlying reader object. In particular the reader supports a look-ahead option, which allows you to see the next char returned by next(). Furthermore the skip-method supports skipping until (but excluding) a given char. Similar functionality is supported by the reader as well.

Field Summary

static int
END_OF_STREAM
the end of stream symbol
static int
UNDEFINED
undefined state for the lookahead char
private int
lastChar
the last char returned
private CharBuffer
line
private int
lineCounter
the line counter
private int
lookaheadChar
the lookahead chars

Constructor Summary

ExtendedBufferedReader(Reader r)
Created extended buffered reader using default buffer-size
ExtendedBufferedReader(Reader r, int bufSize)
Create extended buffered reader using the given buffer-size

Method Summary

int
getLineNumber()
Returns the nof line read ATTENTION: the skip-method does invalidate the line-number counter
int
lookAhead()
Returns the next char in the stream without consuming it.
boolean
markSupported()
int
read()
Reads the next char from the input stream.
int
read(char[] buf, int off, int len)
Non-blocking reading of len chars into buffer buf starting at bufferposition off.
int
readAgain()
Returns the last read character again.
String
readLine()
String
readUntil(char c)
Reads all characters up to (but not including) the given character.
long
skip(long n)
Skips char in the stream ATTENTION: invalidates the line-counter !!!!!
long
skipUntil(char c)
Skips all chars in the input until (but excluding) the given char

Field Details

END_OF_STREAM

public static final int END_OF_STREAM
the end of stream symbol
Field Value:
-1

UNDEFINED

public static final int UNDEFINED
undefined state for the lookahead char
Field Value:
-2

lastChar

private int lastChar
the last char returned

line

private CharBuffer line

lineCounter

private int lineCounter
the line counter

lookaheadChar

private int lookaheadChar
the lookahead chars

Constructor Details

ExtendedBufferedReader

public ExtendedBufferedReader(Reader r)
Created extended buffered reader using default buffer-size

ExtendedBufferedReader

public ExtendedBufferedReader(Reader r,
                              int bufSize)
Create extended buffered reader using the given buffer-size

Method Details

getLineNumber

public int getLineNumber()
Returns the nof line read ATTENTION: the skip-method does invalidate the line-number counter
Returns:
the current-line-number (or -1)

lookAhead

public int lookAhead()
            throws IOException
Returns the next char in the stream without consuming it. Remember the next char read by read(..) will always be identical to lookAhead().
Returns:
the next char (without consuming it) or END_OF_STREAM

markSupported

public boolean markSupported()

read

public int read()
            throws IOException
Reads the next char from the input stream.
Returns:
the next char or END_OF_STREAM if end of stream has been reached.

read

public int read(char[] buf,
                int off,
                int len)
            throws IOException
Non-blocking reading of len chars into buffer buf starting at bufferposition off. performs an iteratative read on the underlying stream as long as the following conditions hold: - less than len chars have been read - end of stream has not been reached - next read is not blocking
Returns:
nof chars actually read or END_OF_STREAM

readAgain

public int readAgain()
Returns the last read character again.
Returns:
the last read char or UNDEFINED

readLine

public String readLine()
            throws IOException
Returns:
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached

readUntil

public String readUntil(char c)
            throws IOException
Reads all characters up to (but not including) the given character.
Parameters:
c - the character to read up to
Returns:
the string up to the character c

skip

public long skip(long n)
            throws IllegalArgumentException,
                   IOException
Skips char in the stream ATTENTION: invalidates the line-counter !!!!!
Returns:
nof skiped chars

skipUntil

public long skipUntil(char c)
            throws IllegalArgumentException,
                   IOException
Skips all chars in the input until (but excluding) the given char
Parameters:
c -
Returns: