Skip navigation links

Oracle® Fusion Middleware Java API Reference for Oracle Coherence
12c (12.1.3.0.0)

E47890-01


com.tangosol.io
Class MultiBufferReadBuffer

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.io.AbstractReadBuffer
          extended by com.tangosol.io.MultiBufferReadBuffer

All Implemented Interfaces:
ReadBuffer, ByteSequence, java.lang.Cloneable

public class MultiBufferReadBuffer
extends AbstractReadBuffer

The MultiBufferReadBuffer is a ReadBuffer implementation that presents a view across any number of underlying ReadBuffer objects, as if they were appended end-to-end into a single ReadBuffer.

Author:
cp 2006.04.15

Nested Class Summary
 class MultiBufferReadBuffer.MultiBufferInput
          An implementation of the BufferInput interface that is backed by a series of the underlying ReadBuffer BufferInput objects.

 

Nested classes/interfaces inherited from class com.tangosol.io.AbstractReadBuffer
AbstractReadBuffer.AbstractBufferInput

 

Nested classes/interfaces inherited from interface com.tangosol.io.ReadBuffer
ReadBuffer.BufferInput

 

Field Summary

 

Fields inherited from class com.tangosol.io.AbstractReadBuffer
NO_BINARY, NO_BYTES

 

Constructor Summary
MultiBufferReadBuffer(ReadBuffer[] abuf)
          Construct a MultiBufferReadBuffer from an array of underlying ReadBuffer objects.

 

Method Summary
 byte byteAt(int of)
          Returns the byte at the specified offset.
 void copyBytes(int ofBegin, int ofEnd, byte[] abDest, int ofDest)
          Copies bytes from this ReadBuffer into the destination byte array.
 boolean equals(java.lang.Object o)
          Compare two ReadBuffer objects for equality.
protected  ReadBuffer getBuffer(int iBuffer)
          Obtain the specified buffer.
protected  int getBufferCount()
          Determine the number of ReadBuffer objects that contain the data presented by this MultiBufferReadBuffer.
protected  int getBufferIndexByOffset(int of)
          Determine which underlying ReadBuffer contains the specified offset.
protected  int getBufferOffset(int iBuffer)
          Determine the offset of the specified buffer.
 ReadBuffer.BufferInput getDestructiveBufferInput()
          Return a self-destructing BufferInput over this Buffer.
protected  ReadBuffer.BufferInput instantiateBufferInput()
          Factory method: Instantiate a BufferInput object to read data from the ReadBuffer.
protected  ReadBuffer.BufferInput instantiateBufferInput(boolean fDestructive)
          Factory method: Instantiate a BufferInput object to read data from the ReadBuffer.
protected  ReadBuffer instantiateReadBuffer(int of, int cb)
          Factory method: Instantiate a ReadBuffer for a portion of this ReadBuffer.
 int length()
          Determine the length of the buffer.
protected  ReadBuffer releaseBuffer(int iBuffer)
          Release the specified buffer.
 Binary toBinary(int of, int cb)
          Return a Binary object that holds the specified portion of this ReadBuffer.
 byte[] toByteArray(int of, int cb)
          Get a portion of the contents of the ReadBuffer as a byte array.
 java.nio.ByteBuffer toByteBuffer()
          Return a read-only ByteBuffer view of this ReadBuffer.
 java.nio.ByteBuffer toByteBuffer(int of, int cb)
          Return a read-only ByteBuffer view of the specified portion of this ReadBuffer.
 void writeTo(java.nio.ByteBuffer buf)
          Write the contents of the Binary object to a ByteBuffer.
 void writeTo(java.nio.ByteBuffer buf, int of, int cb)
          Write the contents of the Binary object to a ByteBuffer.
 void writeTo(java.io.DataOutput out)
          Write the contents of this ReadBuffer to a DataOutput.
 void writeTo(java.io.DataOutput out, int of, int cb)
          Write the contents of this ReadBuffer to a DataOutput.
 void writeTo(java.io.OutputStream out)
          Write the contents of this ReadBuffer to an OutputStream.
 void writeTo(java.io.OutputStream out, int of, int cb)
          Write the contents of the ReadBuffer to an OutputStream.

 

Methods inherited from class com.tangosol.io.AbstractReadBuffer
checkBounds, clone, getBufferInput, getReadBuffer, readPackedInt, readUnsignedByte, sizeofPackedInt, subSequence, toBinary, toByteArray

 

Constructor Detail

MultiBufferReadBuffer

public MultiBufferReadBuffer(ReadBuffer[] abuf)
Construct a MultiBufferReadBuffer from an array of underlying ReadBuffer objects.
Parameters:
abuf - an array of ReadBuffer objects from which to construct this MultiBufferReadBuffer

Method Detail

getDestructiveBufferInput

public ReadBuffer.BufferInput getDestructiveBufferInput()
Return a self-destructing BufferInput over this Buffer. As the BufferInput is advanced the individual buffer segments will be released allowing them to potentially be garbage collected.
Returns:
a destructed BufferInput

writeTo

public void writeTo(java.io.OutputStream out)
             throws java.io.IOException
Write the contents of this ReadBuffer to an OutputStream.
Parameters:
out - an OutputStream to write to
Throws:
java.io.IOException - if an I/O exception occurs

writeTo

public void writeTo(java.io.OutputStream out,
                    int of,
                    int cb)
             throws java.io.IOException
Write the contents of the ReadBuffer to an OutputStream.
Parameters:
out - an OutputStream to write to
of - the beginning index, inclusive
cb - the number of bytes to write to an OutputStream
Throws:
java.io.IOException - if an I/O exception occurs

writeTo

public void writeTo(java.io.DataOutput out)
             throws java.io.IOException
Write the contents of this ReadBuffer to a DataOutput.
Parameters:
out - a DataOutput to write to
Throws:
java.io.IOException - if an I/O exception occurs

writeTo

public void writeTo(java.io.DataOutput out,
                    int of,
                    int cb)
             throws java.io.IOException
Write the contents of this ReadBuffer to a DataOutput.
Parameters:
out - a DataOutput to write to
of - the beginning index, inclusive
cb - the number of bytes to write to a DataOutput
Throws:
java.io.IOException - if an I/O exception occurs

writeTo

public void writeTo(java.nio.ByteBuffer buf)
Write the contents of the Binary object to a ByteBuffer.
Parameters:
buf - a ByteBuffer to write to

writeTo

public void writeTo(java.nio.ByteBuffer buf,
                    int of,
                    int cb)
             throws java.io.IOException
Write the contents of the Binary object to a ByteBuffer.
Parameters:
buf - an ByteBuffer to write to
of - the beginning index, inclusive
cb - the number of bytes to write to a ByteBuffer
Throws:
java.io.IOException - if an I/O exception occurs

length

public int length()
Determine the length of the buffer.
Returns:
the number of bytes of data represented by this ReadBuffer

byteAt

public byte byteAt(int of)
Returns the byte at the specified offset. An offset ranges from 0 to length() - 1. The first byte of the sequence is at offset 0, the next at offset 1, and so on, as for array indexing.
Parameters:
of - the offset (index) of the byte
Returns:
the byte at the specified offset in this ReadBuffer

copyBytes

public void copyBytes(int ofBegin,
                      int ofEnd,
                      byte[] abDest,
                      int ofDest)
Copies bytes from this ReadBuffer into the destination byte array.

The first byte to be copied is at offset ofBegin; the last byte to be copied is at offset ofEnd-1 (thus the total number of bytes to be copied is ofEnd - ofBegin). The bytes are copied into the sub-array of abDest starting at offset ofDest and ending at index:

     ofDest + (ofEnd - ofBegin) - 1
 

This method is the ReadBuffer equivalent of String.getChars(int, int, char[], int). It allows the caller to extract a chunk of bytes into the caller's own array.

Parameters:
ofBegin - offset of the first byte in the ReadBuffer to copy
ofEnd - offset after the last byte in the ReadBuffer to copy
abDest - the destination byte array
ofDest - the offset in the destination byte array to copy the first byte to

toByteArray

public byte[] toByteArray(int of,
                          int cb)
Get a portion of the contents of the ReadBuffer as a byte array.

This method is an equivalent of getReadBuffer(of, cb).toByteArray().

Specified by:
toByteArray in interface ReadBuffer
Overrides:
toByteArray in class AbstractReadBuffer
Parameters:
of - the beginning index, inclusive
cb - the number of bytes to include in the resulting byte[]
Returns:
a byte[] containing the specified portion of this ReadBuffer

toBinary

public Binary toBinary(int of,
                       int cb)
Return a Binary object that holds the specified portion of this ReadBuffer.

This method is an equivalent of getReadBuffer(of, cb).toBinary().

Specified by:
toBinary in interface ReadBuffer
Overrides:
toBinary in class AbstractReadBuffer
Parameters:
of - the beginning index, inclusive
cb - the number of bytes to include in the Binary object
Returns:
a Binary object containing the specified portion of this ReadBuffer

toByteBuffer

public java.nio.ByteBuffer toByteBuffer()
Return a read-only ByteBuffer view of this ReadBuffer. This view may or may not reflect any subsequent changes made to the underlying content.
Returns:
a read-only ByteBuffer view of this ReadBuffer

toByteBuffer

public java.nio.ByteBuffer toByteBuffer(int of,
                                        int cb)
Return a read-only ByteBuffer view of the specified portion of this ReadBuffer. This view may or may not reflect any subsequent changes made to the underlying content.

This method is an equivalent of getReadBuffer(of, cb).toByteBuffer().

Parameters:
of - the beginning index, inclusive
cb - the number of bytes to include in the ByteBuffer object
Returns:
a read-only ByteBuffer view of the specified portion of this ReadBuffer

equals

public boolean equals(java.lang.Object o)
Compare two ReadBuffer objects for equality.
Specified by:
equals in interface ReadBuffer
Overrides:
equals in class AbstractReadBuffer
Parameters:
o - a ReadBuffer object
Returns:
true iff the other ReadBuffer is identical to this

instantiateReadBuffer

protected ReadBuffer instantiateReadBuffer(int of,
                                           int cb)
Factory method: Instantiate a ReadBuffer for a portion of this ReadBuffer.
Specified by:
instantiateReadBuffer in class AbstractReadBuffer
Parameters:
of - the beginning index, inclusive
cb - the number of bytes to include in the resulting ReadBuffer
Returns:
a ReadBuffer that represents a portion of this ReadBuffer

instantiateBufferInput

protected ReadBuffer.BufferInput instantiateBufferInput()
Factory method: Instantiate a BufferInput object to read data from the ReadBuffer.
Specified by:
instantiateBufferInput in class AbstractReadBuffer
Returns:
a new BufferInput reading from this ReadBuffer

instantiateBufferInput

protected ReadBuffer.BufferInput instantiateBufferInput(boolean fDestructive)
Factory method: Instantiate a BufferInput object to read data from the ReadBuffer.
Parameters:
fDestructive - true iff the BufferInput should self-destruct as it is advanced
Returns:
a new BufferInput reading from this ReadBuffer

getBufferCount

protected int getBufferCount()
Determine the number of ReadBuffer objects that contain the data presented by this MultiBufferReadBuffer.
Returns:
the count of underlying ReadBuffer objects

getBufferOffset

protected int getBufferOffset(int iBuffer)
Determine the offset of the specified buffer. The offset of a buffer is the absolute offset of the first byte stored in the buffer.
Parameters:
iBuffer - an index 0 <= iBuffer < getBufferCount()
Returns:
the absolute offset of the first byte of the specified ReadBuffer

getBuffer

protected ReadBuffer getBuffer(int iBuffer)
Obtain the specified buffer.
Parameters:
iBuffer - an index 0 <= iBuffer < getBufferCount()
Returns:
the specified ReadBuffer

releaseBuffer

protected ReadBuffer releaseBuffer(int iBuffer)
Release the specified buffer. Once released any operation requiring access to overall buffer segment maintained by said buffer will result in an error. This method allows for "destructive streaming", see #getDestructiveBufferInput()
Parameters:
iBuffer - an index 0 <= iBuffer < getBufferCount()
Returns:
the released buffer

getBufferIndexByOffset

protected int getBufferIndexByOffset(int of)
Determine which underlying ReadBuffer contains the specified offset.
Parameters:
of - an offset into this MultiBufferReadBuffer
Returns:
the index of the ReadBuffer containing the specified offset

Skip navigation links

Oracle® Fusion Middleware Java API Reference for Oracle Coherence
12c (12.1.3.0.0)

E47890-01


Copyright © 2000, 2014, Oracle and/or its affiliates. All rights reserved.