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

java.lang.Object
  extended by java.io.Reader
      extended by org.inria.ns.reflex.util.io.ReaderAggregator
All Implemented Interfaces:
Closeable, Readable

public class ReaderAggregator
extends Reader

ReaderAggregator aggregates several Readers into a single one.

Author:
Philippe Poulard
See Also:
Reader

Constructor Summary
ReaderAggregator(Iterator readers)
          Create a new reader aggregator.
ReaderAggregator(List readers)
          Create a new reader aggregator.
ReaderAggregator(Reader reader1, Reader reader2)
          Convenient constructor that creates a new reader aggregator with 2 sources.
ReaderAggregator(Reader reader1, Reader reader2, Reader reader3)
          Convenient constructor that creates a new reader aggregator with 3 sources.
 
Method Summary
 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 character.
 int read(char[] cbuf)
          Read characters into an array.
 int read(char[] cbuf, int off, int len)
          Read characters into a portion of an array.
 boolean ready()
          Tell whether this stream is ready to be read.
 void reset()
          Reset not supported.
 long skip(long n)
          Skip characters.
 
Methods inherited from class java.io.Reader
read
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReaderAggregator

public ReaderAggregator(List readers)
Create a new reader aggregator.

Parameters:
readers - A non-null list (possibly empty) of readers.
See Also:
Reader

ReaderAggregator

public ReaderAggregator(Iterator readers)
Create a new reader aggregator.

Parameters:
readers - A non-null iterator (possibly empty) on readers.
See Also:
Reader

ReaderAggregator

public ReaderAggregator(Reader reader1,
                        Reader reader2)
Convenient constructor that creates a new reader aggregator with 2 sources.

Parameters:
reader1 - The first reader to read.
reader2 - The second reader to read.

ReaderAggregator

public ReaderAggregator(Reader reader1,
                        Reader reader2,
                        Reader reader3)
Convenient constructor that creates a new reader aggregator with 3 sources.

Parameters:
reader1 - The first reader to read.
reader2 - The second reader to read.
reader3 - The third reader to read.
Method Detail

read

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

Overrides:
read in class Reader
Returns:
The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached.
Throws:
IOException - If an I/O error occurs

read

public int read(char[] cbuf)
         throws IOException
Read characters 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 Reader
Parameters:
cbuf - The destination buffer.
Returns:
The number of characters 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(char[] cbuf,
                int off,
                int len)
         throws IOException
Read characters 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.

Specified by:
read in class Reader
Parameters:
cbuf - The destination buffer.
off - The offset at which to start storing characters.
len - The maximum number of characters to read.
Returns:
The number of characters 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.
IndexOutOfBoundsException - If len or offset are out of the boundaries of the buffer.

skip

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

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

ready

public boolean ready()
              throws IOException
Tell whether this stream is ready to be read.

Overrides:
ready in class Reader
Returns:
true if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.
Throws:
IOException - If an I/O error occurs.

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
Specified by:
close in class Reader
Throws:
IOException - If an I/O error occurs

mark

public void mark(int readlimit)
          throws IOException
Mark not supported.

Overrides:
mark in class Reader
Parameters:
readlimit - Not used.
Throws:
IOException - Always thrown.

reset

public void reset()
           throws IOException
Reset not supported.

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

markSupported

public boolean markSupported()
Mark not supported.

Overrides:
markSupported in class Reader
Returns:
false.