Overview | Package | Class | Tree | Deprecated | Index | Help
| Sun Adapter for Batch/FTP
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.stc.eways.batchext
Class InputStreamFindAdapter

    java.lang.Object
      com.stc.eways.batchext.InputStreamFindAdapter

    public class InputStreamFindAdapter

extends java.lang.Object

This class is a shim to the java.io.InputStream interface. Constructor takes the InputStream and then this class provides similar methods as the InputStream plus a few more to make dealing with the stream in the record parser a bit easier. Where practical, the method names from the InputStream interface are used and, if so, the semantics are the same as the InputStream interface. Important: To provide for the ability to "peek", the InputStream that is passed to the constructor must support skipping backwards. The java.io.FileInputStream does. The ByteArrayInputStream does not. To use a ByteArrayInputStream, see the BatchByteArrayInputStream.

Version:
  $Revision: 1.4 $
Author:
  jim.fu@sun.com
See Also:
  `BatchRecordParser`, `BatchByteArrayInputStream`, `InputStream`

Field Summary
`protected boolean` | `m_bDelimOnLast`
`protected java.io.InputStream` | `m_is` The input stream passed to the constructor

Constructor Summary
`InputStreamFindAdapter(java.io.InputStream is)` Constructor - pass the InputStream we are to wrap.

Method Summary
`int` | `available()` Get the total number of bytes that can be read.
`InputStreamFindResult` | `find(byte b)` This function peeks ahead and searches for 'b' starting at the current position in the stream.
`InputStreamFindResult` | `find(byte[] arr)` This function peeks ahead and searches for 'arr' starting at the current position in the stream.
`boolean` | `getDelimOnLastRecord()` Gets the property which determines how the find method will interpret the delimiter for the last record.
`int` | `read(byte[] buffer, int count)` Read 'count' bytes into 'buffer' starting at current position in the InputStream.
`int` | `read(byte[] buffer, int off, int count)` Semantically equiv to the same read method in the InputStream.
`void` | `setDelimOnLastRecord(boolean bDelimOnLast)` Sets the property which determines how the find method will interpret the delimiter for the last record.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### m_is

    protected java.io.InputStream m_is

  The input stream passed to the constructor

### m_bDelimOnLast

    protected boolean m_bDelimOnLast

Constructor Detail

### InputStreamFindAdapter

    public InputStreamFindAdapter(java.io.InputStream is)
                           throws java.lang.Exception

  Constructor - pass the InputStream we are to wrap. Must not be null.

  Throws:
    `java.lang.Exception`

Method Detail

### available

    public int available()
                  throws java.lang.Exception

  Get the total number of bytes that can be read. Routes to the similarly named method in the InputStream. As you read more and more of the stream, this method will return a lower and lower value.

  Throws:
    `java.lang.Exception` - If there is a problem determining this or if underlying InputStream throws an exception.

### read

    public int read(byte[] buffer,
                    int count)
             throws java.lang.Exception

  Read 'count' bytes into 'buffer' starting at current position in the InputStream.

  Parameters:
    `buffer` - The caller allocated buffer to fill with bytes
    `count` - The number of bytes to put in buffer
  Returns:
    The number of bytes placed in buffer.
  Throws:
    `java.lang.Exception` - If there is a problem getting the bytes. It is an error if there are not 'count' bytes to get from current position (i.e. try to get more than what is available).

### read

    public int read(byte[] buffer,
                    int off,
                    int count)
             throws java.lang.Exception

  Semantically equiv to the same read method in the InputStream.

  Throws:
    `java.lang.Exception`

### find

    public InputStreamFindResult find(byte b)
                               throws java.lang.Exception

  This function peeks ahead and searches for 'b' starting at the current position in the stream. If found, returns the zero based index as an offset from the current position, otherwise -1.

  Parameters:
    `b` - The byte to look for.
  Throws:
    `java.lang.Exception` - If there's a problem navigating the stream.

### setDelimOnLastRecord

    public void setDelimOnLastRecord(boolean bDelimOnLast)

  Sets the property which determines how the find method will interpret the delimiter for the last record. If set to true, then the last record must end with a delimiter. If set to false, the last record does not have to end with a delimiter. The default value for this property is true (the last record must end with the delimiter).

  Parameters:
    `bDelimOnLast` - Set to true if delimiter is required for the last record; otherwise, set to false.
  See Also:
    `getDelimOnLastRecord()`, `find(byte)`

### getDelimOnLastRecord

    public boolean getDelimOnLastRecord()

  Gets the property which determines how the find method will interpret the delimiter for the last record.

  See Also:
    `setDelimOnLastRecord(boolean)`, `find(byte)`

### find

    public InputStreamFindResult find(byte[] arr)
                               throws java.lang.Exception

  This function peeks ahead and searches for 'arr' starting at the current position in the stream. If found, returns the zero based index as an offset from the current position, otherwise -1.

  Parameters:
    `arr` - The byte array to look for.
  Throws:
    `java.lang.Exception` - If there's a problem navigating the stream.

Overview | Package | Class | Tree | Deprecated | Index | Help
| Sun Adapter for Batch/FTP
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD