CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation

com.tangosol.io
Class MultiByteArrayOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.tangosol.io.MultiByteArrayOutputStream
All Implemented Interfaces:
OutputStreaming, Closeable, Flushable

public class MultiByteArrayOutputStream
extends OutputStream
implements OutputStreaming

An OutputStream that accumulates the written data to a series of byte arrays that do not exceed a specified size.

Author:
cp 2001.11.13

Field Summary
protected  byte[] m_ab
          The current block of output.
protected  int m_cbBlock
          The max size of each block.
protected  int m_cbPadBack
          The number of additional bytes to allocate and leave free at the back (end) of each block
protected  int m_cbPadFront
          The number of additional bytes to allocate and leave free at the front (start) of each block
protected  boolean m_fClosed
          True after close is invoked.
protected  List m_listBlock
          The list of blocks.
protected  int m_of
          The offset into the current block of output.
 
Constructor Summary
MultiByteArrayOutputStream(int cbBlock)
          Construct a MultiByteArrayOutputStream to write to byte arrays of the specified length.
MultiByteArrayOutputStream(int cbBlock, int cbPadFront, int cbPadBack)
          Construct a MultiByteArrayOutputStream to write to byte arrays of the specified length, leaving the specified amount of padding at the front and back of each byte array.
 
Method Summary
protected  void check()
          Verify that the stream is still open.
 void close()
          Close the stream, flushing any accumulated bytes.
 void flush()
          Flush any accumulated bytes.
 int getBackPaddingSize()
          Determine the number of extra bytes of padding that will be allocated and left blank at the end of each block after the data portion.
 byte[] getBlock(int i)
          Obtain the specified block of data that was written.
 int getBlockCount()
          Determine the number of blocks that have been written thus far.
 int getBlockDataSize()
          Determine the maximum number of bytes of data that will be stored in each block.
 int getFrontPaddingSize()
          Determine the number of extra bytes of padding that will be allocated and left blank at the start of each block in front of the data portion.
protected  int requestCapacity(int cbMore)
          Ensure that the current block contains some available capacity, preferably enough to fulfill the specified capacity.
 String toString()
          Create a human readable string representing the data written to the stream.
 void write(byte[] abSrc, int ofSrc, int cbSrc)
          Writes len bytes from the specified byte array starting at offset off to this output stream.
 void write(int b)
          Writes the specified byte to this output stream.
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from interface com.tangosol.io.OutputStreaming
write
 

Field Detail

m_ab

protected byte[] m_ab
The current block of output.


m_of

protected int m_of
The offset into the current block of output.


m_cbBlock

protected int m_cbBlock
The max size of each block.


m_cbPadFront

protected int m_cbPadFront
The number of additional bytes to allocate and leave free at the front (start) of each block


m_cbPadBack

protected int m_cbPadBack
The number of additional bytes to allocate and leave free at the back (end) of each block


m_listBlock

protected List m_listBlock
The list of blocks.


m_fClosed

protected boolean m_fClosed
True after close is invoked.

Constructor Detail

MultiByteArrayOutputStream

public MultiByteArrayOutputStream(int cbBlock)
Construct a MultiByteArrayOutputStream to write to byte arrays of the specified length.

Parameters:
cbBlock - the number of bytes (maximum) per block

MultiByteArrayOutputStream

public MultiByteArrayOutputStream(int cbBlock,
                                  int cbPadFront,
                                  int cbPadBack)
Construct a MultiByteArrayOutputStream to write to byte arrays of the specified length, leaving the specified amount of padding at the front and back of each byte array.

Parameters:
cbBlock - the number of data bytes (maximum) per block
cbPadFront - the number of additional bytes to allocate and leave free at the front (start) of each block
cbPadBack - the number of additional bytes to allocate and leave free at the back (end) of each block
Method Detail

write

public void write(int b)
           throws IOException
Writes the specified byte to this output stream.

Specified by:
write in interface OutputStreaming
Specified by:
write in class OutputStream
Parameters:
b - the byte.
Throws:
IOException - if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.

write

public void write(byte[] abSrc,
                  int ofSrc,
                  int cbSrc)
           throws IOException
Writes len bytes from the specified byte array starting at offset off to this output stream.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Specified by:
write in interface OutputStreaming
Overrides:
write in class OutputStream
Parameters:
abSrc - the data
ofSrc - the start offset in the data
cbSrc - the number of bytes to write
Throws:
IOException - if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.

flush

public void flush()
           throws IOException
Flush any accumulated bytes.

Specified by:
flush in interface OutputStreaming
Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream
Throws:
IOException - if an I/O error occurs

close

public void close()
           throws IOException
Close the stream, flushing any accumulated bytes.

Specified by:
close in interface OutputStreaming
Specified by:
close in interface Closeable
Overrides:
close in class OutputStream
Throws:
IOException - if an I/O error occurs

toString

public String toString()
Create a human readable string representing the data written to the stream.

Returns:
a String representation of the stream's contents

getBlockCount

public int getBlockCount()
Determine the number of blocks that have been written thus far. This value is only guaranteed to be correct after calling flush.

Returns:
the number of blocks (byte arrays) of output that have any data

getBlock

public byte[] getBlock(int i)
Obtain the specified block of data that was written.

Parameters:
i - block index in the range 0..getBlocKCount()-1
Returns:
the specified block (byte array) of output that was written

getBlockDataSize

public int getBlockDataSize()
Determine the maximum number of bytes of data that will be stored in each block.

Returns:
the number of data bytes (maximum) per block

getFrontPaddingSize

public int getFrontPaddingSize()
Determine the number of extra bytes of padding that will be allocated and left blank at the start of each block in front of the data portion.

Returns:
the number of additional bytes to allocate and leave free at the front (start) of each block

getBackPaddingSize

public int getBackPaddingSize()
Determine the number of extra bytes of padding that will be allocated and left blank at the end of each block after the data portion.

Returns:
the number of additional bytes to allocate and leave free at the back (end) of each block

check

protected void check()
              throws IOException
Verify that the stream is still open.

Throws:
IOException

requestCapacity

protected int requestCapacity(int cbMore)
Ensure that the current block contains some available capacity, preferably enough to fulfill the specified capacity. As a result of calling this method m_ab and m_of may change. If this call returns then the current block is guarenteed to contain at least one free byte of available capacity.

Parameters:
cbMore - the requested capacity
Returns:
the size of the current block

CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation