Class AbstractByteArrayReadBuffer
- java.lang.Object
-
- com.tangosol.util.Base
-
- com.tangosol.io.AbstractReadBuffer
-
- com.tangosol.io.AbstractByteArrayReadBuffer
-
- All Implemented Interfaces:
ReadBuffer
,ByteSequence
,HashEncoded
,Cloneable
- Direct Known Subclasses:
Binary
,ByteArrayReadBuffer
public abstract class AbstractByteArrayReadBuffer extends AbstractReadBuffer
The AbstractByteArrayReadBuffer abstract class is intended to serve as a base class for the following:- the pre-existing Binary class
- a new byte[] based class that does not attempt to add the immutability aspect provided by the Binary class
- a new ByteBuffer based class that will work with Java NIO
This implementation is not intended to be thread safe.
- Author:
- cp 2005.01.18
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
AbstractByteArrayReadBuffer.ByteArrayBufferInput
This is a simple implementation of the BufferInput interface on top of a byte array.-
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 Modifier and Type Field Description protected byte[]
m_ab
The byte array that holds the binary data.protected int
m_cb
Number of bytes in the byte array that belong to this ReadBuffer object.protected int
m_of
Offset into the byte array at which the binary data is located.-
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 Modifier Constructor Description protected
AbstractByteArrayReadBuffer()
Default constructor; intended for deserialization use by subclasses.protected
AbstractByteArrayReadBuffer(byte[] ab, int of, int cb)
Construct an AbstractByteArrayReadBuffer on a portion of a byte array.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description byte
byteAt(int of)
Returns the byte at the specified offset.void
copyBytes(int ofBegin, int ofEnd, byte[] abDest, int ofDest)
Copies bytes from this ReadBuffer into the destination byte array.boolean
equals(Object o)
Compare two ReadBuffer objects for equality.protected ReadBuffer.BufferInput
instantiateBufferInput()
Factory method: Instantiate a BufferInput object to read data from the ReadBuffer.protected abstract boolean
isByteArrayPrivate()
Determine if the underlying byte[] should be treated as private data.int
length()
Determine the length of the buffer.protected void
resetRange(int of, int cb)
Reset the portion of the byte array the ReadBuffer operates upon.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(int of, int cb)
Get a portion of the contents of the ReadBuffer as a byte array.ByteBuffer
toByteBuffer()
Return a read-only ByteBuffer view of this ReadBuffer.ByteBuffer
toByteBuffer(int of, int cb)
Return a read-only ByteBuffer view of the specified portion of this ReadBuffer.void
writeTo(DataOutput out)
Write the contents of this ReadBuffer to a DataOutput.void
writeTo(DataOutput out, int of, int cb)
Write the contents of this ReadBuffer to a DataOutput.void
writeTo(OutputStream out)
Write the contents of this ReadBuffer to an OutputStream.void
writeTo(OutputStream out, int of, int cb)
Write the contents of the ReadBuffer to an OutputStream.void
writeTo(ByteBuffer buf)
Write the contents of the Binary object to a ByteBuffer.void
writeTo(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, clone, getBufferInput, getEncodedHash, getReadBuffer, instantiateReadBuffer, readPackedInt, readUnsignedByte, sizeofPackedInt, subSequence, 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
-
-
-
-
Field Detail
-
m_ab
protected byte[] m_ab
The byte array that holds the binary data. This value should not be changed.
-
m_of
protected int m_of
Offset into the byte array at which the binary data is located. This value should not be changed.
-
m_cb
protected int m_cb
Number of bytes in the byte array that belong to this ReadBuffer object. This value should not be changed.
-
-
Constructor Detail
-
AbstractByteArrayReadBuffer
protected AbstractByteArrayReadBuffer()
Default constructor; intended for deserialization use by subclasses.Note that this default constructor leaves the buffer in an invalid state.
-
AbstractByteArrayReadBuffer
protected AbstractByteArrayReadBuffer(byte[] ab, int of, int cb)
Construct an AbstractByteArrayReadBuffer on a portion of a byte array.- Parameters:
ab
- a byte arrayof
- an offset into the byte arraycb
- the number of bytes to utilize- Throws:
IndexOutOfBoundsException
- ifof
orcb
is negative, orof + cb
is larger thanab.length
NullPointerException
- ifab
isnull
-
-
Method Detail
-
length
public int length()
Determine the length of the buffer.- 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 from0
tolength() - 1
. The first byte of the sequence is at offset0
, the next at offset1
, and so on, as for array indexing.- 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 ofabDest
starting at offsetofDest
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 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
-
writeTo
public void writeTo(OutputStream out) throws IOException
Write the contents of this ReadBuffer to an OutputStream.- 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.- 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.- 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.- 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.- 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.- 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
-
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 interfaceReadBuffer
- Overrides:
toByteArray
in 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()
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 interfaceByteSequence
- Specified by:
toBinary
in interfaceReadBuffer
- Overrides:
toBinary
in classAbstractReadBuffer
- 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 interfaceReadBuffer
- Overrides:
toBinary
in 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.- 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()
.- 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
-
equals
public boolean equals(Object o)
Compare two ReadBuffer objects for equality.- Specified by:
equals
in interfaceReadBuffer
- Overrides:
equals
in classAbstractReadBuffer
- Parameters:
o
- a ReadBuffer object- Returns:
- true iff the other ReadBuffer is identical to this
-
instantiateBufferInput
protected ReadBuffer.BufferInput instantiateBufferInput()
Factory method: Instantiate a BufferInput object to read data from the ReadBuffer.- Specified by:
instantiateBufferInput
in classAbstractReadBuffer
- Returns:
- a new BufferInput reading from this ReadBuffer
-
resetRange
protected void resetRange(int of, int cb)
Reset the portion of the byte array the ReadBuffer operates upon.- Parameters:
of
- an offset into the byte arraycb
- the number of bytes to utilize- Throws:
IndexOutOfBoundsException
- ifof
orcb
are negative, orof + cb
is larger than the buffer's length
-
isByteArrayPrivate
protected abstract boolean isByteArrayPrivate()
Determine if the underlying byte[] should be treated as private data.- Returns:
- true iff the underlying data should not ever be exposed by this object
-
-