Skip navigation links

Oracle® Coherence Java API Reference
Release 12.1.2.0.3

E26043-02


com.tangosol.io
Class AbstractReadBuffer

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

All Implemented Interfaces:
ReadBuffer, ByteSequence, HashEncoded, java.lang.Cloneable
Direct Known Subclasses:
AbstractByteArrayReadBuffer, ByteBufferReadBuffer, MultiBufferReadBuffer

public abstract class AbstractReadBuffer
extends Base
implements ReadBuffer, HashEncoded

Abstract base implementation of the ReadBuffer interface.

Author:
cp 2006.04.17

Nested Class Summary
 class AbstractReadBuffer.AbstractBufferInput
          This is an implementation of the BufferInput interface that delegates its work back to its ReadBuffer.

 

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

 

Field Summary
static Binary NO_BINARY
          An empty Binary object.
static byte[] NO_BYTES
          An empty byte array (by definition immutable).

 

Fields inherited from interface com.tangosol.util.HashEncoded
UNENCODED

 

Constructor Summary
AbstractReadBuffer()
           

 

Method Summary
protected  void checkBounds(int of, int cb)
          Check if the specified read is within bounds.
 java.lang.Object clone()
          Create a clone of this ReadBuffer object.
 boolean equals(java.lang.Object o)
          Compare two ReadBuffer objects for equality.
 ReadBuffer.BufferInput getBufferInput()
          Get a BufferInput object to read data from this buffer.
 int getEncodedHash()
          Return the encoded hash value or HashEncoded.UNENCODED if absent.
 ReadBuffer getReadBuffer(int of, int cb)
          Obtain a ReadBuffer for a portion of this ReadBuffer.
protected abstract  ReadBuffer.BufferInput instantiateBufferInput()
          Factory method: Instantiate a BufferInput object to read data from the ReadBuffer.
protected abstract  ReadBuffer instantiateReadBuffer(int of, int cb)
          Factory method: Instantiate a ReadBuffer for a portion of this ReadBuffer.
static int readPackedInt(ByteSequence bin, int of)
          Read an int value using a variable-length storage format as described by WriteBuffer.BufferOutput.writePackedInt(int) from the given ByteSequence and offset.
static int readUnsignedByte(ByteSequence bin, int of)
          Read an unsigned byte value from the given ByteSequence and offset.
static int sizeofPackedInt(int n)
          Return the number of bytes that would be required to store the given int using the variable-length storage format as described by WriteBuffer.BufferOutput.writePackedInt(int).
 ByteSequence subSequence(int ofStart, int ofEnd)
          Returns a new ByteSequence that is a subsequence of this sequence.
 Binary toBinary()
          Return a new Binary object that holds the complete contents of this ReadBuffer.
 Binary toBinary(int of, int cb)
          Return a Binary object that holds the specified portion of this ReadBuffer.
 byte[] toByteArray()
          Get the contents of the ReadBuffer as a byte array.
 byte[] toByteArray(int of, int cb)
          Get a portion of the contents of the ReadBuffer as a byte array.

 

Methods inherited from interface com.tangosol.io.ReadBuffer
byteAt, copyBytes, length, toByteBuffer, toByteBuffer, writeTo, writeTo, writeTo, writeTo, writeTo, writeTo

 

Field Detail

NO_BYTES

public static final byte[] NO_BYTES
An empty byte array (by definition immutable).

NO_BINARY

public static final Binary NO_BINARY
An empty Binary object.

Constructor Detail

AbstractReadBuffer

public AbstractReadBuffer()

Method Detail

getBufferInput

public ReadBuffer.BufferInput getBufferInput()
Get a BufferInput object to read data from this buffer. Note that each call to this method will return a new BufferInput object, with the possible exception being that a zero-length ReadBuffer could always return the same instance (since there is nothing to read).
Specified by:
getBufferInput in interface ReadBuffer
Returns:
a BufferInput that is reading from this buffer starting at offset zero

getReadBuffer

public ReadBuffer getReadBuffer(int of,
                                int cb)
Obtain a ReadBuffer for a portion of this ReadBuffer.
Specified by:
getReadBuffer in interface ReadBuffer
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

toByteArray

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

This is the equivalent of toByteArray(0, length()).

Specified by:
toByteArray in interface ReadBuffer
Returns:
a byte[] with the contents of this ReadBuffer object

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
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()
Return a new Binary object that holds the complete contents of this ReadBuffer.

This is the equivalent of toBinary(0, length()).

Specified by:
toBinary in interface ReadBuffer
Specified by:
toBinary in interface ByteSequence
Returns:
the contents of this ReadBuffer as a Binary object

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
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

subSequence

public ByteSequence subSequence(int ofStart,
                                int ofEnd)
Returns a new ByteSequence that is a subsequence of this sequence. The subsequence starts with the byte value at the specified index and ends with the byte value at index ofEnd - 1. The length (in bytes) of the returned sequence is ofEnd - ofStart, so if ofStart == ofEnd then an empty sequence is returned.
Specified by:
subSequence in interface ReadBuffer
Specified by:
subSequence in interface ByteSequence
Parameters:
ofStart - the start index, inclusive
ofEnd - the end index, exclusive
Returns:
the specified subsequence
Since:
Coherence 3.7

getEncodedHash

public int getEncodedHash()
Return the encoded hash value or HashEncoded.UNENCODED if absent.
Specified by:
getEncodedHash in interface HashEncoded
Returns:
the encoded hash value or HashEncoded.UNENCODED if absent

equals

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

clone

public java.lang.Object clone()
Create a clone of this ReadBuffer object.
Specified by:
clone in interface ReadBuffer
Returns:
a ReadBuffer object with the same contents as this ReadBuffer object

instantiateReadBuffer

protected abstract ReadBuffer instantiateReadBuffer(int of,
                                                    int cb)
Factory method: Instantiate a ReadBuffer for a portion of this ReadBuffer.
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 abstract ReadBuffer.BufferInput instantiateBufferInput()
Factory method: Instantiate a BufferInput object to read data from the ReadBuffer.
Returns:
a new BufferInput reading from this ReadBuffer

checkBounds

protected void checkBounds(int of,
                           int cb)
Check if the specified read is within bounds.
Parameters:
of - the absolute offset of the read operation
cb - the length in bytes of the read operation
Throws:
java.lang.IndexOutOfBoundsException - if the specified read is not within bounds

readUnsignedByte

public static int readUnsignedByte(ByteSequence bin,
                                   int of)
Read an unsigned byte value from the given ByteSequence and offset.

This method is the counterpart for the DataOutput.writeByte(int) method when it is used with unsigned 8-bit values.

Returns:
an int value in the range 0x00 to 0xFF

readPackedInt

public static int readPackedInt(ByteSequence bin,
                                int of)
Read an int value using a variable-length storage format as described by WriteBuffer.BufferOutput.writePackedInt(int) from the given ByteSequence and offset.
Returns:
an int value

sizeofPackedInt

public static int sizeofPackedInt(int n)
Return the number of bytes that would be required to store the given int using the variable-length storage format as described by WriteBuffer.BufferOutput.writePackedInt(int).
Parameters:
n - the integer that will be stored as a packed int
Returns:
the number of bytes required to store the packed int

Skip navigation links

Oracle® Coherence Java API Reference
Release 12.1.2.0.3

E26043-02


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