org.activemq.io.util
Class WireByteArrayInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.ByteArrayInputStream
          extended by org.activemq.io.util.WireByteArrayInputStream
All Implemented Interfaces:
Closeable

public class WireByteArrayInputStream
extends ByteArrayInputStream

Optimized ByteArrayInputStream that can be used more than once. Which is nice.

Version:
$Revision: 1.1.1.1 $

Field Summary
 
Fields inherited from class java.io.ByteArrayInputStream
buf, count, mark, pos
 
Constructor Summary
WireByteArrayInputStream()
          Creates WireByteArrayInputStream with a minmalist byte array
WireByteArrayInputStream(byte[] buf)
          Creates a WireByteArrayInputStream.
WireByteArrayInputStream(byte[] buf, int offset, int length)
          Creates WireByteArrayInputStream that uses buf as its buffer array.
WireByteArrayInputStream(ByteArray ba)
          Create a WireByteArrayInputStream that uses a ByteArray
 
Method Summary
 int available()
           
 byte[] getRawData()
           
 int position()
           
 int read()
          Reads the next byte of data from this input stream.
 int read(byte[] b, int off, int len)
          Reads up to len bytes of data into an array of bytes from this input stream.
 void restart(byte[] newBuff)
          reset the WireByteArrayInputStream to use an new byte array
 void restart(byte[] newBuff, int offset, int length)
          reset the WireByteArrayInputStream to use an new byte array
 
Methods inherited from class java.io.ByteArrayInputStream
close, mark, markSupported, reset, skip
 
Methods inherited from class java.io.InputStream
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WireByteArrayInputStream

public WireByteArrayInputStream(byte[] buf)
Creates a WireByteArrayInputStream.

Parameters:
buf - the input buffer.

WireByteArrayInputStream

public WireByteArrayInputStream(byte[] buf,
                                int offset,
                                int length)
Creates WireByteArrayInputStream that uses buf as its buffer array.

Parameters:
buf - the input buffer.
offset - the offset in the buffer of the first byte to read.
length - the maximum number of bytes to read from the buffer.

WireByteArrayInputStream

public WireByteArrayInputStream(ByteArray ba)
Create a WireByteArrayInputStream that uses a ByteArray

Parameters:
ba -

WireByteArrayInputStream

public WireByteArrayInputStream()
Creates WireByteArrayInputStream with a minmalist byte array

Method Detail

position

public int position()
Returns:
the current position in the stream

getRawData

public byte[] getRawData()
Returns:
the underlying data array

restart

public void restart(byte[] newBuff,
                    int offset,
                    int length)
reset the WireByteArrayInputStream to use an new byte array

Parameters:
newBuff - buffer to use
offset - the offset in the buffer of the first byte to read.
length - the maximum number of bytes to read from the buffer.

restart

public void restart(byte[] newBuff)
reset the WireByteArrayInputStream to use an new byte array

Parameters:
newBuff -

read

public int read()
Reads the next byte of data from this input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned.

This read method cannot block.

Overrides:
read in class ByteArrayInputStream
Returns:
the next byte of data, or -1 if the end of the stream has been reached.

read

public int read(byte[] b,
                int off,
                int len)
Reads up to len bytes of data into an array of bytes from this input stream.

Overrides:
read in class ByteArrayInputStream
Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the maximum number of bytes read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

available

public int available()
Overrides:
available in class ByteArrayInputStream
Returns:
the number of bytes that can be read from the input stream without blocking.


Copyright © 2004-2009 Protique, Ltd.. All Rights Reserved.