biz.c24.io.api.presentation.stream
Class BorderedCharDataReader

java.lang.Object
  extended by biz.c24.io.api.presentation.stream.DataReader
      extended by biz.c24.io.api.presentation.stream.BorderedCharDataReader
All Implemented Interfaces:
Serializable

public class BorderedCharDataReader
extends DataReader
implements Serializable

Char data stream reader.

Provides the charachter stream processing. Additively it is provides the stackable borders on visible data (a.k.a. nested windows) that allows to read the limited by certain border data.

Version:
$Revision: 19293 $ $Date: 2012-06-07 10:32:48 -0400 (Thu, 07 Jun 2012) $
See Also:
Serialized Form

Nested Class Summary
 class BorderedCharDataReader.CharDataLocator
          The location in charachter stream representation class.
 
Nested classes/interfaces inherited from class biz.c24.io.api.presentation.stream.DataReader
DataReader.Locator
 
Field Summary
 
Fields inherited from class biz.c24.io.api.presentation.stream.DataReader
count, eof, locator, pos
 
Constructor Summary
BorderedCharDataReader()
          Default constructor.
 
Method Summary
 void acquireLimit(String[] sign)
          Force to re-locate the current border if it has the same sign as expected charachters.
 int available()
          Returns the number of available charachters (taking into consideration the existing borders).
 void close()
          Closes this reader and releases any system resources associated with it.
protected  void compact(int from, int requested)
          Compacts the data in the internal buffer.
protected  int fill(int requested)
          Fills out the internal buffer by next charachters from underlied reader.
 String get20Characters()
          Debug only method to get the upmost 20 charachters in raw data.
 String get20CharactersBeforeOffset(int offset)
           
 int getColumnNumber()
          Returns the column number of current location.
 InputStream getDataStream()
          Returns the underlied incoming data stream.
 int getLineNumber()
          Returns the line number of current location.
 String getNextToken(String delimiter)
          Get the next token delimited from the stream.
 int getOffset()
          Returns the current offset within charachter data.
 int indexOf(char delimiter, int from)
          Find out the position of next occurrence the delimiter from specified pos.
 int indexOf(String str)
          Find out the position of next occurence the str.
 int indexOf(String str, int from)
          Find out the position of next occurence the str from specified pos.
 void initialize(Reader in)
          Initialization by specified data stream.
 String lookUp(int length)
          Lookups the next length charachters in incoming data without updating the current location.
 String lookUpmost(int length)
          Deprecated.  
 String lookUpmostWithoutPad(String pad, int length)
          Deprecated.  
 String read(char delimiter)
          Only looking for a single character delimiter so no point in using an expensive String
 String read(int length)
          Reads the next length charachters in incoming data.
 boolean ready()
          Checks whether coming data on next read or not.
 void setLimit(String[] sign, boolean isOptional)
          Sets the additional border on character stream.
 int skipIf(String str, int length)
          Do skip the length charachters while they equals the specified str.
 boolean startsFrom(String str)
          Check wether the charachter stream equals to specified str.
 boolean startsFrom(String str, boolean caseSensitive)
          Check wether the charachter stream equals to specified str.
 void trimSpaces(String[] wrappers)
          Trims the white spaces between wrapped elements
 void unsetLimit()
          Removes the current border and forces to re-locate next one.
 
Methods inherited from class biz.c24.io.api.presentation.stream.DataReader
ensureOpen, eof, getLocator, getLookAhead, getLookBehind, mark, rollback, setLookAhead, setLookBehind, skip, updateLocator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BorderedCharDataReader

public BorderedCharDataReader()
Default constructor.

Method Detail

initialize

public final void initialize(Reader in)
                      throws IOException
Initialization by specified data stream.

Parameters:
in - The underlied charachter data reader.
Throws:
IOException - If I/O errors occured.

getOffset

public int getOffset()
Returns the current offset within charachter data.

Returns:
the charachter number in current internal buffer.

ready

public boolean ready()
              throws IOException
Checks whether coming data on next read or not.

Returns:
true if there are charachters, false - otherwise.
Throws:
IOException - If an I/O error occurs.

read

public String read(int length)
            throws IOException
Reads the next length charachters in incoming data.

Parameters:
length - The number of chars that need to read.
Returns:
the requested charachters as string or null - if number of available charachters less than expected or not at all.
Throws:
IOException - If an I/O error occurs.

read

public String read(char delimiter)
            throws IOException
Only looking for a single character delimiter so no point in using an expensive String

Parameters:
delimiter -
Returns:
value
Throws:
IOException

lookUp

public String lookUp(int length)
              throws IOException
Lookups the next length charachters in incoming data without updating the current location.

Parameters:
length - The number of chars that need to read.
Returns:
the requested charachters as string or null - if number of available charachters less than expected or not at all.
Throws:
IOException - If I/O errors occured.

trimSpaces

public void trimSpaces(String[] wrappers)
Trims the white spaces between wrapped elements

Parameters:
wrappers - The Wrappers used by the text to locate elements

lookUpmost

public String lookUpmost(int length)
                  throws IOException
Deprecated. 

Lookups the length next charachters in incoming data without updating the current location.

Parameters:
length - The number of chars that need to read.
Returns:
the requested charachters as string or empty string - if number of available charachters less than expected or not at all.
Throws:
IOException - If an I/O error occurs.

lookUpmostWithoutPad

public String lookUpmostWithoutPad(String pad,
                                   int length)
                            throws IOException
Deprecated. 

Lookups at least the length next charachters in incoming data without updating the current location. If they are prepend or tailed by specified pad, they are trimmed up to actual data.

Parameters:
pad - The padding charachters that may happend before and after the actual data.
length - The number of chars that need to read.
Returns:
the requested charachters as string or empty string - if number of available charachters less than expected or not at all.
Throws:
IOException - If an I/O error occurs.

skipIf

public int skipIf(String str,
                  int length)
           throws IOException
Do skip the length charachters while they equals the specified str.

Parameters:
str - The string against which the skipped charachters will be compared.
length - The number of charachters that needed be skipped.
Returns:
The actual number of skipped charachters.
Throws:
IOException - If an I/O error occurs.

get20Characters

public String get20Characters()
Debug only method to get the upmost 20 charachters in raw data.

Returns:
the string of upmost 20 charachters from current position.

get20CharactersBeforeOffset

public String get20CharactersBeforeOffset(int offset)

getNextToken

public String getNextToken(String delimiter)
                    throws IOException
Get the next token delimited from the stream. The old method only considered the next 20 characters where as this one is unbounded. KCP added

Throws:
IOException

indexOf

public int indexOf(String str)
            throws IOException
Find out the position of next occurence the str.

Parameters:
str - The string against which charachters need be compared.
Returns:
The position from which specified string is started.
Throws:
IOException - if I/O error occured.

indexOf

public int indexOf(String str,
                   int from)
            throws IOException
Find out the position of next occurence the str from specified pos.

Parameters:
str - The string against which charachters need be compared.
from - The position in charachters from which search should start.
Returns:
The position from which specified string is started.
Throws:
IOException - if I/O error occured.

indexOf

public int indexOf(char delimiter,
                   int from)
            throws IOException
Find out the position of next occurrence the delimiter from specified pos.

Parameters:
delimiter - The string against which characters need be compared.
from - The position in characters from which search should start.
Returns:
The position from which specified string is started.
Throws:
IOException - if I/O error occurred.

setLimit

public void setLimit(String[] sign,
                     boolean isOptional)
              throws IOException
Sets the additional border on character stream.

Provides the border on readed data. The borders will be discovered in incoming charachter stream and consequently restricted the data that will be available on next read/look up operations. Note, that adding new border will affect on all existing but not move out them, they will stay actual but will be re-located if needed.

Parameters:
sign - The set of signs that represents this border.
isOptional - whether this border required or not.
Throws:
IOException - if I/O error occured.

acquireLimit

public void acquireLimit(String[] sign)
                  throws IOException
Force to re-locate the current border if it has the same sign as expected charachters.

Parameters:
sign - The set of signs that is expected in charachtyer stream.
Throws:
IOException - If an I/O error occurs.

unsetLimit

public void unsetLimit()
                throws IOException
Removes the current border and forces to re-locate next one.

Throws:
IOException - If an I/O error occurs.

startsFrom

public boolean startsFrom(String str)
                   throws IOException
Check wether the charachter stream equals to specified str.

Parameters:
str - The charachter sequence against that the equality is checked.
Returns:
true if charachter stream is equals to specified strinf, false - otherwise.
Throws:
IOException - If an I/O error occurs.

startsFrom

public boolean startsFrom(String str,
                          boolean caseSensitive)
                   throws IOException
Check wether the charachter stream equals to specified str.

Parameters:
str - The charachter sequence against that the equality is checked.
caseSensitive - should be considered the case sensitivity or not.
Returns:
true if charachter stream is equals to specified strinf, false - otherwise.
Throws:
IOException - If an I/O error occurs.

available

public int available()
Returns the number of available charachters (taking into consideration the existing borders).

Overrides:
available in class DataReader
Returns:
The number of available charachters.
See Also:
FilterInputStream.in

close

public void close()
           throws IOException
Closes this reader and releases any system resources associated with it.

Specified by:
close in class DataReader
Throws:
IOException - if an I/O error occurs.

getDataStream

public final InputStream getDataStream()
Returns the underlied incoming data stream.

Overrides:
getDataStream in class DataReader
Returns:
The incoming data stream.
Throws:
UnsupportedOperationException - If implementation doesn't provided that ability.

fill

protected final int fill(int requested)
                  throws IOException
Fills out the internal buffer by next charachters from underlied reader.

Specified by:
fill in class DataReader
Parameters:
requested - the number of charachters that were requested.
Returns:
the number of charachters that were actually readed into internal buffer.
Throws:
IOException - If unexpected I/O error happends.

compact

protected final void compact(int from,
                             int requested)
                      throws IOException
Compacts the data in the internal buffer.

Specified by:
compact in class DataReader
Parameters:
from - The pointer in buffer up to which data may be marked as invalidated.
requested - the number of charachters that should stay in buffer in any way.
Throws:
IOException - If unexpected I/O error happends.

getLineNumber

public final int getLineNumber()
Returns the line number of current location.

Returns:
The line nuber of current location within charachters stream.

getColumnNumber

public final int getColumnNumber()
Returns the column number of current location.

Returns:
The column nuber of current location within charachters stream.


C24 Technologies © 2002-2012: All Rights Reserved.