Package org.eclipse.jgit.util.io
Class UnionInputStream
java.lang.Object
java.io.InputStream
org.eclipse.jgit.util.io.UnionInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
An InputStream which reads from one or more InputStreams.
This stream may enter into an EOF state, returning -1 from any of the read methods, and then later successfully read additional bytes if a new InputStream is added after reaching EOF.
Currently this stream does not support the mark/reset APIs. If mark and later
reset functionality is needed the caller should wrap this stream with a
BufferedInputStream
.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final InputStream
private final LinkedList<InputStream>
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty InputStream that is currently at EOF state.UnionInputStream
(InputStream... inputStreams) Create an InputStream that is a union of the individual streams. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(InputStream in) Add the given InputStream onto the end of the stream queue.int
void
close()
private InputStream
head()
boolean
isEmpty()
Returns true if there are no more InputStreams in the stream queue.private void
pop()
int
read()
int
read
(byte[] b, int off, int len) long
skip
(long count) Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skipNBytes, transferTo
-
Field Details
-
EOF
-
streams
-
-
Constructor Details
-
UnionInputStream
public UnionInputStream()Create an empty InputStream that is currently at EOF state. -
UnionInputStream
Create an InputStream that is a union of the individual streams.As each stream reaches EOF, it will be automatically closed before bytes from the next stream are read.
- Parameters:
inputStreams
- streams to be pushed onto this stream.
-
-
Method Details
-
head
-
pop
- Throws:
IOException
-
add
Add the given InputStream onto the end of the stream queue.When the stream reaches EOF it will be automatically closed.
- Parameters:
in
- the stream to add; must not be null.
-
isEmpty
public boolean isEmpty()Returns true if there are no more InputStreams in the stream queue.If this method returns
true
then all read methods will signal EOF by returning -1, until another InputStream has been pushed into the queue withadd(InputStream)
.- Returns:
- true if there are no more streams to read from.
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
available
- Overrides:
available
in classInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-