Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


com.tangosol.io
Interface ReadBuffer

All Superinterfaces:
ByteSequence, java.lang.Cloneable
All Known Implementing Classes:
AbstractByteArrayReadBuffer, AbstractReadBuffer, Binary, ByteArrayReadBuffer, ByteBufferReadBuffer, MultiBufferReadBuffer

public interface ReadBuffer
extends ByteSequence, java.lang.Cloneable

The ReadBuffer interface represents an in-memory block of binary data, such as that represented by a byte[], a Binary object, or an NIO buffer.

Author:
cp 2005.01.18

Nested Class Summary
static interface ReadBuffer.BufferInput
          The BufferInput interface represents a DataInputStream on top of a ReadBuffer.

 

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.
 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.
 ReadBuffer getReadBuffer(int of, int cb)
          Obtain a ReadBuffer for a portion of this ReadBuffer.
 int length()
          Determine the length of the buffer.
 ByteSequence subSequence(int ofStart, int ofEnd)
          Returns a new ByteSequence that is a subsequence of this sequence.
 Binary toBinary()
          Returns a new Binary object that holds the complete contents of this ReadBuffer.
 Binary toBinary(int of, int cb)
          Returns 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.

 

Method Detail

length

int length()
Determine the length of the buffer.
Specified by:
length in interface ByteSequence
Returns:
the number of bytes of data represented by this ReadBuffer

byteAt

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 ByteSequence
Parameters:
of - the offset (index) of the byte
Returns:
the byte at the specified offset in this ReadBuffer
Throws:
java.lang.IndexOutOfBoundsException - if the of argument is negative or not less than the length of this ReadBuffer

copyBytes

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.

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
Throws:
java.lang.IndexOutOfBoundsException - Thrown if any of the following is true:
  • ofBegin is negative;
  • ofBegin is greater than ofEnd
  • ofEnd is greater than the length of this ReadBuffer;
  • ofDest is negative
  • ofDest + (ofEnd - ofBegin) is larger than abDest.length
java.lang.NullPointerException - if abDest is null

getBufferInput

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).
Returns:
a BufferInput that is reading from this buffer starting at offset zero

getReadBuffer

ReadBuffer getReadBuffer(int of,
                         int cb)
Obtain 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
Throws:
java.lang.IndexOutOfBoundsException - if of or cb is negative, or of + cb is larger than the length of this ReadBuffer object

toByteArray

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

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

Returns:
a byte[] with the contents of this ReadBuffer object

toByteArray

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().

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
Throws:
java.lang.IndexOutOfBoundsException - if of or cb is negative, or of + cb is larger than the length of this ReadBuffer object

toBinary

Binary toBinary()
Returns 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 ByteSequence
Returns:
the contents of this ReadBuffer as a Binary object

toBinary

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().

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
Throws:
java.lang.IndexOutOfBoundsException - if of or cb is negative, or of + cb is larger than the length of this ReadBuffer object

subSequence

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 ByteSequence
Parameters:
ofStart - the start index, inclusive
ofEnd - the end index, exclusive
Returns:
the specified subsequence
Since:
Coherence 3.7

equals

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

clone

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

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


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