org.apache.commons.csv
Class ExtendedBufferedReader

java.lang.Object
  extended by java.io.Reader
      extended by java.io.BufferedReader
          extended by org.apache.commons.csv.ExtendedBufferedReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable

 class ExtendedBufferedReader
extends java.io.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
private  int lastChar
          the last char returned
private  CharBuffer line
           
private  int lineCounter
          the line counter
private  int lookaheadChar
          the lookahead chars
static int UNDEFINED
          undefined state for the lookahead char
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
ExtendedBufferedReader(java.io.Reader r)
          Created extended buffered reader using default buffer-size
ExtendedBufferedReader(java.io.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.
 java.lang.String readLine()
           
 java.lang.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
 
Methods inherited from class java.io.BufferedReader
close, mark, ready, reset
 
Methods inherited from class java.io.Reader
read, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

END_OF_STREAM

public static final int END_OF_STREAM
the end of stream symbol

See Also:
Constant Field Values

UNDEFINED

public static final int UNDEFINED
undefined state for the lookahead char

See Also:
Constant Field Values

lookaheadChar

private int lookaheadChar
the lookahead chars


lastChar

private int lastChar
the last char returned


lineCounter

private int lineCounter
the line counter


line

private CharBuffer line
Constructor Detail

ExtendedBufferedReader

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


ExtendedBufferedReader

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

Method Detail

read

public int read()
         throws java.io.IOException
Reads the next char from the input stream.

Overrides:
read in class java.io.BufferedReader
Returns:
the next char or END_OF_STREAM if end of stream has been reached.
Throws:
java.io.IOException

readAgain

public int readAgain()
Returns the last read character again.

Returns:
the last read char or UNDEFINED

read

public int read(char[] buf,
                int off,
                int len)
         throws java.io.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

Overrides:
read in class java.io.BufferedReader
Returns:
nof chars actually read or END_OF_STREAM
Throws:
java.io.IOException

readUntil

public java.lang.String readUntil(char c)
                           throws java.io.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
Throws:
java.io.IOException

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Overrides:
readLine in class java.io.BufferedReader
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
Throws:
java.io.IOException

skip

public long skip(long n)
          throws java.lang.IllegalArgumentException,
                 java.io.IOException
Skips char in the stream ATTENTION: invalidates the line-counter !!!!!

Overrides:
skip in class java.io.BufferedReader
Returns:
nof skiped chars
Throws:
java.lang.IllegalArgumentException
java.io.IOException

skipUntil

public long skipUntil(char c)
               throws java.lang.IllegalArgumentException,
                      java.io.IOException
Skips all chars in the input until (but excluding) the given char

Parameters:
c -
Returns:
Throws:
java.lang.IllegalArgumentException
java.io.IOException

lookAhead

public int lookAhead()
              throws java.io.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
Throws:
java.io.IOException

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)

markSupported

public boolean markSupported()
Overrides:
markSupported in class java.io.BufferedReader