edu.emory.mathcs.util.io
Interface TimedInput

All Superinterfaces:
Input
All Known Subinterfaces:
TimedRedirectibleInput

public interface TimedInput
extends Input

Input source that supports read with timeouts. If timeout occurs before any data is available, TimeoutException is thrown.

Version:
1.0
Author:
Dawid Kurzyniec

Method Summary
 int timedRead(byte[] buf, int off, int len, long timeout)
          Reads up to len bytes of data from the input stream into an array of bytes.
 int timedRead(byte[] buf, long timeout)
          Reads some number of bytes of data from the input stream into an array of bytes.
 int timedRead(long timeout)
          Read a byte of data if available within specified timeout.
 
Methods inherited from interface edu.emory.mathcs.util.io.Input
available, close, mark, markSupported, read, read, read, reset, skip
 

Method Detail

timedRead

public int timedRead(long timeout)
              throws java.io.IOException,
                     TimeoutException
Read a byte of data if available within specified timeout.

Parameters:
timeout - the number of milliseconds to wait for data
Returns:
the byte of data read
Throws:
java.io.IOException - if an I/O error occurs
TimeoutException - if timeout occurs before data is available
See Also:
InputStream.read()

timedRead

public int timedRead(byte[] buf,
                     long timeout)
              throws java.io.IOException,
                     TimeoutException
Reads some number of bytes of data from the input stream into an array of bytes. An attempt is made to read as many as buf.length bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer. If buf has nonzero size but no data is available within the specified timeout and the stream is not at EOF, TimeoutException is thrown.

Parameters:
buf - the buffer into which the data is read
timeout - the maximum number of milliseconds to wait before data is available
Returns:
the actual number of bytes read
Throws:
java.io.IOException - if an I/O error occurs
TimeoutException - if timeout occurs before data is available
See Also:
InputStream.read(byte[])

timedRead

public int timedRead(byte[] buf,
                     int off,
                     int len,
                     long timeout)
              throws java.io.IOException,
                     TimeoutException
Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer. If nonzero bytes is requested but no data is available within the specified timeout and the stream is not at EOF, TimeoutException is thrown.

Parameters:
buf - the buffer into which the data is read
off - the start offset in array buf where data is written
len - the maximum number of bytes to read
timeout - the maximum number of milliseconds to wait before data is available
Returns:
the actual number of bytes read
Throws:
java.io.IOException - if an I/O error occurs
TimeoutException - if timeout occurs before data is available
See Also:
InputStream.read(byte[],int,int)