|
com.Ostermiller.util Java Utilities |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
com.Ostermiller.util.ConcatInputStream
public class ConcatInputStream
An input stream which reads sequentially from multiple sources. More information about this class is available from ostermiller.org.
Constructor Summary | |
---|---|
ConcatInputStream()
Create a new input stream that can dynamically accept new sources. |
|
ConcatInputStream(InputStream in)
Create a new InputStream with one source. |
|
ConcatInputStream(InputStream[] in)
Create a new InputStream with an arbitrary number of sources. |
|
ConcatInputStream(InputStream in1,
InputStream in2)
Create a new InputStream with two sources. |
Method Summary | |
---|---|
void |
addInputStream(InputStream in)
Add the given inputStream to the queue of inputStreams from which to concatenate data. |
void |
addInputStreams(InputStream[] in)
Add the given inputStream to the queue of inputStreams from which to concatenate data. |
int |
available()
Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. |
void |
close()
Closes this input stream and releases any system resources associated with the stream. |
void |
lastInputStreamAdded()
Causes the addInputStream method to throw IllegalStateException and read() methods to return -1 (end of stream) when there is no more available data. |
void |
mark(int readlimit)
Mark not supported |
boolean |
markSupported()
Does not support mark. |
int |
read()
Reads the next byte of data from the underlying streams. |
int |
read(byte[] b)
Reads some number of bytes from the underlying streams and stores them into the buffer array b. |
int |
read(byte[] b,
int off,
int len)
Reads up to length bytes of data from the underlying streams into an array of bytes. |
void |
reset()
Reset not supported. |
long |
skip(long n)
Skips over and discards n bytes of data from this input stream. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ConcatInputStream()
New sources should be added using the addInputStream() method. When all sources have been added the lastInputStreamAdded() should be called so that read methods can return -1 (end of stream).
Adding new sources may by interleaved with read calls.
public ConcatInputStream(InputStream in)
in
- InputStream to use as a source.
NullPointerException
- if in is nullpublic ConcatInputStream(InputStream in1, InputStream in2)
in1
- first InputStream to use as a source.in2
- second InputStream to use as a source.
NullPointerException
- if either source is null.public ConcatInputStream(InputStream[] in)
in
- InputStreams to use as a sources.
NullPointerException
- if the input array on any element is null.Method Detail |
---|
public void lastInputStreamAdded()
Calling this method when this class is no longer accepting more inputStreams has no effect.
public void addInputStream(InputStream in)
in
- InputStream to add to the concatenation.
IllegalStateException
- if more inputStreams can't be added because lastInputStreamAdded() has been called, close() has been called, or a constructor with inputStream parameters was used.public void addInputStreams(InputStream[] in)
in
- InputStream to add to the concatenation.
IllegalStateException
- if more inputStreams can't be added because lastInputStreamAdded() has been called, close() has been called, or a constructor with inputStream parameters was used.
NullPointerException
- the array of inputStreams, or any of the contents is null.public int read() throws IOException
If this class in not done accepting input streams and the end of the last known stream is reached, this method will block forever unless another thread adds an input stream or interrupts.
read
in class InputStream
IOException
- if an I/O error occurs.public int read(byte[] b) throws IOException
If the length of b is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte.
The read(b) method for class InputStream has the same effect as:
read(b, 0, b.length)
If this class in not done accepting input streams and the end of the last known stream is reached, this method will block forever unless another thread adds an input stream or interrupts.
read
in class InputStream
b
- - Destination buffer
IOException
- - If an I/O error occurs
NullPointerException
- - If b is null.public int read(byte[] b, int off, int len) throws IOException
If length is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte.
This method blocks until input data is available
If this class in not done accepting input streams and the end of the last known stream is reached, this method will block forever unless another thread adds an input stream or interrupts.
read
in class InputStream
b
- Destination bufferoff
- Offset at which to start storing byteslen
- Maximum number of bytes to read
IOException
- - If an I/O error occurs
NullPointerException
- - If b is null.
IndexOutOfBoundsException
- - if length or offset are not possible.public long skip(long n) throws IOException
If this class in not done accepting input streams and the end of the last known stream is reached, this method will block forever unless another thread adds an input stream or interrupts.
skip
in class InputStream
n
- he number of characters to skip
IOException
- If an I/O error occurspublic int available() throws IOException
available
in class InputStream
IOException
- If an I/O error occurspublic void close() throws IOException
close
in interface Closeable
close
in class InputStream
IOException
public void mark(int readlimit)
mark
in class InputStream
public void reset() throws IOException
reset
in class InputStream
IOException
- because reset is not supported.public boolean markSupported()
markSupported
in class InputStream
|
com.Ostermiller.util Java Utilities |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2001-2012 by Stephen Ostermiller