## org.openorb.io
Class StorageBuffer

    java.lang.Object
      |
      +--org.openorb.io.StorageBuffer

public class StorageBuffer
extends java.lang.Object

A storage buffer holds binary data for further processing. MarshalBuffers and BufferSource objects output a stream of StorageBuffers.

Author:
  Unknown

Constructor Summary
`StorageBuffer(byte[] buf, int off, int len)` Public constructor, Create storage buffer from bytes.
`StorageBuffer(byte[] buf, int off, int len, java.io.InputStream is, int total_len)` Public constructor, read part from buffer and remainder from stream.
`StorageBuffer(java.io.InputStream is, int total_len)` public constructor, read from stream.

Method Summary
`int` `available()` Available bytes
`boolean` `isReadWriteMode()` Check if the buffer is in read write mode.
`byte[]` `linearize()` Move the entire buffer into a single byte array.
`boolean` `mark()` Mark current buffer position for future reset.
`int` `next(OctetSeqHolder buf, IntHolder off, IntHolder len)` Read the next piece of the buffer.
`boolean` `reset()` reset buffer position to position marked with mark operation.
`void` `setReadWriteMode(boolean readWriteMode)` Set read write mode.
`int` `skip(IntHolder len)` Skip over bytes.
`void` `writeTo(java.io.OutputStream os)` Writes entire buffer to output stream.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### StorageBuffer

    public StorageBuffer(byte[] buf,
                         int off,
                         int len)

  Public constructor, Create storage buffer from bytes. The bytes are considered read-only.

### StorageBuffer

    public StorageBuffer(java.io.InputStream is,
                         int total_len)
                  throws java.io.IOException

  public constructor, read from stream.

### StorageBuffer

    public StorageBuffer(byte[] buf,
                         int off,
                         int len,
                         java.io.InputStream is,
                         int total_len)
                  throws java.io.IOException

  Public constructor, read part from buffer and remainder from stream. A whole buffer is always read. If the reading thread is interrupted the buffer will be completley read and the interrupted status reset.
  Parameters:
    `buf` - Prefix bytes. Copied.
    `off` - Offset into prefix buffer.
    `len` - Length of data in prefix buffer.
    `is` - Input stream for remainder of data.
    `total_len` - total length including data from prexix and stream.

Method Detail

### available

    public int available()

  Available bytes

### writeTo

    public void writeTo(java.io.OutputStream os)
                 throws java.io.IOException

  Writes entire buffer to output stream.

### next

    public int next(OctetSeqHolder buf,
                    IntHolder off,
                    IntHolder len)

  Read the next piece of the buffer. This buffer is modifyable if in m_read_write_mode.
  Parameters:
    `buf` - Out parameter, holds pointer to scratch space on return.
    `off` - Out parameter, holds buffer offset on return.
    `len` - InOut parameter, Length of requested buffer. Holds unallocated length on return. (ie: original - return)
  Returns:
    Length of returned buf. If end of buffer has been reached -1 is returned.

### skip

    public int skip(IntHolder len)

  Skip over bytes.
  Parameters:
    `len` - InOut parameter, Length of requested skip. Holds unskipped length on return. (ie: original - return)
  Returns:
    Length of returned buf. If end of buffer has been reached -1 is returned.

### linearize

    public byte[] linearize()

  Move the entire buffer into a single byte array. Calls to this function should generaly be avoided, call mark and next to iterate over the buffer instead.
  Returns:
    the linearized buffer or null when an exception during System.arraycopy() occured.

### isReadWriteMode

    public boolean isReadWriteMode()

  Check if the buffer is in read write mode. In read write mode buffers returned from the next operation can be safely modified, modifying the contents of the buffer.

### setReadWriteMode

    public void setReadWriteMode(boolean readWriteMode)

  Set read write mode. In read write mode buffers returned from the next operation can be safely modified, modifying the contents of the buffer.

### mark

    public boolean mark()

  Mark current buffer position for future reset.

### reset

    public boolean reset()

  reset buffer position to position marked with mark operation.