net.groboclown.util.io.v1
Class ReadByteStream

java.lang.Object
  |
  +--net.groboclown.util.io.v1.ReadByteStream

public class ReadByteStream
extends Object

Reads a byte array from a stream until the stream is finished. You can specify a maximum size to read, and the block read size.

Version:
Alpha 0.9.0
Author:
Matt Albrecht

Field Summary
static int DEFAULT_BLOCK_READ_SIZE
          Default block read size.
private  int m_bufferSize
           
private  InputStream m_is
           
private  int m_maxSize
           
static int READ_TO_END_OF_STREAM
          Read in an unlimited number of bytes.
 
Constructor Summary
ReadByteStream(InputStream is)
          Default constructor
ReadByteStream(InputStream is, int maxReadSize, int blockReadSize)
           
 
Method Summary
 byte[] readByteStream()
          Read in the byte stream, using the current settings.
static byte[] readByteStream(InputStream is)
          Read in the byte stream.
static byte[] readByteStream(InputStream is, int maxReadSize, int blockReadSize)
          Read in the byte stream.
 void setInputStream(InputStream is)
          Sets the internal input stream.
 void setSizes(int maxReadSize, int blockReadSize)
          Sets the internal sizes.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

READ_TO_END_OF_STREAM

public static final int READ_TO_END_OF_STREAM
Read in an unlimited number of bytes. This can be very dangerous.

DEFAULT_BLOCK_READ_SIZE

public static final int DEFAULT_BLOCK_READ_SIZE
Default block read size.

m_is

private InputStream m_is

m_maxSize

private int m_maxSize

m_bufferSize

private int m_bufferSize
Constructor Detail

ReadByteStream

public ReadByteStream(InputStream is)
Default constructor

ReadByteStream

public ReadByteStream(InputStream is,
                      int maxReadSize,
                      int blockReadSize)
Method Detail

setInputStream

public void setInputStream(InputStream is)
Sets the internal input stream.

setSizes

public void setSizes(int maxReadSize,
                     int blockReadSize)
Sets the internal sizes.

readByteStream

public byte[] readByteStream()
                      throws IOException
Read in the byte stream, using the current settings.

readByteStream

public static byte[] readByteStream(InputStream is)
                             throws IOException
Read in the byte stream. Does not close the stream after it has finished reading. Uses the default sizes.
See Also:
readByteStream( InputStream, int, int )

readByteStream

public static byte[] readByteStream(InputStream is,
                                    int maxReadSize,
                                    int blockReadSize)
                             throws IOException
Read in the byte stream. Does not close the stream after it has finished reading.

Note that there is no variable checking, for performance reasons. The user needs to verify that:

Parameters:
is - the input stream, which cannot be null.
maxReadSize - the maximum number of bytes to read, which must be positive, and must be modulo 0 of blockReadSize. This is an "estimation", and may actually read in more than this many bytes if it is not modulo 0 of blockReadSize, but will always return all the bytes read.
blockReadSize - the number of bytes to read in per read command, which cannot be more than maxReadSize, and cannot be less than or equal to zero.


Written under the LGPL