Package net.sf.basedb.util
Class InputStreamSplitter
java.lang.Object
java.io.InputStream
net.sf.basedb.util.InputStreamSplitter
- All Implemented Interfaces:
Closeable
,AutoCloseable
This class can be used to split an input stream into one or more
additional output streams. When data is read from this input stream
the bytes are also written to the specified output streams with one of the
OutputStream.write(int)
or
OutputStream.write(byte[], int, int)
methods.- Version:
- 2.0
- Author:
- nicklas
- Last modified
- $Date: 2010-08-13 10:50:27 +0200 (fr, 13 aug 2010) $
-
Field Summary
Modifier and TypeFieldDescriptionprivate final boolean
If theskip(long)
method should copy to the output streams or no.private final OutputStream[]
Streams to copy the data to.private final InputStream
The source input stream to read from.private int
private final boolean
If the remainder of the input stream should be copied if it is closed before the end. -
Constructor Summary
ConstructorDescriptionInputStreamSplitter
(InputStream in, boolean copySkipped, boolean readToEnd, OutputStream... copyTo) Create a new input stream splitter.InputStreamSplitter
(InputStream in, OutputStream... copyTo) Create a new input stream splitter. -
Method Summary
Modifier and TypeMethodDescriptionint
void
close()
private void
copy
(byte[] b, int off, int len) Write data to all output streams.private void
copy
(int b) Write data to all output streams.long
Get the number of bytes that has been read or skipped from the input stream.void
mark
(int readlimit) boolean
int
read()
int
read
(byte[] b) int
read
(byte[] b, int off, int len) void
reset()
long
skip
(long n) Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
numRead
private int numRead -
in
The source input stream to read from. -
copyTo
Streams to copy the data to. -
copySkipped
private final boolean copySkippedIf theskip(long)
method should copy to the output streams or no. -
readToEnd
private final boolean readToEndIf the remainder of the input stream should be copied if it is closed before the end.
-
-
Constructor Details
-
InputStreamSplitter
Create a new input stream splitter. Skipped bytes are not copied and the remainder of the stream is not copied if closed.- Parameters:
in
- The input stream to read fromcopyTo
- The output streams to copy data to
-
InputStreamSplitter
public InputStreamSplitter(InputStream in, boolean copySkipped, boolean readToEnd, OutputStream... copyTo) Create a new input stream splitter. Skipped bytes are not copied and the remainder of the stream is not copied if closed.- Parameters:
in
- The input stream to read from. Null is not allowedcopySkipped
- TRUE if skipped bytes should be copied, FALSE otherwisereadToEnd
- If the remainder of the input stream should be copied if it is closed before the endcopyTo
- The output streams to copy data to. Null is not allowed- Since:
- 2.4
-
-
Method Details
-
available
- Overrides:
available
in classInputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
mark
public void mark(int readlimit) - Overrides:
mark
in classInputStream
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classInputStream
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
reset
- Overrides:
reset
in classInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
getNumRead
public long getNumRead()Get the number of bytes that has been read or skipped from the input stream.- Since:
- 2.4
-
copy
Write data to all output streams.- Throws:
IOException
-
copy
Write data to all output streams.- Throws:
IOException
-