|
Oracle® Coherence Java API Reference Release 3.6.0.0 E15725-01 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object
com.tangosol.io.AbstractWriteBuffer
com.tangosol.io.nio.ByteBufferWriteBuffer
public final class ByteBufferWriteBuffer
A WriteBuffer implementation on top of a Java NIO ByteBuffer.
Nested Class Summary | |
---|---|
class |
ByteBufferWriteBuffer.ByteBufferOutput This is a simple implementation of the BufferOutput interface on top of a ByteBuffer. |
Nested classes/interfaces inherited from class com.tangosol.io.AbstractWriteBuffer |
---|
AbstractWriteBuffer.AbstractBufferOutput |
Nested classes/interfaces inherited from interface com.tangosol.io.WriteBuffer |
---|
WriteBuffer.BufferOutput |
Field Summary |
---|
Fields inherited from class com.tangosol.io.AbstractWriteBuffer |
---|
CHAR_BUF_MASK, CHAR_BUF_SIZE, m_achBuf, NO_BINARY, NO_BYTES |
Constructor Summary | |
---|---|
ByteBufferWriteBuffer(ByteBuffer buf) Construct a ByteBufferWriteBuffer on an NIO ByteBuffer. |
Method Summary | |
---|---|
Object |
clone() Create a clone of this WriteBuffer object. Changes to the clone will not affect the original, and vice-versa. |
WriteBuffer.BufferOutput |
getBufferOutput(int of) Get a BufferOutput object to write data to this buffer starting at a particular offset. Note that each call to this method will return a new BufferOutput object, with the possible exception being that a zero-length non-resizing WriteBuffer could always return the same instance (since it is not writable). This is functionally equivalent to:
|
ByteBuffer |
getByteBuffer() Obtain the ByteBuffer that this WriteBuffer is based on. |
int |
getCapacity() Determine the number of bytes that the buffer can hold without resizing itself. In other words, a WriteBuffer has getCapacity() - WriteBuffer.length() bytes that can be written to it without overflowing the current underlying buffer allocation. Since the buffer is an abstract concept, the actual mechanism for the underlying buffer is not known, but it could be a Java NIO buffer, or a byte array, etc.
Note that if the maximum size returned by |
ReadBuffer |
getReadBuffer() Get a ReadBuffer object that is a snapshot of this WriteBuffer's data. This method is functionally equivalent to the following code:
|
ReadBuffer |
getUnsafeReadBuffer() Get a ReadBuffer object to read data from this buffer. This method is not guaranteed to return a snapshot of this buffer's data, nor is it guaranteed to return a live view of this buffer, which means that subsequent changes to this WriteBuffer may or may not affect the contents and / or the length of the returned ReadBuffer. To get a snapshot, use the |
int |
length() Determine the length of the data that is in the buffer. This is the actual number of bytes of data that have been written to the buffer, not the capacity of the buffer. |
void |
retain(int of, int cb) Starting with the byte at offset of, retain cb bytes in this WriteBuffer, such that the byte at offset of is shifted to offset 0, the byte at offset of + 1 is shifted to offset 1, and so on up to the byte at offset of + cb - 1, which is shifted to offset cb - 1. After this method, the length of the buffer as indicated by the WriteBuffer.length() method will be equal to cb.
Legal values for the offset of the first byte to retain of are (of >= 0 && of <= If cb is zero, then this method will have the same effect as clear. If of is zero, then this method will have the effect of truncating the data in the buffer, but no bytes will be shifted within the buffer. The effect on the capacity of the buffer is implementation-specific; some implementations are expected to retain the same capacity while others are expected to shrink accordingly. |
Binary |
toBinary() Returns a new Binary object that holds the complete contents of this WriteBuffer. This method is functionally equivalent to the following code:
|
byte[] |
toByteArray() Returns a new byte array that holds the complete contents of this WriteBuffer. This method is functionally equivalent to the following code:
|
void |
write(int ofDest, byte b) Store the specified byte at the specified offset within the buffer. For purposes of side-effects and potential exceptions, this method is functionally equivalent to the following code:
|
void |
write(int ofDest, byte[] abSrc, int ofSrc, int cbSrc) Store the specified number of bytes from the specified location within the passed byte array at the specified offset within this buffer. As a result of this method, the buffer length as reported by the As a result of this method, the buffer capacity as reported by the |
void |
write(int ofDest, ReadBuffer bufSrc, int ofSrc, int cbSrc) Store the specified portion of the contents of the specified ReadBuffer at the specified offset within this buffer. For purposes of side-effects and potential exceptions, this method is functionally equivalent to the following code:
|
Methods inherited from class com.tangosol.io.AbstractWriteBuffer |
---|
clear, copyBufferInputPortion, copyBufferInputRemainder, copyStream, getAppendingBufferOutput, getBufferOutput, getMaximumCapacity, getWriteBuffer, getWriteBuffer, releaseBuffers, retain, tmpbuf, tmpbuf, write, write, write, write |
Methods inherited from interface com.tangosol.io.WriteBuffer |
---|
clear, getAppendingBufferOutput, getBufferOutput, getMaximumCapacity, getWriteBuffer, getWriteBuffer, retain, write, write, write, write |
Constructor Detail |
---|
public ByteBufferWriteBuffer(ByteBuffer buf)
buf
- the underlying NIO ByteBufferMethod Detail |
---|
public ByteBuffer getByteBuffer()
public void write(int ofDest, byte b)
For purposes of side-effects and potential exceptions, this method is functionally equivalent to the following code:
byte[] abSrc = new byte[1];
abSrc[0] = b;
write(ofDest, abSrc, 0, abSrc.length);
write
in interface WriteBuffer
write
in class AbstractWriteBuffer
ofDest
- the offset within this buffer to store the passed datab
- the byte to store in this bufferpublic void write(int ofDest, byte[] abSrc, int ofSrc, int cbSrc)
As a result of this method, the buffer length as reported by the WriteBuffer.length()
method will become Math.max(WriteBuffer.length()
, ofDest + cbSrc).
As a result of this method, the buffer capacity as reported by the WriteBuffer.getCapacity()
method will not change if the new value returned by WriteBuffer.length()
would not exceed the old value returned by WriteBuffer.getCapacity()
; otherwise, the capacity will be increased such that WriteBuffer.getCapacity()
>= WriteBuffer.length()
. Regardless, it is always true that WriteBuffer.getCapacity()
>= WriteBuffer.length()
and WriteBuffer.getMaximumCapacity()
>= WriteBuffer.getCapacity()
. If the buffer capacity cannot be increased due to resource constraints, an undesignated Error or RuntimeException will be thrown, such as OutOfMemoryError.
write
in interface WriteBuffer
write
in class AbstractWriteBuffer
ofDest
- the offset within this buffer to store the passed dataabSrc
- the array containing the bytes to store in this bufferofSrc
- the offset within the passed byte array to copy fromcbSrc
- the number of bytes to copy from the passed byte arraypublic void write(int ofDest, ReadBuffer bufSrc, int ofSrc, int cbSrc)
For purposes of side-effects and potential exceptions, this method is functionally equivalent to the following code:
byte[] abSrc = bufSrc.toByteArray(ofSrc, cbSrc);
write(ofDest, abSrc, 0, abSrc.length);
write
in interface WriteBuffer
write
in class AbstractWriteBuffer
ofDest
- the offset within this buffer to store the passed databufSrc
- the array of bytes to store in this bufferofSrc
- the offset within the passed ReadBuffer to copy fromcbSrc
- the number of bytes to copy from the passed ReadBufferpublic int length()
length
in interface WriteBuffer
length
in class AbstractWriteBuffer
public void retain(int of, int cb)
WriteBuffer.length()
method will be equal to cb.
Legal values for the offset of the first byte to retain of are (of >= 0 && of <= WriteBuffer.length()
). Legal values for the number of bytes to retain cb are (cb >= 0 && cb <= WriteBuffer.length()
), such that (of + cb <= WriteBuffer.length()
).
If cb is zero, then this method will have the same effect as clear. If of is zero, then this method will have the effect of truncating the data in the buffer, but no bytes will be shifted within the buffer.
The effect on the capacity of the buffer is implementation-specific; some implementations are expected to retain the same capacity while others are expected to shrink accordingly.
retain
in interface WriteBuffer
retain
in class AbstractWriteBuffer
of
- the offset of the first byte within the WriteBuffer that will be retainedcb
- the number of bytes to retainpublic int getCapacity()
WriteBuffer.length()
bytes that can be written to it without overflowing the current underlying buffer allocation. Since the buffer is an abstract concept, the actual mechanism for the underlying buffer is not known, but it could be a Java NIO buffer, or a byte array, etc.
Note that if the maximum size returned by WriteBuffer.getMaximumCapacity()
is greater than the current size returned by this method, then the WriteBuffer will automatically resize itself to allocate more space when the amount of data written to it passes the current size.
getCapacity
in interface WriteBuffer
getCapacity
in class AbstractWriteBuffer
public WriteBuffer.BufferOutput getBufferOutput(int of)
Note that each call to this method will return a new BufferOutput object, with the possible exception being that a zero-length non-resizing WriteBuffer could always return the same instance (since it is not writable).
This is functionally equivalent to:
BufferOutput bufout = getBufferOutput();
bufout.setOffset(of);
return bufout;
getBufferOutput
in interface WriteBuffer
getBufferOutput
in class AbstractWriteBuffer
of
- the offset of the first byte of this buffer that the BufferOutput will write topublic ReadBuffer getReadBuffer()
This method is functionally equivalent to the following code:
ReadBuffer buf = getUnsafeReadBuffer();
byte[] ab = buf.toByteArray();
return new ByteArrayReadBuffer(ab);
getReadBuffer
in interface WriteBuffer
getReadBuffer
in class AbstractWriteBuffer
public ReadBuffer getUnsafeReadBuffer()
To get a snapshot, use the WriteBuffer.getReadBuffer()
method.
getUnsafeReadBuffer
in interface WriteBuffer
getUnsafeReadBuffer
in class AbstractWriteBuffer
public byte[] toByteArray()
This method is functionally equivalent to the following code:
return getUnsafeReadBuffer().toByteArray();
toByteArray
in interface WriteBuffer
toByteArray
in class AbstractWriteBuffer
public Binary toBinary()
This method is functionally equivalent to the following code:
return getUnsafeReadBuffer().toBinary();
toBinary
in interface WriteBuffer
toBinary
in class AbstractWriteBuffer
public Object clone()
clone
in interface WriteBuffer
clone
in class AbstractWriteBuffer
|
Oracle® Coherence Java API Reference Release 3.6.0.0 E15725-01 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |