olg.csv.base.csv
Class 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.

Author:
Olivier Godineau

Field Summary
static int BUF_SIZE
          Reader Buffer size default size.
 
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.
 int getSize()
          Returns the current size of the stream.
 boolean isEof()
          Indicates if end of file is reached.
 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

BUF_SIZE

public static final int BUF_SIZE
Reader Buffer size default size.

See Also:
Constant Field Values
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


Copyright © 2014. All rights reserved.