olg.csv.base.csv
Class CharSearchReader

Package class diagram package CharSearchReader
java.lang.Object
  extended by olg.csv.base.csv.CharSearchReader
All Implemented Interfaces:
Closeable

public class CharSearchReader
extends Object
implements Closeable

This class provides methods based on the character search and hides the original stream reading.


Field Summary
static int BUF_SIZE
          Reader Buffer size default size.
private  char[] cbuf
          the char buffer.
private  int currentBufSize
          Current buffer size.
private  boolean eof
          Indicates if end of file is reached.
private static org.slf4j.Logger LOGGER
          the class logger.
private  int maxBufSize
          reader buffer size.
private  int offset
          buffer offset.
private  BufferedReader reader
          The input reader.
private  StringBuilder store
          Retains the characters previously read into the buffer.
 
Constructor Summary
  CharSearchReader(InputStream reader, String charset)
           
protected CharSearchReader(InputStream reader, String charset, int bufSize)
           
 
Method Summary
 char charAt(int index)
          Returns the char at an index.
 void close()
          
 boolean exists(int index)
          Indicates if a char exists at an index in this stream.
 int find(char... args)
          Finds the first index of the first character found.
 int findNextAtIndex(int begin, char... args)
          Finds the first index of the first character found starting at a specific index in the stream.
private  int findNextAtIndexFromBegin(int begin, char... args)
          Finds the first index of the first character found starting at a specific index in the stream.
private  int findNextInBufAtIndex(int begin, char... args)
          Finds the first index of the first character found starting at a specific index in the buf.
 int getSize()
          Returns the current size of the stream.
 boolean isEof()
          Indicates if end of file is reached.
private  void loadBuf()
          Loads the next sequence.
private  void loadNextSequence()
          Stores the current sequence and loads the next sequence.
 void skip(int nb)
          Skips characters in the stream.
 String substring(int begin, int end)
          Returns a new String that contains a subsequence of characters currently contained in the stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

private static final org.slf4j.Logger LOGGER
the class logger.


BUF_SIZE

public static final int BUF_SIZE
Reader Buffer size default size.

See Also:
Constant Field Values

currentBufSize

private int currentBufSize
Current buffer size.


reader

private BufferedReader reader
The input reader.


eof

private boolean eof
Indicates if end of file is reached.


offset

private int offset
buffer offset.


maxBufSize

private int maxBufSize
reader buffer size.


cbuf

private final char[] cbuf
the char buffer.


store

private final StringBuilder store
Retains the characters previously read into the buffer.

Constructor Detail

CharSearchReader

public CharSearchReader(InputStream reader,
                        String charset)
                 throws IOException
Parameters:
reader - the input stream.
charset - the charset name.
Throws:
IOException - If an I/O error occurs or If the named charset is not supported

CharSearchReader

protected CharSearchReader(InputStream reader,
                           String charset,
                           int bufSize)
                    throws IOException
Parameters:
reader - the input stream.
charset - the charset name.
bufSize - the max buf size.
Throws:
IOException - If an I/O error occurs or If the named charset is not supported
Method Detail

isEof

public boolean isEof()
Indicates if end of file is reached.

Returns:
eof;

charAt

public char charAt(int index)
            throws IOException
Returns the char at an index. Must be >=0.

Parameters:
index - the index.
Returns:
the char at this index.
Throws:
IOException - when the index is not reachable or If an I/O error occurs

exists

public boolean exists(int index)
Indicates if a char exists at an index in this stream.

Parameters:
index - the index
Returns:
true if a char exists at this index

find

public int find(char... args)
         throws IOException
Finds the first index of the first character found.

Parameters:
args - the chars to search.
Returns:
the index of the first occurrence of the first character found, or -1 if any character does not occur.
Throws:
IOException - the eof is reached without find chars or if an I/O error occurs.

findNextAtIndex

public int findNextAtIndex(int begin,
                           char... args)
                    throws IOException
Finds the first index of the first character found starting at a specific index in the stream.

Parameters:
begin - the index to start the search from.
args - the chars to search.
Returns:
the index of the first occurrence of the first character found greater than or equal to begin, or -1 if any character does not occur.
Throws:
IOException - when the begin index is not reachable or the eof is reached without find chars.

skip

public void skip(int nb)
Skips characters in the stream.

Parameters:
nb - The number of characters to skip

substring

public String substring(int begin,
                        int end)
Returns a new String that contains a subsequence of characters currently contained in the stream.

Parameters:
begin - The beginning index, inclusive.
end - The ending index, exclusive.
Returns:
the new String.

getSize

public int getSize()
Returns the current size of the stream.

Returns:
the current size.

close

public void close()

Specified by:
close in interface Closeable

findNextInBufAtIndex

private int findNextInBufAtIndex(int begin,
                                 char... args)
Finds the first index of the first character found starting at a specific index in the buf.

Parameters:
begin - the index to start the search from.
args - the chars to search.
Returns:
the index of the first occurrence of the first character found greater than or equal to begin, or -1 if any character does not occur.

findNextAtIndexFromBegin

private int findNextAtIndexFromBegin(int begin,
                                     char... args)
                              throws IOException
Finds the first index of the first character found starting at a specific index in the stream.

Parameters:
begin - the index to start the search from.
args - the chars to search.
Returns:
the index of the first occurrence of the first character found greater than or equal to begin, or -1 if any character does not occur.
Throws:
IOException - the eof is reached without find chars or if an I/O error occurs.

loadNextSequence

private void loadNextSequence()
                       throws IOException
Stores the current sequence and loads the next sequence.

Throws:
IOException - if end of line is reached on loading the next sequence or an I/O error occurs

loadBuf

private void loadBuf()
              throws IOException
Loads the next sequence.

Throws:
IOException - If an I/O error occurs


Copyright © 2014. All rights reserved.