com.ibm.etill.framework.io
Class TimeOutInputStream
java.lang.Object
|
+--java.io.InputStream
|
+--java.io.FilterInputStream
|
+--java.io.BufferedInputStream
|
+--com.ibm.etill.framework.io.TimeOutInputStream
- public final class TimeOutInputStream
- extends 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)
Constructor Summary |
TimeOutInputStream(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(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. |
TimeOutInputStream
public TimeOutInputStream(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 streamsize
- the buffer size
readUntilStop
public final byte[] readUntilStop(String stop,
int nstop,
int readlimit)
throws 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).
readFully
public final void readFully(byte[] message)
throws 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.