Oracle® Coherence Java API Reference
v3.5

E14977-01

com.tangosol.io.nio
Class ByteBufferReadBuffer

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.io.AbstractReadBuffer
          extended by com.tangosol.io.nio.ByteBufferReadBuffer
All Implemented Interfaces:
ReadBuffer, java.lang.Cloneable

public class ByteBufferReadBuffer
extends AbstractReadBuffer
implements ReadBuffer

A ReadBuffer implementation on top of a Java NIO ByteBuffer.

Author:
cp 2006.04.05

Nested Class Summary
 class ByteBufferReadBuffer.ByteBufferInput
          This is a simple implementation of the BufferInput interface on top of a ByteBuffer.
 
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
ByteBufferReadBuffer(java.nio.ByteBuffer buf)
          Construct a ByteBufferReadBuffer on an NIO ByteBuffer.
 
Method Summary
 byte byteAt(int of)
          Returns the byte at the specified offset.
 java.lang.Object clone()
          Create a clone of this ReadBuffer object.
 void copyBytes(int ofBegin, int ofEnd, byte[] abDest, int ofDest)
          Copies bytes from this ReadBuffer into the destination byte array.
 java.nio.ByteBuffer getByteBuffer()
          Obtain the ByteBuffer that this ReadBuffer is based on.
protected  ReadBuffer.BufferInput instantiateBufferInput()
          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.
 Binary toBinary(int of, int cb)
          Returns a Binary object that holds the specified portion of this ReadBuffer.

This is the equivalent of getReadBuffer(of, cb).toBinary().

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

This is the equivalent of getReadBuffer(of, cb).toByteArray().

 
Methods inherited from class com.tangosol.io.AbstractReadBuffer
checkBounds, equals, getBufferInput, getReadBuffer, toBinary, toByteArray
 
Methods inherited from interface com.tangosol.io.ReadBuffer
getBufferInput, getReadBuffer, toBinary, toByteArray
 

Constructor Detail

ByteBufferReadBuffer

public ByteBufferReadBuffer(java.nio.ByteBuffer buf)
Construct a ByteBufferReadBuffer on an NIO ByteBuffer.

Parameters:
buf - the underlying NIO ByteBuffer
Method Detail

getByteBuffer

public java.nio.ByteBuffer getByteBuffer()
Obtain the ByteBuffer that this ReadBuffer is based on.

Returns:
the underlying ByteBuffer

length

public int length()
Determine the length of the buffer.

Specified by:
length in interface ReadBuffer
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.

Specified by:
byteAt in interface ReadBuffer
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 subarray 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.

Specified by:
copyBytes in interface ReadBuffer
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 is the 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)
Returns a Binary object that holds the specified portion of this ReadBuffer.

This is the 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

clone

public java.lang.Object clone()
Create a clone of this ReadBuffer object.

Specified by:
clone in interface ReadBuffer
Overrides:
clone in class AbstractReadBuffer
Returns:
a ReadBuffer object with the same contents as this ReadBuffer object

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

Oracle® Coherence Java API Reference
v3.5

E14977-01

Copyright © 2000, 2009, Oracle. All rights reserved.