com.kirkwarez.kirkpack.io
Class Streamer

java.lang.Object
  extended bycom.kirkwarez.kirkpack.io.Streamer

public class Streamer
extends Object

The Streamer is avery simple class that reads from one stream, and writes to another, the size of the buffer at a time, until the providing stream runs out of data, or the optionally specified length parameter has been reached.

Due to an annoying coincidence, the stream method that streams for a length using the default buffersize does not exist. You can circumvent this by using the stream method that does length and supplying the DEFAULT_BUFFER_SIZE as buffersize. Sorry :^P

Since:
3.00
Version:
3.00
Author:
Berend "Kirk" Wouda

Field Summary
static int DEFAULT_BUFFER_SIZE
          The default buffer size.
protected  InputStream input
          The stream to read from.
protected  OutputStream output
          The stream to write to.
 
Constructor Summary
Streamer(InputStream input, OutputStream output)
          Constructs new Streamer that will read from the given input and write it to the given output.
 
Method Summary
 InputStream getInputStream()
          Returns the input stream.
 OutputStream getOutputStream()
          Returns the output stream.
protected  byte[] read(int buffersize)
          Fully reads in the buffer from the input stream, unless the end of the stream is reached.
protected  void setInputStream(InputStream input)
          Sets the input stream.
protected  void setOutputStream(OutputStream output)
          Sets the output stream.
 void stream()
          Streams one stream to another using the default buffer size.
 void stream(int buffersize)
          Streams one stream to another using the given buffer size.
 void stream(int buffersize, int length)
          Streams one stream to another using the given buffer size for the given amount of bytes.
protected  void write(byte[] buffer)
          Fully writes out the given buffer to the output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

input

protected InputStream input
The stream to read from.


output

protected OutputStream output
The stream to write to.


DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
The default buffer size.

See Also:
Constant Field Values
Constructor Detail

Streamer

public Streamer(InputStream input,
                OutputStream output)
Constructs new Streamer that will read from the given input and write it to the given output.

Parameters:
input - The stream to read from. May not be null.
output - The stream to write to. May not be null.
Method Detail

stream

public void stream(int buffersize,
                   int length)
            throws IOException
Streams one stream to another using the given buffer size for the given amount of bytes.

Parameters:
buffersize - The size of the buffer to use.
length - The amount of bytes to stream over.
Throws:
IOException - When the streams mess up, or when there is not enough data.

stream

public void stream(int buffersize)
            throws IOException
Streams one stream to another using the given buffer size. Goes on until the input stream has drained.

Parameters:
buffersize - The size of the buffer to use.
Throws:
IOException - When the streams mess up.

stream

public void stream()
            throws IOException
Streams one stream to another using the default buffer size. Goes on until the input stream has drained.

Throws:
IOException - When the streams mess up.

read

protected byte[] read(int buffersize)
               throws IOException
Fully reads in the buffer from the input stream, unless the end of the stream is reached. In that case, a smaller buffer with the remains is returned.

Parameters:
buffersize - the amount to read in.
Returns:
The buffer with the data.
Throws:
IOException - When there is trouble reading.

write

protected void write(byte[] buffer)
              throws IOException
Fully writes out the given buffer to the output stream.

Parameters:
buffer - The buffer to write to the output stream.
Throws:
IOException - When there is trouble writing.

getInputStream

public InputStream getInputStream()
Returns the input stream.

Returns:
The stream which will be read from.

setInputStream

protected void setInputStream(InputStream input)
Sets the input stream.

Parameters:
input - The stream which will be read from.

getOutputStream

public OutputStream getOutputStream()
Returns the output stream.

Returns:
The stream which will be wriiten to.

setOutputStream

protected void setOutputStream(OutputStream output)
Sets the output stream.

Parameters:
output - The stream which will be written to.