Xj3D VRML/X3D Code API

org.web3d.util
Class SequenceReader

java.lang.Object
  extended byjava.io.Reader
      extended byorg.web3d.util.SequenceReader

public class SequenceReader
extends java.io.Reader

Represents the logical concatenation of other readers.

The standard java.io package does not provide this capability so this class does the same as SequenceInputStream except for Reader derived classes.

It starts out with an ordered collection of input streams and reads from the first one until end of file is reached,whereupon it reads from the second one, and so on, until end of file is reached on the last of the contained input streams.

Version:
$Revision: 1.4 $
Author:
Justin Couch

Field Summary
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
SequenceReader(java.util.List readers)
          Initializes a newly created SequenceReader with the list of be a List that produces objects whose run-time type is Reader.
SequenceReader(java.io.Reader s1, java.io.Reader s2)
          Initializes a newly created SequenceReader by remembering the two arguments, which will be read as s1 then s2 order to provide the bytes to be read from this SequenceReader.
 
Method Summary
 void close()
          Closes this input stream and releases any system resources associated with the stream.
 int read()
          Reads the next char of data from this input stream.
 int read(char[] b, int off, int len)
          Reads up to len bytes of data from this input stream into an array of bytes.
 
Methods inherited from class java.io.Reader
mark, markSupported, read, ready, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SequenceReader

public SequenceReader(java.util.List readers)
Initializes a newly created SequenceReader with the list of be a List that produces objects whose run-time type is Reader. The readers that are produced by the list will be read in order defined in the list to provide the bytes to be read from this SequenceReader. After each input stream from the list is exhausted, it is closed by calling its close() method.

Parameters:
readers - A list of input streams to process
See Also:
List

SequenceReader

public SequenceReader(java.io.Reader s1,
                      java.io.Reader s2)
Initializes a newly created SequenceReader by remembering the two arguments, which will be read as s1 then s2 order to provide the bytes to be read from this SequenceReader.

Parameters:
s1 - The first input stream to read.
s2 - The second input stream to read.
Method Detail

read

public int read()
         throws java.io.IOException
Reads the next char of data from this input stream. If no char is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

This method tries to read one character from the current substream. If it reaches the end of the stream, it calls the close method of the current substream and begins reading from the next substream.

Returns:
The next char of data, or -1 if the end of the stream is reached.
Throws:
java.io.IOException - if an I/O error occurs.

read

public int read(char[] b,
                int off,
                int len)
         throws java.io.IOException
Reads up to len bytes of data from this input stream into an array of bytes. This method blocks until at least 1 byte of input is available. If the first argument is null, up to len bytes are read and discarded.

The read method of SequenceReader tries to read the data from the current substream. If it fails to read any characters because the substream has reached the end of the stream, it calls the close method of the current substream and begins reading from the next substream.

Parameters:
b - The buffer into which the data is read.
off - The start offset of the data.
len - The maximum number of bytes read.
Returns:
The number of bytes read.
Throws:
java.io.IOException - if an I/O error occurs.

close

public void close()
           throws java.io.IOException
Closes this input stream and releases any system resources associated with the stream. A closed SequenceReader cannot perform input operations and cannot be reopened.

If this stream was created from an list, all remaining elements are requested from the list and closed before the close method returns. of Reader .

Throws:
java.io.IOException - if an I/O error occurs.

Xj3D VRML/X3D Code API

Copyright © 2001 - 2005 Web3D Consortium