org.mbari.siam.utils
Class StreamUtils

java.lang.Object
  extended by org.mbari.siam.utils.StreamUtils

public class StreamUtils
extends java.lang.Object


Constructor Summary
StreamUtils()
           
 
Method Summary
static int readBytes(java.io.InputStream instream, byte[] outbuf, int startIndex, int nBytes, long timeout)
          Read characters from input stream into buffer, until specified number of characters have been read, or operation times out.
static int readUntil(java.io.InputStream instream, byte[] outbuf, byte[] terminator, long timeout)
          Read characters from input stream into buffer, until specified terminator is encountered.
static int skipUntil(java.io.InputStream instream, byte[] terminator, long timeout)
          Skip streaming characters until specified terminator is encountered or until buffer if full (deprecated) Note that it is possible to ignore timeout by setting it to 0.
static int skipUntil(java.io.InputStream instream, byte[] terminator, long timeout, int maxBytes)
          Read characters from input stream into buffer, until specified terminator is encountered, maxBytes are received, or timeout milliseconds elapse.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamUtils

public StreamUtils()
Method Detail

readUntil

public static int readUntil(java.io.InputStream instream,
                            byte[] outbuf,
                            byte[] terminator,
                            long timeout)
                     throws TimeoutException,
                            java.lang.NullPointerException,
                            java.io.IOException,
                            java.lang.Exception
Read characters from input stream into buffer, until specified terminator is encountered.

Parameters:
instream - input stream
outbuf - output buffer
terminator - terminator character string
Throws:
TimeoutException
java.lang.NullPointerException
java.io.IOException
java.lang.Exception

skipUntil

public static int skipUntil(java.io.InputStream instream,
                            byte[] terminator,
                            long timeout,
                            int maxBytes)
                     throws TimeoutException,
                            java.lang.NullPointerException,
                            java.io.IOException,
                            java.lang.Exception
Read characters from input stream into buffer, until specified terminator is encountered, maxBytes are received, or timeout milliseconds elapse. Note that it is possible to ignore timeout and/or maxBytes by setting them to 0.

Parameters:
instream - input stream
terminator - terminator character string
timeout - stop after timeout ms
maxBytes - stop after maxBytes skipped
Throws:
TimeoutException
java.lang.NullPointerException
java.io.IOException
java.lang.Exception

skipUntil

public static int skipUntil(java.io.InputStream instream,
                            byte[] terminator,
                            long timeout)
                     throws TimeoutException,
                            java.io.IOException,
                            java.lang.NullPointerException,
                            java.lang.Exception
Skip streaming characters until specified terminator is encountered or until buffer if full (deprecated) Note that it is possible to ignore timeout by setting it to 0.

Parameters:
instream - input stream
terminator - termination character string
timeout - timeout in milliseconds
Throws:
TimeoutException
java.io.IOException
java.lang.NullPointerException
java.lang.Exception

readBytes

public static int readBytes(java.io.InputStream instream,
                            byte[] outbuf,
                            int startIndex,
                            int nBytes,
                            long timeout)
                     throws java.io.IOException,
                            java.lang.Exception
Read characters from input stream into buffer, until specified number of characters have been read, or operation times out.

Parameters:
instream - input stream
outbuf - output buffer
startIndex - start filling output buffer fromt this index
nBytes - number of bytes to read
timeout - in millisec
Throws:
java.io.IOException
java.lang.Exception


Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.