Package com.tangosol.io.nio
Class ByteBufferReadBuffer
- java.lang.Object
-
- com.tangosol.util.Base
-
- com.tangosol.io.AbstractReadBuffer
-
- com.tangosol.io.nio.ByteBufferReadBuffer
-
- All Implemented Interfaces:
ReadBuffer,ByteSequence,HashEncoded,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
Nested Classes Modifier and Type Class Description classByteBufferReadBuffer.ByteBufferInputThis 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 class com.tangosol.util.Base
Base.LoggingWriter
-
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
-
Fields inherited from class com.tangosol.util.Base
LOG_ALWAYS, LOG_CONFIG, LOG_DEBUG, LOG_ERR, LOG_INFO, LOG_MAX, LOG_MIN, LOG_QUIET, LOG_WARN, POWER_0, POWER_G, POWER_K, POWER_M, POWER_T, UNIT_D, UNIT_H, UNIT_M, UNIT_MS, UNIT_NS, UNIT_S, UNIT_US
-
Fields inherited from interface com.tangosol.util.HashEncoded
UNENCODED
-
-
Constructor Summary
Constructors Constructor Description ByteBufferReadBuffer(ByteBuffer buf)Construct a ByteBufferReadBuffer on an NIO ByteBuffer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description bytebyteAt(int of)Returns the byte at the specified offset.Objectclone()Create a clone of this ReadBuffer object.voidcopyBytes(int ofBegin, int ofEnd, byte[] abDest, int ofDest)Copies bytes from this ReadBuffer into the destination byte array.ByteBuffergetByteBuffer()Obtain the ByteBuffer that this ReadBuffer is based on.protected ReadBuffer.BufferInputinstantiateBufferInput()Factory method: Instantiate a BufferInput object to read data from the ReadBuffer.protected ReadBufferinstantiateReadBuffer(int of, int cb)Factory method: Instantiate a ReadBuffer for a portion of this ReadBuffer.intlength()Determine the length of the buffer.BinarytoBinary(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.ByteBuffertoByteBuffer()Return a read-only ByteBuffer view of this ReadBuffer.ByteBuffertoByteBuffer(int of, int cb)Return a read-only ByteBuffer view of the specified portion of this ReadBuffer.voidwriteTo(DataOutput out)Write the contents of this ReadBuffer to a DataOutput.voidwriteTo(DataOutput out, int of, int cb)Write the contents of this ReadBuffer to a DataOutput.voidwriteTo(OutputStream out)Write the contents of this ReadBuffer to an OutputStream.voidwriteTo(OutputStream out, int of, int cb)Write the contents of the ReadBuffer to an OutputStream.voidwriteTo(ByteBuffer buf)Write the contents of the Binary object to a ByteBuffer.voidwriteTo(ByteBuffer buf, int of, int cb)Write the contents of the Binary object to a ByteBuffer.-
Methods inherited from class com.tangosol.io.AbstractReadBuffer
checkBounds, equals, getBufferInput, getEncodedHash, getReadBuffer, readPackedInt, readUnsignedByte, sizeofPackedInt, subSequence, toBinary, toByteArray
-
Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
-
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.tangosol.io.ReadBuffer
equals, getBufferInput, getReadBuffer, subSequence, toBinary, toByteArray
-
-
-
-
Constructor Detail
-
ByteBufferReadBuffer
public ByteBufferReadBuffer(ByteBuffer buf)
Construct a ByteBufferReadBuffer on an NIO ByteBuffer.- Parameters:
buf- the underlying NIO ByteBuffer
-
-
Method Detail
-
getByteBuffer
public ByteBuffer getByteBuffer()
Obtain the ByteBuffer that this ReadBuffer is based on.- Returns:
- the underlying ByteBuffer
-
writeTo
public void writeTo(OutputStream out) throws IOException
Write the contents of this ReadBuffer to an OutputStream.- Specified by:
writeToin interfaceReadBuffer- Parameters:
out- an OutputStream to write to- Throws:
IOException- if an I/O exception occurs
-
writeTo
public void writeTo(OutputStream out, int of, int cb) throws IOException
Write the contents of the ReadBuffer to an OutputStream.- Specified by:
writeToin interfaceReadBuffer- Parameters:
out- an OutputStream to write toof- the beginning index, inclusivecb- the number of bytes to write to an OutputStream- Throws:
IOException- if an I/O exception occurs
-
writeTo
public void writeTo(DataOutput out) throws IOException
Write the contents of this ReadBuffer to a DataOutput.- Specified by:
writeToin interfaceReadBuffer- Parameters:
out- a DataOutput to write to- Throws:
IOException- if an I/O exception occurs
-
writeTo
public void writeTo(DataOutput out, int of, int cb) throws IOException
Write the contents of this ReadBuffer to a DataOutput.- Specified by:
writeToin interfaceReadBuffer- Parameters:
out- a DataOutput to write toof- the beginning index, inclusivecb- the number of bytes to write to a DataOutput- Throws:
IOException- if an I/O exception occurs
-
writeTo
public void writeTo(ByteBuffer buf)
Write the contents of the Binary object to a ByteBuffer.- Specified by:
writeToin interfaceReadBuffer- Parameters:
buf- a ByteBuffer to write to
-
writeTo
public void writeTo(ByteBuffer buf, int of, int cb) throws IOException
Write the contents of the Binary object to a ByteBuffer.- Specified by:
writeToin interfaceReadBuffer- Parameters:
buf- an ByteBuffer to write toof- the beginning index, inclusivecb- the number of bytes to write to a ByteBuffer- Throws:
IOException- if an I/O exception occurs
-
length
public int length()
Determine the length of the buffer.- Specified by:
lengthin interfaceByteSequence- Specified by:
lengthin interfaceReadBuffer- 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 from0tolength() - 1. The first byte of the sequence is at offset0, the next at offset1, and so on, as for array indexing.- Specified by:
byteAtin interfaceByteSequence- Specified by:
byteAtin interfaceReadBuffer- 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 offsetofEnd-1(thus the total number of bytes to be copied isofEnd - ofBegin). The bytes are copied into the sub-array ofabDeststarting at offsetofDestand ending at index:ofDest + (ofEnd - ofBegin) - 1This 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:
copyBytesin interfaceReadBuffer- Parameters:
ofBegin- offset of the first byte in the ReadBuffer to copyofEnd- offset after the last byte in the ReadBuffer to copyabDest- the destination byte arrayofDest- 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:
toByteArrayin interfaceReadBuffer- Overrides:
toByteArrayin classAbstractReadBuffer- Parameters:
of- the beginning index, inclusivecb- 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:
toBinaryin interfaceReadBuffer- Overrides:
toBinaryin classAbstractReadBuffer- Parameters:
of- the beginning index, inclusivecb- the number of bytes to include in the Binary object- Returns:
- a Binary object containing the specified portion of this ReadBuffer
-
toByteBuffer
public 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.- Specified by:
toByteBufferin interfaceReadBuffer- Returns:
- a read-only ByteBuffer view of this ReadBuffer
-
toByteBuffer
public 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().- Specified by:
toByteBufferin interfaceReadBuffer- Parameters:
of- the beginning index, inclusivecb- the number of bytes to include in the ByteBuffer object- Returns:
- a read-only ByteBuffer view of the specified portion of this ReadBuffer
-
clone
public Object clone()
Create a clone of this ReadBuffer object.- Specified by:
clonein interfaceReadBuffer- Overrides:
clonein classAbstractReadBuffer- 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:
instantiateReadBufferin classAbstractReadBuffer- Parameters:
of- the beginning index, inclusivecb- 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:
instantiateBufferInputin classAbstractReadBuffer- Returns:
- a new BufferInput reading from this ReadBuffer
-
-