Oracle Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.1.2)

E26041-01

OctetArrayWriteBuffer Class Reference

#include <coherence/io/OctetArrayWriteBuffer.hpp>

Inherits AbstractWriteBuffer.

Inherited by BinaryWriteBuffer.

List of all members.


Detailed Description

OctetArrayWriteBuffer is an implementation of WriteBuffer on an octet array.

It is designed to support both fixed length buffers and resizable buffers.

This implementation is explicitly not thread-safe.

Author:
jh 2007.01.11

Public Types

typedef spec::Handle Handle
 OctetArrayWriteBuffer Handle definition.
typedef spec::View View
 OctetArrayWriteBuffer View definition.
typedef spec::Holder Holder
 OctetArrayWriteBuffer Holder definition.
typedef this_spec::Handle Handle
 AbstractWriteBuffer Handle definition.
typedef this_spec::View View
 AbstractWriteBuffer View definition.
typedef this_spec::Holder Holder
 AbstractWriteBuffer Holder definition.

Public Member Functions

virtual size32_t length () const
 Determine the length of the data that is in the buffer.

This is the actual number of octets of data that have been written to the buffer, not the capacity of the buffer.

Returns:
the number of octets of data represented by this WriteBuffer

virtual size32_t getCapacity () const
 Determine the number of octets that the buffer can hold without resizing itself.

In other words, a WriteBuffer has getCapacity() - length() octets 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.

Note that if the maximum size returned by 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.

Returns:
the number of octets of data that this WriteBuffer can hold without resizing its underlying buffer

virtual size32_t getMaximumCapacity () const
 Determine the maximum number of octets that the buffer can hold.

If the maximum size is greater than the current size, then the buffer is expected to resize itself as necessary up to the maximum size in order to contain the data given to it.

Returns:
the maximum number of octets of data that the WriteBuffer can hold

virtual void write (size32_t ofDest, octet_t b)
 Store the specified octet at the specified offset within the buffer.

For purposes of side-effects and potential exceptions, this method is functionally equivalent to the following code:


 Array<octet_t>::Handle habSrc = Array<octet_t>::create(1);
 habSrc[0] = b;
 write(ofDest, habSrc, 0, 1);
 

Parameters:
ofDest the offset within this buffer to store the passed data
b the octet to store in this buffer

virtual void write (size32_t ofDest, Array< octet_t >::View vabSrc, size32_t ofSrc, size32_t cbSrc)
 Store the specified number of octets from the specified location within the passed octet array at the specified offset within this buffer.

As a result of this method, the buffer length as reported by the length() method will become max(length(), ofDest + cbSrc).

As a result of this method, the buffer capacity as reported by the getCapacity() method will not change if the new value returned by length() would not exceed the old value returned by getCapacity(); otherwise, the capacity will be increased such that {getCapacity() >= length(). Regardless, it is always true that getCapacity() >= length() and getMaximumCapacity() >= getCapacity(). If the buffer capacity cannot be increased due to resource constraints, an undesignated Exception will be thrown.

Parameters:
ofDest the offset within this buffer to store the passed data
vabSrc the array containing the octets to store in this buffer
ofSrc the offset within the passed octet array to copy from
cbSrc the number of octets to copy from the passed octet array
Exceptions:
NullPointerException if vabSrc is NULL
IndexOutOfBoundsException if ofSrc + cbSrc is greater than vabSrc->length, or if ofDest + cbSrc is greater than getMaximumCapacity()

virtual void write (size32_t ofDest, ReadBuffer::View vBufSrc, size32_t ofSrc, size32_t 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:


 Array<octet_t>::View vabSrc = vbufSrc.toOctetArray(ofSrc, cbSrc);
 write(ofDest, vabSrc, 0, vabSrc->length);
 

Parameters:
ofDest the offset within this buffer to store the passed data
vBufSrc the source ReadBuffer
ofSrc the offset within the passed ReadBuffer to copy from
cbSrc the number of octets to copy from the passed ReadBuffer

virtual void retain (size32_t of, size32_t cb)
 Starting with the octet at offset of, retain cb octets in this WriteBuffer, such that the octet at offset of is shifted to offset 0, the octet at offset of + 1 is shifted to offset 1, and so on up to the octet at offset of + cb - 1, which is shifted to offset cb - 1.

After this method, the length of the buffer as indicated by the length() method will be equal to cb.

Legal values for the offset of the first octet to retain of are (of >= 0 && of <= length()). Legal values for the number of octets to retain cb are (cb >= 0 && cb <= length()), such that (of + cb <= 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 octets 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.

Parameters:
of the offset of the first octet within the WriteBuffer that will be retained
cb the number of octets to retain
Exceptions:
IndexOutOfBoundsException if of + cb is greater than length()

virtual ReadBuffer::View getUnsafeReadBuffer () const
 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 getReadBuffer() method.

Returns:
a ReadBuffer that reflects the contents of this WriteBuffer but whose behavior is undefined if the WriteBuffer is modified


Protected Member Functions

 OctetArrayWriteBuffer (Array< octet_t >::Handle hab)
 Construct an OctetArrayWriteBuffer on an octet array.
 OctetArrayWriteBuffer (size32_t cbCap, size32_t cbMax=(std::numeric_limits< size32_t >::max)())
 Construct an OctetArrayWriteBuffer with a certain initial capacity and a certain maximum capacity.
 OctetArrayWriteBuffer (const OctetArrayWriteBuffer &that)
 Copy constructor.
virtual
BufferOutput::Handle 
instantiateBufferOutput ()
 Factory method: Instantiate a BufferOutput object to write data to the WriteBuffer.

Returns:
a new BufferOutput writing to this ReadBuffer

virtual void checkBounds (size32_t of, size32_t cb)
 Validate the ranges for the passed bounds and make sure that the underlying array is big enough to handle them.
virtual void grow (size32_t cbCap)
 Grow the underlying octet array to at least the specified size.
virtual void updateLength (size32_t cb)
 Update the length if the passed length is greater than the current buffer length.
virtual void onEscape (bool fEscaped) const
 Event called when the guarding Object's escape state changes.

As with all event methods any derived implementation should include a call to the super class's implementation. Ultimately delegation must reach Object::onEscape() which will perform the actual act of preparing the object for multi/single-threaded access.

Throughout the call it is guaranteed that the object remains visible to only a single thread, and as such it is not allowable to perform an action from within this method which would attempt to escape this object.

Parameters:
fEscaped true if the object is escaping, false if it is being captured


Protected Attributes

MemberHandle< Array
< octet_t > > 
m_hab
 The octet array that holds the binary data.
octet_t * m_pab
 Raw pointer to byte[] within m_hab, or NULL if this object is escaped which would make its use impossible to prove as safe.
size32_t m_cbab
 The cached size of m_hab.
size32_t m_cb
 Number of octets in the octet array that have been written by this WriteBuffer.
size32_t m_cbMax
 Number of octets that the octet array can be grown to.
MemberHandle
< ReadBuffer
m_hBufUnsafe
 Cached ReadBuffer to quickly provide an answer to getUnsafeReadBuffer().

Classes

class  OctetArrayBufferOutput
 OctetArrayBufferOutput is an implementation of BufferOutput optimized for writing to the buffer's underlying octet array. More...

Constructor & Destructor Documentation

OctetArrayWriteBuffer ( Array< octet_t >::Handle  hab  )  [protected]

Construct an OctetArrayWriteBuffer on an octet array.

Parameters:
hab an octet array
Exceptions:
NullPointerException if hab is NULL

OctetArrayWriteBuffer ( size32_t  cbCap,
size32_t  cbMax = (std::numeric_limits< size32_t >::max)() 
) [protected]

Construct an OctetArrayWriteBuffer with a certain initial capacity and a certain maximum capacity.

Parameters:
cbCap initial capacity
cbMax maximum capacity
Exceptions:
IllegalArgumentException if cbCap is greater than cbMax


Member Function Documentation

virtual void checkBounds ( size32_t  of,
size32_t  cb 
) [protected, virtual]

Validate the ranges for the passed bounds and make sure that the underlying array is big enough to handle them.

Parameters:
of the offset that data is about to be written to
cb the length of the data that is about to be written

Reimplemented in BinaryWriteBuffer.

virtual void grow ( size32_t  cbCap  )  [protected, virtual]

Grow the underlying octet array to at least the specified size.

Parameters:
cbCap the required or requested capacity

virtual void updateLength ( size32_t  cb  )  [protected, virtual]

Update the length if the passed length is greater than the current buffer length.

Parameters:
cb the count of the last octet written (or the index of the next octet to write)


Member Data Documentation

size32_t m_cb [protected]

Number of octets in the octet array that have been written by this WriteBuffer.

This is the length.

size32_t m_cbMax [protected]

Number of octets that the octet array can be grown to.

This is the maximum capacity.


The documentation for this class was generated from the following file:
Copyright © 2000, 2013, Oracle and/or its affiliates. All rights reserved.