Package com.tangosol.io
Class AbstractReadBuffer
java.lang.Object
com.tangosol.util.Base
com.tangosol.io.AbstractReadBuffer
- All Implemented Interfaces:
ReadBuffer,ByteSequence,HashEncoded,Cloneable
- Direct Known Subclasses:
AbstractByteArrayReadBuffer,ByteBufferReadBuffer,MultiBufferReadBuffer
Abstract base implementation of the ReadBuffer interface.
- Author:
- cp 2006.04.17
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassThis is an implementation of the BufferInput interface that delegates its work back to its ReadBuffer.Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriterNested classes/interfaces inherited from interface com.tangosol.io.ReadBuffer
ReadBuffer.BufferInput -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BinaryAn empty Binary object.static final byte[]An empty byte array (by definition immutable).Fields inherited from class com.tangosol.util.Base
DEFAULT_LOAD_FACTOR, 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_USFields inherited from interface com.tangosol.util.HashEncoded
UNENCODED -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckBounds(int of, int cb) Check if the specified read is within bounds.clone()Create a clone of this ReadBuffer object.booleanCompare two ReadBuffer objects for equality.Get a BufferInput object to read data from this buffer.intReturn the encoded hash value orHashEncoded.UNENCODEDif absent.getReadBuffer(int of, int cb) Obtain a ReadBuffer for a portion of this ReadBuffer.protected abstract ReadBuffer.BufferInputFactory method: Instantiate a BufferInput object to read data from the ReadBuffer.protected abstract ReadBufferinstantiateReadBuffer(int of, int cb) Factory method: Instantiate a ReadBuffer for a portion of this ReadBuffer.static intreadPackedInt(ByteSequence bin, int of) Read an int value using a variable-length storage format as described byWriteBuffer.BufferOutput.writePackedInt(int)from the givenByteSequenceand offset.static intreadUnsignedByte(ByteSequence bin, int of) Read an unsigned byte value from the givenByteSequenceand offset.static intsizeofPackedInt(int n) Return the number of bytes that would be required to store the given int using the variable-length storage format as described byWriteBuffer.BufferOutput.writePackedInt(int).subSequence(int ofStart, int ofEnd) Returns a newByteSequencethat is a subsequence of this sequence.toBinary()Return a new Binary object that holds the complete contents of this ReadBuffer.toBinary(int of, int cb) Return a Binary object that holds the specified portion of this ReadBuffer.byte[]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 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, newHashMap, newHashMap, newHashSet, newHashSet, 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, waitMethods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.tangosol.io.ReadBuffer
byteAt, copyBytes, length, toByteBuffer, toByteBuffer, writeTo, writeTo, writeTo, writeTo, writeTo, writeTo
-
Field Details
-
NO_BYTES
public static final byte[] NO_BYTESAn empty byte array (by definition immutable). -
NO_BINARY
An empty Binary object.
-
-
Constructor Details
-
AbstractReadBuffer
public AbstractReadBuffer()
-
-
Method Details
-
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:
getBufferInputin interfaceReadBuffer- Returns:
- a BufferInput that is reading from this buffer starting at offset zero
-
getReadBuffer
Obtain a ReadBuffer for a portion of this ReadBuffer.- Specified by:
getReadBufferin interfaceReadBuffer- 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
-
toByteArray
public byte[] toByteArray()Get the contents of the ReadBuffer as a byte array.This is the equivalent of
toByteArray(0, length()).- Specified by:
toByteArrayin interfaceReadBuffer- 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:
toByteArrayin interfaceReadBuffer- 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
Return a new Binary object that holds the complete contents of this ReadBuffer.This is the equivalent of
toBinary(0, length()).- Specified by:
toBinaryin interfaceByteSequence- Specified by:
toBinaryin interfaceReadBuffer- Returns:
- the contents of this ReadBuffer as a Binary object
-
toBinary
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- 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
-
subSequence
Returns a newByteSequencethat is a subsequence of this sequence. The subsequence starts with thebytevalue at the specified index and ends with thebytevalue at index ofEnd - 1. The length (inbytes) of the returned sequence is ofEnd - ofStart, so if ofStart == ofEnd then an empty sequence is returned.- Specified by:
subSequencein interfaceByteSequence- Specified by:
subSequencein interfaceReadBuffer- Parameters:
ofStart- the start index, inclusiveofEnd- the end index, exclusive- Returns:
- the specified subsequence
- Since:
- Coherence 3.7
-
getEncodedHash
public int getEncodedHash()Return the encoded hash value orHashEncoded.UNENCODEDif absent.- Specified by:
getEncodedHashin interfaceHashEncoded- Returns:
- the encoded hash value or
HashEncoded.UNENCODEDif absent
-
equals
Compare two ReadBuffer objects for equality.- Specified by:
equalsin interfaceReadBuffer- Overrides:
equalsin classObject- Parameters:
o- a ReadBuffer object- Returns:
- true iff the other ReadBuffer is identical to this
-
clone
Create a clone of this ReadBuffer object.- Specified by:
clonein interfaceReadBuffer- Overrides:
clonein classObject- Returns:
- a ReadBuffer object with the same contents as this ReadBuffer object
-
instantiateReadBuffer
Factory method: Instantiate a ReadBuffer for a portion of this ReadBuffer.- 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
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 operationcb- the length in bytes of the read operation- Throws:
IndexOutOfBoundsException- if the specified read is not within bounds
-
readUnsignedByte
Read an unsigned byte value from the givenByteSequenceand offset.This method is the counterpart for the
DataOutput.writeByte(int)method when it is used with unsigned 8-bit values.- Parameters:
bin- the byte sequenceof- the offset- Returns:
- an
intvalue in the range 0x00 to 0xFF
-
readPackedInt
Read an int value using a variable-length storage format as described byWriteBuffer.BufferOutput.writePackedInt(int)from the givenByteSequenceand offset.- Parameters:
bin- the byte sequenceof- the 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 byWriteBuffer.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
-