org.inria.ns.reflex.util.io
Class InputStreamAggregator

java.lang.Object
  extended by java.io.InputStream
      extended by org.inria.ns.reflex.util.io.InputStreamAggregator
All Implemented Interfaces:
Closeable

public class InputStreamAggregator
extends InputStream

InputStreamAggregator aggregates several InputStreams into a single one.

Author:
Philippe Poulard
See Also:
InputStream

Constructor Summary
InputStreamAggregator(InputStream input1, InputStream input2)
          Convenient constructor that creates a new InputStream aggregator with 2 sources.
InputStreamAggregator(InputStream input1, InputStream input2, InputStream input3)
          Convenient constructor that creates a new InputStream aggregator with 3 sources.
InputStreamAggregator(Iterator inputStreams)
          Create a new InputStream aggregator.
InputStreamAggregator(List input)
          Create a new InputStream aggregator.
 
Method Summary
 int available()
          Returns the number of bytes that can be read from this input stream without blocking.
 void close()
          Close the stream and any underlying streams.
 void mark(int readlimit)
          Mark not supported.
 boolean markSupported()
          Mark not supported.
 int read()
          Read a single byte.
 int read(byte[] bytes)
          Read bytes into an array.
 int read(byte[] bytes, int off, int len)
          Read bytes into a portion of an array.
 void reset()
          Reset not supported.
 long skip(long n)
          Skip bytes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InputStreamAggregator

public InputStreamAggregator(List input)
Create a new InputStream aggregator.

Parameters:
input - A non-null list (possibly empty) of InputStreams.
See Also:
InputStream

InputStreamAggregator

public InputStreamAggregator(Iterator inputStreams)
Create a new InputStream aggregator.

Parameters:
inputStreams - A non-null iterator (possibly empty) on InputStreams.
See Also:
InputStream

InputStreamAggregator

public InputStreamAggregator(InputStream input1,
                             InputStream input2)
Convenient constructor that creates a new InputStream aggregator with 2 sources.

Parameters:
input1 - The first InputStream to read.
input2 - The second InputStream to read.

InputStreamAggregator

public InputStreamAggregator(InputStream input1,
                             InputStream input2,
                             InputStream input3)
Convenient constructor that creates a new InputStream aggregator with 3 sources.

Parameters:
input1 - The first InputStream to read.
input2 - The second InputStream to read.
input3 - The third InputStream to read.
Method Detail

read

public int read()
         throws IOException
Read a single byte. This method will block until a byte is available, an I/O error occurs, or the end of all underlying streams are reached.

Specified by:
read in class InputStream
Returns:
The byte read, as an integer in the range 0 to 255, or -1 if the end of the stream has been reached.
Throws:
IOException - If an I/O error occurs

read

public int read(byte[] bytes)
         throws IOException
Read bytes into an array. This method will block until some input is available, an I/O error occurs, or the end of all underlying streams are reached.

Overrides:
read in class InputStream
Parameters:
bytes - The destination buffer.
Returns:
The number of bytes read, or -1 if the end of the stream has been reached.
Throws:
IOException - If an I/O error occurs
NullPointerException - If cbuf is null.

read

public int read(byte[] bytes,
                int off,
                int len)
         throws IOException
Read bytes into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of all underlying streams are reached.

Overrides:
read in class InputStream
Parameters:
bytes - The destination buffer.
off - The offset at which to start storing bytes.
len - The maximum number of bytes to read.
Returns:
The number of bytes read, or -1 if the end of the stream has been reached.
Throws:
IOException - If an I/O error occurs
NullPointerException - If "bytes" is null.
IndexOutOfBoundsException - If len or offset are out of the boundaries of the buffer.

skip

public long skip(long n)
          throws IOException
Skip bytes. This method will block until some bytes are available, an I/O error occurs, or the end of the stream is reached.

Overrides:
skip in class InputStream
Parameters:
n - The number of bytes to skip.
Returns:
The number of bytes actually skipped.
Throws:
IllegalArgumentException - If n is negative.
IOException - If an I/O error occurs

available

public int available()
              throws IOException
Returns the number of bytes that can be read from this input stream without blocking.

The available method of InputStreamAggregator returns the sum of the the number of bytes remaining to be read in the current buffer (count - pos) and the result of calling the available method of the underlying input stream.

Overrides:
available in class InputStream
Returns:
The number of bytes that can be read from this input stream without blocking.
Throws:
IOException - if an I/O error occurs.
See Also:
FilterInputStream

close

public void close()
           throws IOException
Close the stream and any underlying streams. Once a stream has been closed, further read(), ready(), mark(), or reset() invocations will throw an IOException. Closing a previously-closed stream, however, has no effect.

Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException - If an I/O error occurs

mark

public void mark(int readlimit)
Mark not supported.

Overrides:
mark in class InputStream
Parameters:
readlimit - Not used.

reset

public void reset()
           throws IOException
Reset not supported.

Overrides:
reset in class InputStream
Throws:
IOException - Always thrown.

markSupported

public boolean markSupported()
Mark not supported.

Overrides:
markSupported in class InputStream
Returns:
false.