2.17.2: 2011-06-17

net.sf.basedb.util
Class InputStreamSplitter

java.lang.Object
  extended by java.io.InputStream
      extended by net.sf.basedb.util.InputStreamSplitter
All Implemented Interfaces:
Closeable

public class InputStreamSplitter
extends InputStream

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 (Fri, 13 Aug 2010) $

Field Summary
private  boolean copySkipped
          If the skip(long) method should copy to the output streams or no.
private  OutputStream[] copyTo
          Streams to copy the data to.
private  InputStream in
          The source input stream to read from.
private  int numRead
           
private  boolean readToEnd
          If the remainder of the input stream should be copied if it is closed before the end.
 
Constructor Summary
InputStreamSplitter(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
 int available()
           
 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 getNumRead()
          Get the number of bytes that has been read or skipped from the input stream.
 void mark(int readlimit)
           
 boolean markSupported()
           
 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.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

numRead

private int numRead

in

private final InputStream in
The source input stream to read from.


copyTo

private final OutputStream[] copyTo
Streams to copy the data to.


copySkipped

private final boolean copySkipped
If the skip(long) method should copy to the output streams or no.


readToEnd

private final boolean readToEnd
If the remainder of the input stream should be copied if it is closed before the end.

Constructor Detail

InputStreamSplitter

public InputStreamSplitter(InputStream in,
                           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
copyTo - 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 allowed
copySkipped - TRUE if skipped bytes should be copied, FALSE otherwise
readToEnd - If the remainder of the input stream should be copied if it is closed before the end
copyTo - The output streams to copy data to. Null is not allowed
Since:
2.4
Method Detail

available

public int available()
              throws IOException
Overrides:
available in class InputStream
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException

mark

public void mark(int readlimit)
Overrides:
mark in class InputStream

markSupported

public boolean markSupported()
Overrides:
markSupported in class InputStream

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

reset

public void reset()
           throws IOException
Overrides:
reset in class InputStream
Throws:
IOException

skip

public long skip(long n)
          throws IOException
Overrides:
skip in class InputStream
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

private void copy(int b)
           throws IOException
Write data to all output streams.

Throws:
IOException

copy

private void copy(byte[] b,
                  int off,
                  int len)
           throws IOException
Write data to all output streams.

Throws:
IOException

2.17.2: 2011-06-17