Public Member Functions |
| ByteArrayBuffer (int capacity, bool readOnly=false) |
| Creates a ByteArrayBuffer object that has its backing array allocated internally and is then owned and deleted when this object is deleted.
|
| ByteArrayBuffer (unsigned char *array, int size, int offset, int length, bool readOnly=false) |
| Creates a ByteArrayBuffer object that wraps the given array.
|
| ByteArrayBuffer (const decaf::lang::Pointer< ByteArrayAdapter > &array, int offset, int length, bool readOnly=false) |
| Creates a byte buffer that wraps the passed ByteArrayAdapter and start at the given offset.
|
| ByteArrayBuffer (const ByteArrayBuffer &other) |
| Create a ByteArrayBuffer that mirrors this one, meaning it shares a reference to this buffers ByteArrayAdapter and when changes are made to that data it is reflected in both.
|
virtual | ~ByteArrayBuffer () |
virtual bool | isReadOnly () const |
| Tells whether or not this buffer is read-only.- Returns
- true if, and only if, this buffer is read-only
|
virtual unsigned char * | array () |
| Returns the byte array that backs this buffer.Modifications to this buffer's content will cause the returned array's content to be modified, and vice versa.Invoke the hasArray method before invoking this method in order to ensure that this buffer has an accessible backing array.- Returns
- The array that backs this buffer
- Exceptions
-
ReadOnlyBufferException | if this buffer is backed by an array but is read-only |
UnsupportedOperationException | if this buffer is not backed by an accessible array |
|
virtual int | arrayOffset () const |
| Returns the offset within this buffer's backing array of the first element of the buffer.If this buffer is backed by an array then buffer position p corresponds to array index p + arrayOffset().Invoke the hasArray method before invoking this method in order to ensure that this buffer has an accessible backing array.- Returns
- The offset within this buffer's array of the first element of the buffer.
- Exceptions
-
ReadOnlyBufferException | if this buffer is backed by an array but is read-only. |
UnsupportedOperationException | if this buffer is not backed by an accessible array. |
|
virtual bool | hasArray () const |
| Tells whether or not this buffer is backed by an accessible byte array.If this method returns true then the array and arrayOffset methods may safely be invoked. Subclasses should override this method if they do not have a backing array as this class always returns true.- Returns
- true if, and only if, this buffer is backed by an array and is not read-only.
|
virtual decaf::nio::CharBuffer * | asCharBuffer () const |
| Creates a view of this byte buffer as a char buffer.The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer, and its mark will be undefined. The new buffer will be read-only if, and only if, this buffer is read-only.- Returns
- the new Char Buffer, which the caller then owns.
|
virtual decaf::nio::DoubleBuffer * | asDoubleBuffer () const |
| Creates a view of this byte buffer as a double buffer.The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer divided by eight, and its mark will be undefined. The new buffer will be read-only if, and only if, this buffer is read-only.- Returns
- the new double Buffer, which the caller then owns.
|
virtual decaf::nio::FloatBuffer * | asFloatBuffer () const |
| Creates a view of this byte buffer as a float buffer.The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer divided by four, and its mark will be undefined. The new buffer will be read-only if, and only if, this buffer is read-only.- Returns
- the new float Buffer, which the caller then owns.
|
virtual decaf::nio::IntBuffer * | asIntBuffer () const |
| Creates a view of this byte buffer as a int buffer.The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer divided by four, and its mark will be undefined. The new buffer will be read-only if, and only if, this buffer is read-only.- Returns
- the new int Buffer, which the caller then owns.
|
virtual decaf::nio::LongBuffer * | asLongBuffer () const |
| Creates a view of this byte buffer as a long buffer.The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer divided by eight, and its mark will be undefined. The new buffer will be read-only if, and only if, this buffer is read-only.- Returns
- the new long Buffer, which the caller then owns.
|
virtual decaf::nio::ShortBuffer * | asShortBuffer () const |
| Creates a view of this byte buffer as a short buffer.The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer divided by two, and its mark will be undefined. The new buffer will be read-only if, and only if, this buffer is read-only.- Returns
- the new short Buffer, which the caller then owns.
|
virtual ByteArrayBuffer * | asReadOnlyBuffer () const |
| Creates a new, read-only byte buffer that shares this buffer's content.The content of the new buffer will be that of this buffer. Changes to this buffer's content will be visible in the new buffer; the new buffer itself, however, will be read-only and will not allow the shared content to be modified. The two buffers' position, limit, and mark values will be independent.If this buffer is itself read-only then this method behaves in exactly the same way as the duplicate method.The new buffer's capacity, limit, position, and mark values will be identical to those of this buffer.- Returns
- The new, read-only byte buffer which the caller then owns.
|
virtual ByteArrayBuffer & | compact () |
| Compacts this buffer.The bytes between the buffer's current position and its limit, if any, are copied to the beginning of the buffer. That is, the byte at index p = position() is copied to index zero, the byte at index p + 1 is copied to index one, and so forth until the byte at index limit() - 1 is copied to index n = limit() - 1 - p. The buffer's position is then set to n+1 and its limit is set to its capacity. The mark, if defined, is discarded.The buffer's position is set to the number of bytes copied, rather than to zero, so that an invocation of this method can be followed immediately by an invocation of another relative put method.- Returns
- a reference to this ByteBuffer.
- Exceptions
-
|
virtual ByteArrayBuffer * | duplicate () |
| Creates a new byte buffer that shares this buffer's content.The content of the new buffer will be that of this buffer. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.The new buffer's capacity, limit, position, and mark values will be identical to those of this buffer. The new buffer will be read-only if, and only if, this buffer is read-only.- Returns
- a new Byte Buffer which the caller owns.
|
virtual unsigned char | get () const |
| Relative get method.Reads the byte at this buffer's current position, and then increments the position.- Returns
- The byte at the buffer's current position.
- Exceptions
-
|
virtual unsigned char | get (int index) const |
| Absolute get method.Reads the byte at the given index.- Parameters
-
index | The index in the Buffer where the byte is to be read. |
- Returns
- the byte that is located at the given index.
- Exceptions
-
IndexOutOfBoundsException | if index is not smaller than the buffer's limit, or index is negative. |
|
virtual char | getChar () |
| Reads the next byte at this buffer's current position, and then increments the position by one.- Returns
- the next char in the buffer.
- Exceptions
-
|
virtual char | getChar (int index) const |
| Reads one byte at the given index and returns it.- Parameters
-
index | The index in the Buffer where the byte is to be read. |
- Returns
- the char at the given index in the buffer
- Exceptions
-
IndexOutOfBoundsException | if index is not smaller than the buffer's limit, or index is negative. |
|
virtual double | getDouble () |
| Reads the next eight bytes at this buffer's current position, and then increments the position by that amount.- Returns
- the next double in the buffer.
- Exceptions
-
|
virtual double | getDouble (int index) const |
| Reads eight bytes at the given index and returns it.- Parameters
-
index | The index in the Buffer where the bytes are to be read. |
- Returns
- the double at the given index in the buffer.
- Exceptions
-
IndexOutOfBoundsException | if index is not smaller than the buffer's limit, or index is negative. |
|
virtual float | getFloat () |
| Reads the next four bytes at this buffer's current position, and then increments the position by that amount.- Returns
- the next float in the buffer.
- Exceptions
-
|
virtual float | getFloat (int index) const |
| Reads four bytes at the given index and returns it.- Parameters
-
index | The index in the Buffer where the bytes are to be read. |
- Returns
- the float at the given index in the buffer.
- Exceptions
-
IndexOutOfBoundsException | if there are not enough bytes remaining to fill the requested Data Type, or index is negative. |
|
virtual long long | getLong () |
| Reads the next eight bytes at this buffer's current position, and then increments the position by that amount.- Returns
- the next long long in the buffer.
- Exceptions
-
|
virtual long long | getLong (int index) const |
| Reads eight bytes at the given index and returns it.- Parameters
-
index | The index in the Buffer where the bytes are to be read. |
- Returns
- the long long at the given index in the buffer.
- Exceptions
-
IndexOutOfBoundsException | if there are not enough bytes remaining to fill the requested Data Type, or index is negative. |
|
virtual int | getInt () |
| Reads the next four bytes at this buffer's current position, and then increments the position by that amount.- Returns
- the next int in the buffer.
- Exceptions
-
|
virtual int | getInt (int index) const |
| Reads four bytes at the given index and returns it.- Parameters
-
index | The index in the Buffer where the bytes are to be read. |
- Returns
- the int at the given index in the buffer.
- Exceptions
-
IndexOutOfBoundsException | if there are not enough bytes remaining to fill the requested Data Type, or index is negative. |
|
virtual short | getShort () |
| Reads the next two bytes at this buffer's current position, and then increments the position by that amount.- Returns
- the next short in the buffer.
- Exceptions
-
|
virtual short | getShort (int index) const |
| Reads two bytes at the given index and returns it.- Parameters
-
index | The index in the Buffer where the bytes are to be read. |
- Returns
- the short at the given index in the buffer.
- Exceptions
-
IndexOutOfBoundsException | if there are not enough bytes remaining to fill the requested Data Type, or index is negative. |
|
virtual ByteArrayBuffer & | put (unsigned char value) |
| Writes the given byte into this buffer at the current position, and then increments the position.- Parameters
-
value | - the byte value to be written. |
- Returns
- a reference to this buffer.
- Exceptions
-
|
virtual ByteArrayBuffer & | put (int index, unsigned char value) |
| Writes the given byte into this buffer at the given index.- Parameters
-
index | - position in the Buffer to write the data |
value | - the byte to write. |
- Returns
- a reference to this buffer.
- Exceptions
-
IndexOutOfBoundsException | if index greater than the buffer's limit minus the size of the type being written, or index is negative. |
ReadOnlyBufferException | if this buffer is read-only. |
|
virtual ByteArrayBuffer & | putChar (char value) |
| Writes one byte containing the given value, into this buffer at the current position, and then increments the position by one.- Parameters
-
value | The value to be written. |
- Returns
- a reference to this buffer.
- Exceptions
-
|
virtual ByteArrayBuffer & | putChar (int index, char value) |
| Writes one byte containing the given value, into this buffer at the given index.- Parameters
-
index | The position in the Buffer to write the data. |
value | The value to write. |
- Returns
- a reference to this buffer.
- Exceptions
-
IndexOutOfBoundsException | if index greater than the buffer's limit minus the size of the type being written, or index is negative. |
ReadOnlyBufferException | if this buffer is read-only |
|
virtual ByteArrayBuffer & | putDouble (double value) |
| Writes eight bytes containing the given value, into this buffer at the current position, and then increments the position by eight.- Parameters
-
value | The value to be written. |
- Returns
- a reference to this buffer.
- Exceptions
-
|
virtual ByteArrayBuffer & | putDouble (int index, double value) |
| Writes eight bytes containing the given value, into this buffer at the given index.- Parameters
-
index | The position in the Buffer to write the data |
value | The value to write. |
- Returns
- a reference to this buffer.
- Exceptions
-
IndexOutOfBoundsException | if index greater than the buffer's limit minus the size of the type being written, or index is negative. |
ReadOnlyBufferException | if this buffer is read-only. |
|
virtual ByteArrayBuffer & | putFloat (float value) |
| Writes four bytes containing the given value, into this buffer at the current position, and then increments the position by eight.- Parameters
-
value | The value to be written. |
- Returns
- a reference to this buffer.
- Exceptions
-
|
virtual ByteArrayBuffer & | putFloat (int index, float value) |
| Writes four bytes containing the given value, into this buffer at the given index.- Parameters
-
index | The position in the Buffer to write the data |
value | The value to write. |
- Returns
- a reference to this buffer.
- Exceptions
-
IndexOutOfBoundsException | if index greater than the buffer's limit minus the size of the type being written, or index is negative. |
ReadOnlyBufferException | if this buffer is read-only. |
|
virtual ByteArrayBuffer & | putLong (long long value) |
| Writes eight bytes containing the given value, into this buffer at the current position, and then increments the position by eight.- Parameters
-
value | The value to be written. |
- Returns
- a reference to this buffer.
- Exceptions
-
|
virtual ByteArrayBuffer & | putLong (int index, long long value) |
| Writes eight bytes containing the given value, into this buffer at the given index.- Parameters
-
index | The position in the Buffer to write the data. |
value | The value to write. |
- Returns
- a reference to this buffer.
- Exceptions
-
IndexOutOfBoundsException | if index greater than the buffer's limit minus the size of the type being written, or index is negative. |
ReadOnlyBufferException | if this buffer is read-only. |
|
virtual ByteArrayBuffer & | putInt (int value) |
| Writes four bytes containing the given value, into this buffer at the current position, and then increments the position by eight.- Parameters
-
value | The value to be written. |
- Returns
- a reference to this buffer.
- Exceptions
-
|
virtual ByteArrayBuffer & | putInt (int index, int value) |
| Writes four bytes containing the given value, into this buffer at the given index.- Parameters
-
index | The position in the Buffer to write the data. |
value | The value to write. |
- Returns
- a reference to this buffer
- Exceptions
-
IndexOutOfBoundsException | if index greater than the buffer's limit minus the size of the type being written, or index is negative. |
ReadOnlyBufferException | if this buffer is read-only |
|
virtual ByteArrayBuffer & | putShort (short value) |
| Writes two bytes containing the given value, into this buffer at the current position, and then increments the position by eight.- Parameters
-
value | The value to be written. |
- Returns
- a reference to this buffer.
- Exceptions
-
|
virtual ByteArrayBuffer & | putShort (int index, short value) |
| Writes two bytes containing the given value, into this buffer at the given index.- Parameters
-
index | The position in the Buffer to write the data |
value | The value to write. |
- Returns
- a reference to this buffer
- Exceptions
-
IndexOutOfBoundsException | if index greater than the buffer's limit minus the size of the type being written, or index is negative. |
ReadOnlyBufferException | if this buffer is read-only. |
|
virtual ByteArrayBuffer * | slice () const |
| Creates a new byte buffer whose content is a shared subsequence of this buffer's content.The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer, and its mark will be undefined. The new buffer will be read-only if, and only if, this buffer is read-only.- Returns
- the newly create ByteBuffer which the caller owns.
|
virtual | ~ByteBuffer () |
virtual std::string | toString () const |
ByteBuffer & | get (std::vector< unsigned char > buffer) |
| Relative bulk get method.
|
ByteBuffer & | get (unsigned char *buffer, int size, int offset, int length) |
| Relative bulk get method.
|
ByteBuffer & | put (ByteBuffer &src) |
| This method transfers the bytes remaining in the given source buffer into this buffer.
|
ByteBuffer & | put (const unsigned char *buffer, int size, int offset, int length) |
| This method transfers bytes into this buffer from the given source array.
|
ByteBuffer & | put (std::vector< unsigned char > &buffer) |
| This method transfers the entire content of the given source byte array into this buffer.
|
virtual int | compareTo (const ByteBuffer &value) const |
|
|
virtual bool | equals (const ByteBuffer &value) const |
|
|
virtual bool | operator== (const ByteBuffer &value) const |
|
|
virtual bool | operator< (const ByteBuffer &value) const |
|
|
| Buffer (int capactiy) |
| Buffer (const Buffer &other) |
virtual | ~Buffer () |
virtual int | capacity () const |
virtual int | position () const |
virtual Buffer & | position (int newPosition) |
| Sets this buffer's position.
|
virtual int | limit () const |
virtual Buffer & | limit (int newLimit) |
| Sets this buffer's limit.
|
virtual Buffer & | mark () |
| Sets this buffer's mark at its position.
|
virtual Buffer & | reset () |
| Resets this buffer's position to the previously-marked position.
|
virtual Buffer & | clear () |
| Clears this buffer.
|
virtual Buffer & | flip () |
| Flips this buffer.
|
virtual Buffer & | rewind () |
| Rewinds this buffer.
|
virtual int | remaining () const |
| Returns the number of elements between the current position and the limit.
|
virtual bool | hasRemaining () const |
| Tells whether there are any elements between the current position and the limit.
|
virtual | ~Comparable () |
virtual int | compareTo (const ByteBuffer &value) const =0 |
| Compares this object with the specified object for order.
|
virtual bool | equals (const ByteBuffer &value) const =0 |
virtual bool | operator== (const ByteBuffer &value) const =0 |
| Compares equality between this object and the one passed.
|
virtual bool | operator< (const ByteBuffer &value) const =0 |
| Compares this object to another and returns true if this object is considered to be less than the one passed.
|
This class defines six categories of operations upon byte buffers:
- Absolute and relative get and put methods that read and write single bytes;
- Relative bulk get methods that transfer contiguous sequences of bytes from this buffer into an array;
- Relative bulk put methods that transfer contiguous sequences of bytes from a byte array or some other byte buffer into this buffer;
- Absolute and relative get and put methods that read and write values of other primitive types, translating them to and from sequences of bytes in a particular byte order;
- Methods for creating view buffers, which allow a byte buffer to be viewed as a buffer containing values of some other primitive type; and
- Methods for compacting, duplicating, and slicing a byte buffer.
Byte buffers can be created either by allocation, which allocates space for the buffer's content, or by wrapping an existing byte array into a buffer.
Access to binary data:
This class defines methods for reading and writing values of all other primitive types, except boolean. Primitive values are translated to (or from) sequences of bytes according to the buffer's current byte order.
For access to heterogeneous binary data, that is, sequences of values of different types, this class defines a family of absolute and relative get and put methods for each type. For 32-bit floating-point values, for example, this class defines:
float getFloat() float getFloat(int index) void putFloat(float f) void putFloat(int index, float f)
Corresponding methods are defined for the types char, short, int, long, and double. The index parameters of the absolute get and put methods are in terms of bytes rather than of the type being read or written.
For access to homogeneous binary data, that is, sequences of values of the same type, this class defines methods that can create views of a given byte buffer. A view buffer is simply another buffer whose content is backed by the byte buffer. Changes to the byte buffer's content will be visible in the view buffer, and vice versa; the two buffers' position, limit, and mark values are independent. The asFloatBuffer method, for example, creates an instance of the FloatBuffer class that is backed by the byte buffer upon which the method is invoked. Corresponding view-creation methods are defined for the types char, short, int, long, and double.
View buffers have two important advantages over the families of type-specific get and put methods described above:
A view buffer is indexed not in terms of bytes but rather in terms of the type-specific size of its values;
A view buffer provides relative bulk get and put methods that can transfer contiguous sequences of values between a buffer and an array or some other buffer of the same type; and
- Since
- 1.0