Package com.tangosol.io
Class MultiByteArrayOutputStream
java.lang.Object
java.io.OutputStream
com.tangosol.io.MultiByteArrayOutputStream
- All Implemented Interfaces:
com.oracle.coherence.common.io.OutputStreaming,OutputStreaming,Closeable,Flushable,AutoCloseable
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
FieldsModifier and TypeFieldDescriptionprotected byte[]The current block of output.protected intThe max size of each block.protected intThe number of flushed blocks.protected intThe number of additional bytes to allocate and leave free at the back (end) of each blockprotected intThe number of additional bytes to allocate and leave free at the front (start) of each blockprotected booleanTrue after close is invoked.protected ListThe list of blocks.protected intThe offset into the current block of output. -
Constructor Summary
ConstructorsConstructorDescriptionMultiByteArrayOutputStream(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
Modifier and TypeMethodDescriptionprotected voidcheck()Verify that the stream is still open.voidclose()Close the stream, flushing any accumulated bytes.voidflush()Flush any accumulated bytes.intDetermine 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.intDetermine the number of blocks that have been written thus far.intDetermine the maximum number of bytes of data that will be stored in each block.intgetBlockDataSize(int i) Determine the specific number of bytes of data stored in the specified block.intDetermine 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 intrequestCapacity(int cbMore) Ensure that the current block contains some available capacity, preferably enough to fulfill the specified capacity.toString()Create a human readable string representing the data written to the stream.voidwrite(byte[] abSrc, int ofSrc, int cbSrc) Writeslenbytes from the specified byte array starting at offsetoffto this output stream.voidwrite(int b) Writes the specified byte to this output stream.Methods inherited from class java.io.OutputStream
nullOutputStream, writeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.oracle.coherence.common.io.OutputStreaming
write
-
Field Details
-
m_ab
protected byte[] m_abThe current block of output. -
m_of
protected int m_ofThe offset into the current block of output. -
m_cbBlock
protected int m_cbBlockThe max size of each block. -
m_cbPadFront
protected int m_cbPadFrontThe number of additional bytes to allocate and leave free at the front (start) of each block -
m_cbPadBack
protected int m_cbPadBackThe number of additional bytes to allocate and leave free at the back (end) of each block -
m_listBlock
The list of blocks. -
m_cBlocks
protected int m_cBlocksThe number of flushed blocks. -
m_fClosed
protected boolean m_fClosedTrue after close is invoked.
-
-
Constructor Details
-
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 blockcbPadFront- the number of additional bytes to allocate and leave free at the front (start) of each blockcbPadBack- the number of additional bytes to allocate and leave free at the back (end) of each block
-
-
Method Details
-
write
Writes the specified byte to this output stream.- Specified by:
writein interfacecom.oracle.coherence.common.io.OutputStreaming- Specified by:
writein classOutputStream- Parameters:
b- thebyte.- Throws:
IOException- if an I/O error occurs. In particular, anIOExceptionmay be thrown if the output stream has been closed.
-
write
Writeslenbytes from the specified byte array starting at offsetoffto this output stream.If
bisnull, aNullPointerExceptionis thrown.If
offis negative, orlenis negative, oroff+lenis greater than the length of the arrayb, then an IndexOutOfBoundsException is thrown.- Specified by:
writein interfacecom.oracle.coherence.common.io.OutputStreaming- Overrides:
writein classOutputStream- Parameters:
abSrc- the dataofSrc- the start offset in the datacbSrc- the number of bytes to write- Throws:
IOException- if an I/O error occurs. In particular, anIOExceptionis thrown if the output stream is closed.
-
flush
Flush any accumulated bytes.- Specified by:
flushin interfaceFlushable- Specified by:
flushin interfacecom.oracle.coherence.common.io.OutputStreaming- Overrides:
flushin classOutputStream- Throws:
IOException- if an I/O error occurs
-
close
Close the stream, flushing any accumulated bytes.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfacecom.oracle.coherence.common.io.OutputStreaming- Overrides:
closein classOutputStream- Throws:
IOException- if an I/O error occurs
-
toString
Create a human readable string representing the data written to the stream. -
getBlockCount
public int getBlockCount()Determine the number of blocks that have been written thus far.- 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.- Parameters:
i- block index in the range [0..getBlockCount()]; passing the getBlockCount() will return the active block- Returns:
- the specified block (byte array) of output
-
getBlockDataSize
public int getBlockDataSize(int i) Determine the specific number of bytes of data stored in the specified block.- Parameters:
i- block index in the range [0..getBlockCount()]; passing the getBlockCount() will return the size of the active block- Returns:
- the number of data bytes in a block
-
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
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
-