activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r594613 - in /activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio: Buffer.h ByteBuffer.cpp ByteBuffer.h
Date Tue, 13 Nov 2007 19:35:44 GMT
Author: tabish
Date: Tue Nov 13 11:35:42 2007
New Revision: 594613

URL: http://svn.apache.org/viewvc?rev=594613&view=rev
Log:
http://issues.apache.org/activemq/browse/AMQCPP-103

Starting the NIO implementation

Modified:
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/Buffer.h
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.h

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/Buffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/Buffer.h?rev=594613&r1=594612&r2=594613&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/Buffer.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/Buffer.h Tue Nov 13 11:35:42 2007
@@ -248,7 +248,7 @@
          * Returns the number of elements between the current position and the limit.
          * @returns The number of elements remaining in this buffer
          */
-        virtual int remaining() const {
+        virtual std::size_t remaining() const {
             return _limit - _position;
         }
 

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.cpp?rev=594613&r1=594612&r2=594613&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.cpp Tue Nov 13 11:35:42
2007
@@ -17,13 +17,231 @@
 
 #include "ByteBuffer.h"
 
+using namespace std;
 using namespace decaf;
 using namespace decaf::nio;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteBuffer::ByteBuffer() {
+ByteBuffer::ByteBuffer() : Buffer(0) {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 ByteBuffer::~ByteBuffer() {
 }
+
+////////////////////////////////////////////////////////////////////////////////
+static ByteBuffer* allocate( std::size_t capacity )
+    throw( lang::exceptions::IllegalArgumentException ) {
+
+    try{
+
+        if( capacity == 0 ) {
+            throw IllegalArgumentException(
+                __FILE__, __LINE__,
+                "ByteBuffer::allocate - Can't allocate zero sized ByteBuffer" );
+        }
+
+        return NULL;
+    }
+    DECAF_CATCH_RETHROW( IllegalArgumentException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IllegalArgumentException )
+    DECAF_CATCHALL_THROW( IllegalArgumentException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer* ByteBuffer::wrap( unsigned char* buffer, int offset, int length )
+    throw( lang::exceptions::NullPointerException ) {
+
+    try{
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "ByteBuffer::wrap - Passed Buffer is Null.");
+        }
+
+        return NULL;
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
+    DECAF_CATCHALL_THROW( NullPointerException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer* ByteBuffer::wrap( std::vector<unsigned char>& buffer ) {
+
+    try{
+
+        if( buffer.empty() ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "ByteBuffer::wrap - Passed Buffer is Empty.");
+        }
+
+        return ByteBuffer::wrap( &buffer[0], 0, buffer.size() );
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
+    DECAF_CATCHALL_THROW( NullPointerException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::get( std::vector<unsigned char> buffer )
+    throw ( BufferUnderflowException ) {
+
+    try{
+
+        if( buffer.empty() ) {
+            return *this;
+        }
+
+        this->get( &buffer[0], 0, buffer.size() );
+
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( BufferUnderflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
+    DECAF_CATCHALL_THROW( BufferUnderflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::get( unsigned char* buffer,
+                             std::size_t offset,
+                             std::size_t length )
+    throw( BufferUnderflowException, NullPointerException ) {
+
+    try{
+
+        if( length == 0 ) {
+            return *this;
+        }
+
+        if( length > this->remaining() ) {
+            throw BufferUnderflowException(
+                __FILE__, __LINE__,
+                "ByteBuffer::get - Not Enough Data to Fill Request.");
+        }
+
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "ByteBuffer::get - Passed Buffer is Null.");
+        }
+
+        // read length bytes starting from the offset
+        for( std::size_t ix = 0; ix < length; ++ix ) {
+            buffer[ix + offset] = this->get();
+        }
+
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( BufferUnderflowException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
+    DECAF_CATCHALL_THROW( BufferUnderflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::put( ByteBuffer& src )
+    throw( BufferOverflowException, ReadOnlyBufferException, IllegalArgumentException ) {
+
+    try{
+
+        if( this == &src ) {
+            throw IllegalArgumentException(
+                __FILE__, __LINE__,
+                "ByteBuffer::put - Can't put Self" );
+        }
+
+        if( this->isReadOnly() ) {
+            throw ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "ByteBuffer::put - This buffer is Read Only.");
+        }
+
+        if( src.remaining() > this->remaining() ) {
+            throw BufferOverflowException(
+                __FILE__, __LINE__,
+                "ByteBuffer::put - Not enough space remaining to put src." );
+        }
+
+        while( src.hasRemaining() ) {
+            this->put( src.get() );
+        }
+
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( BufferUnderflowException )
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
+    DECAF_CATCHALL_THROW( BufferUnderflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::put( const unsigned char* buffer,
+                             std::size_t offset,
+                             std::size_t length )
+    throw( BufferOverflowException, ReadOnlyBufferException, NullPointerException ) {
+
+    try{
+
+        if( length == 0 ) {
+            return *this;
+        }
+
+        if( this->isReadOnly() ) {
+            throw ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "ByteBuffer::put - This buffer is Read Only.");
+        }
+
+        if( length > this->remaining() ) {
+            throw BufferOverflowException(
+                __FILE__, __LINE__,
+                "ByteBuffer::put - Not Enough space to store requested Data.");
+        }
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "ByteBuffer::put - Passed Buffer is Null.");
+        }
+
+        // read length bytes starting from the offset
+        for( std::size_t ix = 0; ix < length; ++ix ) {
+            this->put( buffer[ix + offset] );
+        }
+
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( BufferUnderflowException )
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
+    DECAF_CATCHALL_THROW( BufferUnderflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::put( std::vector<unsigned char>& buffer )
+    throw( BufferOverflowException, ReadOnlyBufferException ) {
+
+    try{
+
+        if( buffer.empty() ) {
+            return *this;
+        }
+
+        this->get( &buffer[0], 0, buffer.size() );
+
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( BufferUnderflowException )
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
+    DECAF_CATCHALL_THROW( BufferUnderflowException )
+}
+

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.h?rev=594613&r1=594612&r2=594613&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.h Tue Nov 13 11:35:42
2007
@@ -20,10 +20,22 @@
 
 #include <decaf/nio/Buffer.h>
 #include <decaf/lang/Comparable.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
+#include <decaf/nio/BufferUnderflowException.h>
+#include <decaf/nio/BufferOverflowException.h>
+#include <decaf/nio/ReadOnlyBufferException.h>
 
 namespace decaf{
 namespace nio{
 
+    class CharBuffer;
+    class DoubleBuffer;
+    class FloatBuffer;
+    class ShortBuffer;
+    class IntBuffer;
+    class LongBuffer;
+
     /**
      * This class defines six categories of operations upon byte buffers:
      *
@@ -83,6 +95,10 @@
      *
      */
     class DECAF_API ByteBuffer : public Buffer {
+    protected:
+
+        bool readOnly;
+
     public:
 
         ByteBuffer();
@@ -108,6 +124,600 @@
             throw( ReadOnlyBufferException,
                    lang::exceptions::UnsupportedOperationException );
 
+        /**
+         * Returns the offset within this buffer's backing array of the first element
+         * of the buffer.
+         * <p>
+         * If this buffer is backed by an array then buffer position p corresponds to
+         * array index p + arrayOffset().
+         * <p>
+         * 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
+         * @throws ReadOnlyBufferException - If this buffer is backed by an array but
+         * is read-only
+         * @throws UnsupportedOperationException - If this buffer is not backed by an
+         * accessible array
+         */
+        virtual int arrayOffset() const
+            throw( ReadOnlyBufferException,
+                   lang::exceptions::UnsupportedOperationException );
+
+        /**
+         * 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.
+         * @returns true if, and only if, this buffer is backed by an array and is not
+         * read-only
+         */
+        virtual bool hasArray() const;
+
+        /**
+         * Relative bulk get method.
+         * <p>
+         * This method transfers bytes from this buffer into the given destination
+         * vector. An invocation of this method of the form src.get(a) behaves in
+         * exactly the same way as the invocation.  The vector must be sized to the
+         * amount of data that is to be read, that is to say, the caller should call
+         * buffer.resize( N ) before calling this get method.
+         * @returns a reference to this Byte Buffer
+         * @throws BufferUnderflowException - If there are fewer than length bytes
+         * remaining in this buffer
+         */
+        virtual ByteBuffer& get( std::vector<unsigned char> buffer )
+            throw ( BufferUnderflowException );
+
+        /**
+         * Relative bulk get method.
+         * <p>
+         * This method transfers bytes from this buffer into the given destination array.
+         * If there are fewer bytes remaining in the buffer than are required to satisfy
+         * the request, that is, if length > remaining(), then no bytes are transferred
+         * and a BufferUnderflowException is thrown.
+         * <p>
+         * Otherwise, this method copies length bytes from this buffer into the given
+         * array, starting at the current position of this buffer and at the given offset
+         * in the array. The position of this buffer is then incremented by length.
+         * <p>
+         * @param buffer - pointer to an allocated buffer to fill
+         * @param offset - position in the buffer to start filling
+         * @param length - amount of data to put in the passed buffer
+         * @returns a reference to this Buffer
+         * @throws BufferUnderflowException - If there are fewer than length bytes
+         * remaining in this buffer
+         * @throws NullPointerException if the passed buffer is null.
+         */
+        virtual ByteBuffer& get( unsigned char* buffer,
+                                 std::size_t offset,
+                                 std::size_t length )
+            throw( BufferUnderflowException,
+                   lang::exceptions::NullPointerException );
+
+        /**
+         * This method transfers the bytes remaining in the given source buffer into
+         * this buffer. If there are more bytes remaining in the source buffer than in
+         * this buffer, that is, if src.remaining() > remaining(), then no bytes are
+         * transferred and a BufferOverflowException is thrown.
+         * <p>
+         * Otherwise, this method copies n = src.remaining() bytes from the given
+         * buffer into this buffer, starting at each buffer's current position. The
+         * positions of both buffers are then incremented by n.
+         * @param src - the buffer to take bytes from an place in this one.
+         * @returns a reference to this buffer
+         * @throws BufferOverflowException - If there is insufficient space in this
+         * buffer for the remaining bytes in the source buffer
+         * @throws IllegalArgumentException - If the source buffer is this buffer
+         * @throws ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ByteBuffer& put( ByteBuffer& src )
+            throw( BufferOverflowException, ReadOnlyBufferException,
+                   lang::exceptions::IllegalArgumentException );
+
+        /**
+         * This method transfers bytes into this buffer from the given source array.
+         * If there are more bytes to be copied from the array than remain in this buffer,
+         * that is, if length > remaining(), then no bytes are transferred and a
+         * BufferOverflowException is thrown.
+         * <p>
+         * Otherwise, this method copies length bytes from the given array into this
+         * buffer, starting at the given offset in the array and at the current position
+         * of this buffer. The position of this buffer is then incremented by length.
+         * @param buffer - The array from which bytes are to be read
+         * @param offset - The offset within the array of the first byte to be read;
+         * @param length - The number of bytes to be read from the given array
+         * @returns a reference to this buffer
+         * @throws BufferOverflowException - If there is insufficient space in this buffer
+         * @throws ReadOnlyBufferException - If this buffer is read-only
+         * @throws NullPointerException if the passed buffer is null.
+         */
+        virtual ByteBuffer& put( const unsigned char* buffer,
+                                 std::size_t offset,
+                                 std::size_t length )
+            throw( BufferOverflowException, ReadOnlyBufferException,
+                   lang::exceptions::NullPointerException );
+
+        /**
+         * This method transfers the entire content of the given source byte array into
+         * this buffer.  This is the same as calling put( &buffer[0], 0, buffer.size()
+         * @pparam buffer - The buffer whose contents are copied to this ByteBuffer
+         * @returns a reference to this buffer
+         * @throws BufferOverflowException - If there is insufficient space in this buffer
+         * @throws ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ByteBuffer& put( std::vector<unsigned char>& buffer )
+            throw( BufferOverflowException, ReadOnlyBufferException );
+
+    public:   // Abstract Methods
+
+        /**
+         * Creates a view of this byte buffer as a char buffer.
+         * <p>
+         * 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.
+         * <p>
+         * 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 CharBuffer* asCharBuffer() const = 0;
+
+        /**
+         * Creates a view of this byte buffer as a double buffer.
+         * <p>
+         * 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.
+         * <p>
+         * 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 DoubleBuffer* asDoubleBuffer() const = 0;
+
+        /**
+         * Creates a view of this byte buffer as a float buffer.
+         * <p>
+         * 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.
+         * <p>
+         * 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 FloatBuffer* asFloatBuffer() const = 0;
+
+        /**
+         * Creates a view of this byte buffer as a int buffer.
+         * <p>
+         * 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.
+         * <p>
+         * 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 IntBuffer* asIntBuffer() const = 0;
+
+        /**
+         * Creates a view of this byte buffer as a long buffer.
+         * <p>
+         * 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.
+         * <p>
+         * 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 LongBuffer* asLongBuffer() const = 0;
+
+        /**
+         * Creates a view of this byte buffer as a short buffer.
+         * <p>
+         * 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.
+         * <p>
+         * 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 ShortBuffer* asShortBuffer() const = 0;
+
+        /**
+         * Creates a new, read-only byte buffer that shares this buffer's content.
+         * <p>
+         * 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.
+         * <p>
+         * If this buffer is itself read-only then this method behaves in exactly the
+         * same way as the duplicate method.
+         * <p>
+         * The new buffer's capacity, limit, position, and mark values will be
+         * identical to those of this buffer.
+         * @return The new, read-only byte buffer which the caller then owns.
+         */
+        virtual ByteBuffer* asReadOnlyBuffer() const = 0;
+
+        /**
+         * Compacts this buffer
+         * <p>
+         * 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.
+         * <p>
+         * 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
+         * @throws ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ByteBuffer& compact() throw( ReadOnlyBufferException ) = 0;
+
+        /**
+         * Creates a new byte buffer that shares this buffer's content.
+         * <p>
+         * 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.
+         * <p>
+         * 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 ByteBuffer* duplicate() = 0;
+
+        /**
+         * 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
+         * @throws BufferUnderflowException - If the buffer's current position is not
+         * smaller than its limit
+         */
+        virtual unsigned char get() throw( BufferUnderflowException ) = 0;
+
+        /**
+         * Writes the given byte into this buffer at the current position, and then
+         * increments the position.
+         * @param value - the byte value to be written
+         * @returns a reference to this buffer
+         * @throws BufferOverflowException - If this buffer's current position is not
+         * smaller than its limit
+         * @throws ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ByteBuffer& put( unsigned char value )
+            throw( BufferOverflowException, ReadOnlyBufferException ) = 0;
+
+        /**
+         * Absolute get method. Reads the byte at the given index.
+         * @param index - the index in the Buffer where the byte is to be read
+         * @returns the byte that is located at the given index
+         * @throws IndexOutOfBoundsException - If index is not smaller than the
+         * buffer's limit
+         */
+        virtual unsigned char get( std::size_t index )
+            throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
+
+        /**
+         * Reads the next byte at this buffer's current position, and then increments
+         * the position by one
+         * @returns the next char in the buffer..
+         * @throws BufferUnderflowException - If there are no more bytes remaining in
+         * this buffer, meaning we have reached the set limit.
+         */
+        virtual char getChar() throw( BufferUnderflowException ) = 0;
+
+        /**
+         * Reads one byte at the given index and returns it
+         * @param index - the index in the Buffer where the byte is to be read
+         * @returns the char at the given index in the buffer
+         * @throws IndexOutOfBoundsException - If index is not smaller than the
+         * buffer's limit
+         */
+        virtual char getChar( std::size_t index )
+            throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
+
+        /**
+         * 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..
+         * @throws BufferUnderflowException - If there are no more bytes remaining in
+         * this buffer, meaning we have reached the set limit.
+         */
+        virtual double getDouble() throw( BufferUnderflowException ) = 0;
+
+        /**
+         * Reads eight bytes at the given index and returns it
+         * @param index - the index in the Buffer where the bytes are to be read
+         * @returns the double at the given index in the buffer
+         * @throws IndexOutOfBoundsException - If there are not enough bytes
+         * remaining to fill the requested Data Type
+         */
+        virtual double getDouble( std::size_t index )
+            throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
+
+        /**
+         * 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..
+         * @throws BufferUnderflowException - If there are no more bytes remaining in
+         * this buffer, meaning we have reached the set limit.
+         */
+        virtual float getFloat() throw( BufferUnderflowException ) = 0;
+
+        /**
+         * Reads four bytes at the given index and returns it
+         * @param index - the index in the Buffer where the bytes are to be read
+         * @returns the float at the given index in the buffer
+         * @throws IndexOutOfBoundsException - If there are not enough bytes
+         * remaining to fill the requested Data Type
+         */
+        virtual float getFloat( std::size_t index )
+            throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
+
+        /**
+         * 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..
+         * @throws BufferUnderflowException - If there are no more bytes remaining in
+         * this buffer, meaning we have reached the set limit.
+         */
+        virtual long long getLong() throw( BufferUnderflowException ) = 0;
+
+        /**
+         * Reads eight bytes at the given index and returns it
+         * @param index - the index in the Buffer where the bytes are to be read
+         * @returns the long long at the given index in the buffer
+         * @throws IndexOutOfBoundsException - If there are not enough bytes
+         * remaining to fill the requested Data Type
+         */
+        virtual long long getLong( std::size_t index )
+            throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
+
+        /**
+         * 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..
+         * @throws BufferUnderflowException - If there are no more bytes remaining in
+         * this buffer, meaning we have reached the set limit.
+         */
+        virtual int getInt() throw( BufferUnderflowException ) = 0;
+
+        /**
+         * Reads four bytes at the given index and returns it
+         * @param index - the index in the Buffer where the bytes are to be read
+         * @returns the int at the given index in the buffer
+         * @throws IndexOutOfBoundsException - If there are not enough bytes
+         * remaining to fill the requested Data Type
+         */
+        virtual int getInt( std::size_t index )
+            throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
+
+        /**
+         * 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..
+         * @throws BufferUnderflowException - If there are no more bytes remaining in
+         * this buffer, meaning we have reached the set limit.
+         */
+        virtual short getShort() throw( BufferUnderflowException ) = 0;
+
+        /**
+         * Reads two bytes at the given index and returns it
+         * @param index - the index in the Buffer where the bytes are to be read
+         * @returns the short at the given index in the buffer
+         * @throws IndexOutOfBoundsException - If there are not enough bytes
+         * remaining to fill the requested Data Type
+         */
+        virtual short getShort( std::size_t index )
+            throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
+
+        /**
+         * Writes the given byte into this buffer at the given index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the byte to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         * @throw ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ByteBuffer& put( std::size_t index, unsigned char value )
+            throw( lang::exceptions::IndexOutOfBoundsException,
+                   ReadOnlyBufferException ) = 0;
+
+        /**
+         * Writes one byte containing the given value, into this buffer at the
+         * current position, and then increments the position by one.
+         * @param value - The value to be written
+         * @returns a reference to this buffer
+         * @throw BufferOverflowException - If there are fewer than bytes remaining
+         * in this buffer than the size of the data to be written
+         * @throw ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ByteBuffer& putChar( char value )
+            throw( BufferOverflowException, ReadOnlyBufferException ) = 0;
+
+        /**
+         * Writes one byte containing the given value, into this buffer at the
+         * given index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the value to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         * @throw ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ByteBuffer& putChar( std::size_t index, char value )
+            throw( lang::exceptions::IndexOutOfBoundsException,
+                   ReadOnlyBufferException ) = 0;
+
+        /**
+         * Writes eight bytes containing the given value, into this buffer at the
+         * current position, and then increments the position by eight.
+         * @param value - The value to be written
+         * @returns a reference to this buffer
+         * @throw BufferOverflowException - If there are fewer than bytes remaining
+         * in this buffer than the size of the data to be written
+         * @throw ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ByteBuffer& putDouble( double value )
+            throw( BufferOverflowException, ReadOnlyBufferException ) = 0;
+
+        /**
+         * Writes eight bytes containing the given value, into this buffer at the
+         * given index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the value to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         * @throw ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ByteBuffer& putDouble( std::size_t index, double value )
+            throw( lang::exceptions::IndexOutOfBoundsException,
+                   ReadOnlyBufferException ) = 0;
+
+        /**
+         * Writes four bytes containing the given value, into this buffer at the
+         * current position, and then increments the position by eight.
+         * @param value - The value to be written
+         * @returns a reference to this buffer
+         * @throw BufferOverflowException - If there are fewer than bytes remaining
+         * in this buffer than the size of the data to be written
+         * @throw ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ByteBuffer& putFloat( float value )
+            throw( BufferOverflowException, ReadOnlyBufferException ) = 0;
+
+        /**
+         * Writes four bytes containing the given value, into this buffer at the
+         * given index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the value to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         * @throw ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ByteBuffer& putFloat( std::size_t index, float value )
+            throw( lang::exceptions::IndexOutOfBoundsException,
+                   ReadOnlyBufferException ) = 0;
+
+        /**
+         * Writes eight bytes containing the given value, into this buffer at the
+         * current position, and then increments the position by eight.
+         * @param value - The value to be written
+         * @returns a reference to this buffer
+         * @throw BufferOverflowException - If there are fewer than bytes remaining
+         * in this buffer than the size of the data to be written
+         * @throw ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ByteBuffer& putLong( long long value )
+            throw( BufferOverflowException, ReadOnlyBufferException ) = 0;
+
+        /**
+         * Writes eight bytes containing the given value, into this buffer at the
+         * given index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the value to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         * @throw ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ByteBuffer& putLong( std::size_t index, long long value )
+            throw( lang::exceptions::IndexOutOfBoundsException,
+                   ReadOnlyBufferException ) = 0;
+
+        /**
+         * Writes four bytes containing the given value, into this buffer at the
+         * current position, and then increments the position by eight.
+         * @param value - The value to be written
+         * @returns a reference to this buffer
+         * @throw BufferOverflowException - If there are fewer than bytes remaining
+         * in this buffer than the size of the data to be written
+         * @throw ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ByteBuffer& putInt( int value )
+            throw( BufferOverflowException, ReadOnlyBufferException ) = 0;
+
+        /**
+         * Writes four bytes containing the given value, into this buffer at the
+         * given index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the value to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         * @throw ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ByteBuffer& putInt( std::size_t index, int value )
+            throw( lang::exceptions::IndexOutOfBoundsException,
+                   ReadOnlyBufferException ) = 0;
+
+        /**
+         * Writes two bytes containing the given value, into this buffer at the
+         * current position, and then increments the position by eight.
+         * @param value - The value to be written
+         * @returns a reference to this buffer
+         * @throw BufferOverflowException - If there are fewer than bytes remaining
+         * in this buffer than the size of the data to be written
+         * @throw ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ByteBuffer& putShort( short value )
+            throw( BufferOverflowException, ReadOnlyBufferException ) = 0;
+
+        /**
+         * Writes two bytes containing the given value, into this buffer at the
+         * given index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the value to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         * @throw ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ByteBuffer& putShort( std::size_t index, short value )
+            throw( lang::exceptions::IndexOutOfBoundsException,
+                   ReadOnlyBufferException ) = 0;
+
+        /**
+         * Creates a new byte buffer whose content is a shared subsequence of this
+         * <p>
+         * 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.
+         * <p>
+         * 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* slice() const = 0;
+
     public:
 
         /**
@@ -120,6 +730,35 @@
         static ByteBuffer* allocate( std::size_t capacity )
             throw( lang::exceptions::IllegalArgumentException );
 
+        /**
+         * Wraps the passed buffer with a new ByteBuffer.
+         * <p>
+         * The new buffer will be backed by the given byte array; that is, modifications
+         * to the buffer will cause the array to be modified and vice versa. The new
+         * buffer's capacity will be array.length, its position will be offset, its limit
+         * will be offset + length, and its mark will be undefined. Its backing array
+         * will be the given array, and its array offset will be zero.
+         * @param buffer - The array that will back the new buffer
+         * @param offset - The offset of the subarray to be used
+         * @param length - The length of the subarray to be used
+         * @returns a new ByteBuffer that is backed by buffer, caller owns.
+         */
+        static ByteBuffer* wrap( unsigned char* array, int offset, int length )
+            throw( lang::exceptions::NullPointerException );
+
+        /**
+         * Wraps the passed STL Byte Vector in a ByteBuffer.
+         * <p>
+         * The new buffer will be backed by the given byte array; modifications to the
+         * buffer will cause the array to be modified and vice versa. The new buffer's
+         * capacity and limit will be buffer.size(), its position will be zero, and its
+         * mark will be undefined. Its backing array will be the given array, and its
+         * array offset will be zero.
+         * @param buffer - The vector that will back the new buffer, the vector must
+         * have been sized to the desired size already by calling vector.resize( N ).
+         * @returns a new ByteBuffer that is backed by buffer, caller owns.
+         */
+        static ByteBuffer* wrap( std::vector<unsigned char>& buffer );
 
     };
 



Mime
View raw message