Build 1.0_r1(from source)

java.io
Class SequenceInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.SequenceInputStream
All Implemented Interfaces:
Closeable

public class SequenceInputStream
extends InputStream

SequenceInputStream is used for streaming over a sequence of streams concatenated together. Reads are taken from the first stream until it ends, then the next stream is used until the last stream returns end of file.


Constructor Summary
SequenceInputStream(Enumeration<? extends InputStream> e)
          Constructs a new SequenceInputStream using the elements returned from Enumeration e as the stream sequence.
SequenceInputStream(InputStream s1, InputStream s2)
          Constructs a new SequenceInputStream using the two streams s1 and s2 as the sequence of streams to read from.
 
Method Summary
 int available()
          Returns a int representing then number of bytes that are available before this InputStream will block.
 void close()
          Close the SequenceInputStream.
 int read()
          Reads a single byte from this SequenceInputStream and returns the result as an int.
 int read(byte[] buffer, int offset, int count)
          Reads at most count bytes from this SequenceInputStream and stores them in byte array buffer starting at offset.
 
Methods inherited from class java.io.InputStream
mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SequenceInputStream

public SequenceInputStream(InputStream s1,
                           InputStream s2)
Constructs a new SequenceInputStream using the two streams s1 and s2 as the sequence of streams to read from.

Parameters:
s1 - the first stream to get bytes from
s2 - the second stream to get bytes from

SequenceInputStream

public SequenceInputStream(Enumeration<? extends InputStream> e)
Constructs a new SequenceInputStream using the elements returned from Enumeration e as the stream sequence. The types returned from nextElement() must be of InputStream.

Parameters:
e - the Enumeration of InputStreams to get bytes from
Method Detail

available

public int available()
              throws IOException
Returns a int representing then number of bytes that are available before this InputStream will block.

Overrides:
available in class InputStream
Returns:
the number of bytes available before blocking.
Throws:
IOException - If an error occurs in this InputStream.

close

public void close()
           throws IOException
Close the SequenceInputStream. All streams in this sequence are closed before returning from this method. This stream cannot be used for input once it has been closed.

Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException - If an error occurs attempting to close this FileInputStream.

read

public int read()
         throws IOException
Reads a single byte from this SequenceInputStream and returns the result as an int. The low-order byte is returned or -1 of the end of stream was encountered. The current stream is read from. If it reaches the end of file, the next stream is read from.

Specified by:
read in class InputStream
Returns:
the byte read or -1 if end of stream.
Throws:
IOException - If an error occurs while reading the stream

read

public int read(byte[] buffer,
                int offset,
                int count)
         throws IOException
Reads at most count bytes from this SequenceInputStream and stores them in byte array buffer starting at offset. Answer the number of bytes actually read or -1 if no bytes were read and end of stream was encountered.

Overrides:
read in class InputStream
Parameters:
buffer - the byte array in which to store the read bytes.
offset - the offset in buffer to store the read bytes.
count - the maximum number of bytes to store in buffer.
Returns:
the number of bytes actually read or -1 if end of stream.
Throws:
IOException - If an error occurs while reading the stream

Build 1.0_r1(from source)

Please submit a feedback, bug or feature