com.ibm.etill.kitcashcassette.io
Class TimeOutInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--java.io.FilterInputStream
              |
              +--java.io.BufferedInputStream
                    |
                    +--com.ibm.etill.kitcashcassette.io.TimeOutInputStream

public final class TimeOutInputStream
extends java.io.BufferedInputStream

This class defines a BufferedInputStream with improved read methods implementing buffered inputs, string recognitions and timeouts.
This class uses a BufferedInputStream to minimize the number of calls to the underlying InputStream.
This class has a read method that returns when a certain string has been detected into a stream. For instance this can be used to detect the end of a Mime Header in an InputStream.
TMP TMP TMP Timeouts are not included in this iteration. In order to set timeouts properly we need the socket class defined in JAVA 1.1.1. We keep this class even though we can not define timeouts, yet. In the future they will be set from here. (may be) (This class needs an interface (callback function) to set timeouts in the SSocket class if we decide to set timeouts from this class)


Field Summary
protected  java.io.InputStream is
           
 
Fields inherited from class java.io.BufferedInputStream
buf, count, marklimit, markpos, pos
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
TimeOutInputStream(java.io.InputStream is, int size)
          Creates a new buffered TimeOut input stream to read data from the specified input stream using a buffer with a specified buffer size.
 
Method Summary
 void readFully(byte[] message)
          Read bytes from a BufferedInputStream connected to an InputStream.
 byte[] readUntilStop(java.lang.String stop, int nstop, int readlimit)
          Read bytes from a BufferedInputStream and returns when the string "stop" has been encountered "nstop" times.
If the "stop" string is not found before "readlimit" bytes are read, an IOException is thrown.
 
Methods inherited from class java.io.BufferedInputStream
available, close, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.io.FilterInputStream
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

is

protected java.io.InputStream is
Constructor Detail

TimeOutInputStream

public TimeOutInputStream(java.io.InputStream is,
                          int size)
Creates a new buffered TimeOut input stream to read data from the specified input stream using a buffer with a specified buffer size.
Parameters:
is - the input stream
size - the buffer size
Method Detail

readFully

public final void readFully(byte[] message)
                     throws java.io.IOException
Read bytes from a BufferedInputStream connected to an InputStream. This method is optimized to read as many bytes as possible from the BufferedInputStream and the underlying InputStream in as a few calls as possible.
This method blocks until either message.length bytes are read, the end of the stream is detected, or an exception is thrown.
Parameters:
message - The byte array read.

readUntilStop

public final byte[] readUntilStop(java.lang.String stop,
                                  int nstop,
                                  int readlimit)
                           throws java.io.IOException
Read bytes from a BufferedInputStream and returns when the string "stop" has been encountered "nstop" times.
If the "stop" string is not found before "readlimit" bytes are read, an IOException is thrown. This method blocks until either the "stop" string is found, the end of the stream or "readlimit" is detected, or an exception is thrown.
Parameters:
stop - The string that forces this method to return if encountered.
nstop - The number of time "stop" has to be encountered before this method returns.
readlimit - The maximum number of bytes in which this method will be trying to find the "stop" string before thronwing an IOException.
Returns:
a byte array containing the message read ("stop" string included).