activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r925692 [4/14] - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/ main/activemq/commands/ main/activemq/io/ main/activemq/wireformat/openwire/ main/activemq/wireformat/openwire/marshal/ main/decaf/internal/io/ main/decaf/internal/nio...
Date Sat, 20 Mar 2010 21:57:24 GMT
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/ShortArrayBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/ShortArrayBuffer.h?rev=925692&r1=925691&r2=925692&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/ShortArrayBuffer.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/ShortArrayBuffer.h
Sat Mar 20 21:57:20 2010
@@ -24,12 +24,16 @@
 #include <decaf/nio/BufferUnderflowException.h>
 #include <decaf/nio/BufferOverflowException.h>
 #include <decaf/nio/ReadOnlyBufferException.h>
-#include <decaf/internal/nio/ByteArrayPerspective.h>
+#include <decaf/internal/util/ByteArrayAdapter.h>
+
+#include <decaf/lang/Pointer.h>
 
 namespace decaf{
 namespace internal{
 namespace nio{
 
+    using decaf::internal::util::ByteArrayAdapter;
+
     class DECAF_API ShortArrayBuffer : public decaf::nio::ShortBuffer{
     private:
 
@@ -37,10 +41,13 @@ namespace nio{
         bool readOnly;
 
         // The reference array object that backs this buffer.
-        internal::nio::ByteArrayPerspective* _array;
+        decaf::lang::Pointer<ByteArrayAdapter> _array;
 
         // Offset into the array that we are to start from
-        std::size_t offset;
+        int offset;
+
+        // The length of the sub-array, or limit
+        int length;
 
     public:
 
@@ -48,44 +55,68 @@ namespace nio{
          * Creates a ShortArrayBuffer object that has its backing array allocated internally
          * and is then owned and deleted when this object is deleted.  The array is
          * initially created with all elements initialized to zero.
-         * @param capacity - size of the array, this is the limit we read and write to.
-         * @param readOnly - should this buffer be read-only, default as false
+         *
+         * @param size
+         *      The size of the array, this is the limit we read and write to.
+         * @param readOnly
+         *      Boolean indicating if this buffer should be read-only, default as false.
+         *
+         * @throws IllegalArguementException if the capacity value is negative.
          */
-        ShortArrayBuffer( std::size_t capacity, bool readOnly = false );
+        ShortArrayBuffer( int size, bool readOnly = false )
+            throw( decaf::lang::exceptions::IllegalArgumentException );
 
         /**
          * Creates a ShortArrayBuffer object that wraps the given array.  If the own flag
          * is set then it will delete this array when this object is deleted.
-         * @param array - array to wrap
-         * @param offset - the position that is this buffers start pos.
-         * @param capacity - size of the array, this is the limit we read and write to.
-         * @param readOnly - should this buffer be read-only, default as false
+         *
+         * @param array
+         *      The actual array to wrap.
+         * @param size
+         *      The size of the given array.
+         * @param offset
+         *      The position that is this buffers start position.
+         * @param length
+         *      The limit of how many bytes into the array this Buffer can write.
+         * @param readOnly
+         *      Boolean indicating if this buffer should be read-only, default as false.
+         *
          * @throws NullPointerException if buffer is NULL
+         * @throws IndexOutOfBoundsException if offset is greater than array capacity.
          */
-        ShortArrayBuffer( short* array, std::size_t offset,
-                          std::size_t capacity, bool readOnly = false )
-            throw( decaf::lang::exceptions::NullPointerException );
+        ShortArrayBuffer( short* array, int size, int offset, int length, bool readOnly =
false )
+            throw( decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException );
 
         /**
-         * Creates a byte buffer that wraps the passed ByteArrayPerspective and
+         * Creates a byte buffer that wraps the passed ByteArrayAdapter and
          * start at the given offset.  The capacity and limit of the new ShortArrayBuffer
          * will be that of the remaining capacity of the passed buffer.
-         * @param array - the ByteArrayPerspective to wrap
-         * @param offset - the position that is this buffers start pos.
-         * @param capacity - the length of the array we are wrapping or limit.
-         * @param readOnly - is this a readOnly buffer.
-         * @throws IndexOutOfBoundsException if offset is greater than array capacity.
+         *
+         * @param array
+         *      The ByteArrayAdapter to wrap.
+         * @param offset
+         *      The position that is this buffers start position.
+         * @param length
+         *      The limit of how many bytes into the array this Buffer can write.
+         * @param readOnly
+         *      Boolean indicating if this buffer should be read-only, default as false.
+         *
+         * @throws NullPointerException if array is NULL
+         * @throws IndexOutOfBoundsException if offset + length is greater than array size.
          */
-        ShortArrayBuffer( ByteArrayPerspective& array,
-                          std::size_t offset, std::size_t capacity,
+        ShortArrayBuffer( const decaf::lang::Pointer<ByteArrayAdapter>& array,
int offset, int length,
                           bool readOnly = false )
-            throw( decaf::lang::exceptions::IndexOutOfBoundsException );
+            throw( decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException );
 
         /**
          * Create a ShortArrayBuffer that mirrors this one, meaning it shares a
-         * reference to this buffers ByteArrayPerspective and when changes
+         * reference to this buffers ByteArrayAdapter and when changes
          * are made to that data it is reflected in both.
-         * @param other - the ShortArrayBuffer this one is to mirror.
+         *
+         * @param other
+         *      The ShortArrayBuffer this one is to mirror.
          */
         ShortArrayBuffer( const ShortArrayBuffer& other );
 
@@ -94,166 +125,83 @@ namespace nio{
     public:
 
         /**
-         * Returns the short array that backs this buffer  (optional operation).
-         * <p>
-         * Modifications to this buffer's content will cause the returned array's content
-         * to be modified, and vice versa.
-         * <p>
-         * 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
-         * @throws ReadOnlyBufferException if this Buffer is read only.
-         * @throws UnsupportedOperationException if the underlying store has no array.
+         * {@inheritDoc}
          */
         virtual short* array()
             throw( decaf::lang::exceptions::UnsupportedOperationException,
                    decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Returns the offset within this buffer's backing array of the first element of
-         * the buffer  (optional operation).
-         * <p>
-         * Invoke the hasArray method before invoking this method in order to ensure that
-         * this buffer has an accessible backing array.
-         * @returns The offset into the backing array where index zero starts.
-         * @throws ReadOnlyBufferException if this Buffer is read only.
-         * @throws UnsupportedOperationException if the underlying store has no array.
+         * {@inheritDoc}
          */
-        virtual std::size_t arrayOffset()
+        virtual int arrayOffset()
             throw( decaf::lang::exceptions::UnsupportedOperationException,
                    decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Creates a new, read-only short 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 short buffer which the caller then owns.
+         * {@inheritDoc}
          */
         virtual ShortBuffer* asReadOnlyBuffer() const;
 
         /**
-         * 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 ShortBuffer
-         * @throws ReadOnlyBufferException - If this buffer is read-only
+         * {@inheritDoc}
          */
         virtual ShortBuffer& compact() throw( decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Creates a new short 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 short Buffer which the caller owns.
+         * {@inheritDoc}
          */
         virtual ShortBuffer* duplicate();
 
         /**
-         * Relative get method. Reads the value at this buffer's current position,
-         * and then increments the position.
-         * @returns the short at the current position
-         * @throws BufferUnderflowException if there no more data to return
+         * {@inheritDoc}
          */
         virtual short get() throw ( decaf::nio::BufferUnderflowException );
 
         /**
-         * Absolute get method. Reads the value at the given index.
-         * @param index - the index in the Buffer where the short is to be read
-         * @returns the short that is located at the given index
-         * @throws IndexOutOfBoundsException - If index is not smaller than the
-         * buffer's limit
+         * {@inheritDoc}
          */
-        virtual short get( std::size_t index ) const
+        virtual short get( int index ) const
             throw ( lang::exceptions::IndexOutOfBoundsException );
 
         /**
-         * Tells whether or not this buffer is backed by an accessible short 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
+         * {@inheritDoc}
          */
         virtual bool hasArray() const { return true; }
 
         /**
-         * Tells whether or not this buffer is read-only.
-         * @returns true if, and only if, this buffer is read-only
+         * {@inheritDoc}
          */
         virtual bool isReadOnly() const {
             return this->readOnly;
         }
 
         /**
-         * Writes the given doubles into this buffer at the current position, and then
-         * increments the position.
-         * @param value - the doubles 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
+         * {@inheritDoc}
          */
         virtual ShortBuffer& put( short value )
             throw( decaf::nio::BufferOverflowException,
                    decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Writes the given doubles into this buffer at the given index.
-         * @param index - position in the Buffer to write the data
-         * @param value - the doubles to write.
-         * @returns a reference to this buffer
-         * @throws IndexOutOfBoundsException - If index greater than the buffer's limit
-         * minus the size of the type being written.
-         * @throws ReadOnlyBufferException - If this buffer is read-only
+         * {@inheritDoc}
          */
-        virtual ShortBuffer& put( std::size_t index, short value )
+        virtual ShortBuffer& put( int index, short value )
             throw( lang::exceptions::IndexOutOfBoundsException,
                    decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Creates a new ShortBuffer 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.
-         * <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 ShortBuffer which the caller owns.
+         * {@inheritDoc}
          */
         virtual ShortBuffer* slice() const;
 
     protected:
 
         /**
-         * Sets this ByteArrayBuffer as Read-Only.
-         * @param value - true if this buffer is to be read-only.
+         * Sets this ShortArrayBuffer as Read-Only.
+         *
+         * @param value
+         *      Boolean value, true if this buffer is to be read-only, false otherwise.
          */
         virtual void setReadOnly( bool value ) {
             this->readOnly = value;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ByteArrayAdapter.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ByteArrayAdapter.cpp?rev=925692&r1=925691&r2=925692&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ByteArrayAdapter.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ByteArrayAdapter.cpp
Sat Mar 20 21:57:20 2010
@@ -31,102 +31,122 @@ using namespace decaf::lang;
 using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter::ByteArrayAdapter( std::size_t capacity ) {
+ByteArrayAdapter::ByteArrayAdapter( int size )
+    throw( decaf::lang::exceptions::IllegalArgumentException ) {
 
     try{
 
-        this->array.bytes = new unsigned char[capacity];
-        memset( this->array.bytes, 0, capacity );
-        this->initialize( array.bytes, capacity, true );
+        if( size < 0 ) {
+            throw IndexOutOfBoundsException(
+                 __FILE__, __LINE__, "Array size given must be greater than zero." );
+        }
+
+        this->array.bytes = new unsigned char[size];
+        memset( this->array.bytes, 0, size );
+        this->initialize( array.bytes, size, true );
     }
     DECAF_CATCH_RETHROW( Exception )
     DECAF_CATCHALL_THROW( Exception )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter::ByteArrayAdapter( unsigned char* array, std::size_t capacity, bool own
)
-    throw( lang::exceptions::NullPointerException ) {
+ByteArrayAdapter::ByteArrayAdapter( unsigned char* array, int size, bool own )
+    throw( decaf::lang::exceptions::NullPointerException,
+           decaf::lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
-        this->initialize( array, capacity, own );
+        this->initialize( array, size, own );
     }
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCHALL_THROW( NullPointerException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter::ByteArrayAdapter( char* array, std::size_t capacity, bool own )
-    throw( lang::exceptions::NullPointerException ) {
+ByteArrayAdapter::ByteArrayAdapter( char* array, int size, bool own )
+    throw( decaf::lang::exceptions::NullPointerException,
+           decaf::lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
-        this->initialize( reinterpret_cast<unsigned char*>( array ), capacity, own
);
+        this->initialize( reinterpret_cast<unsigned char*>( array ), size, own );
     }
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCHALL_THROW( NullPointerException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter::ByteArrayAdapter( double* array, std::size_t capacity, bool own )
-    throw( lang::exceptions::NullPointerException ) {
+ByteArrayAdapter::ByteArrayAdapter( double* array, int size, bool own )
+    throw( decaf::lang::exceptions::NullPointerException,
+           decaf::lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
         this->initialize( reinterpret_cast<unsigned char*>( array ),
-                          capacity * sizeof( double ), own );
+                          size * sizeof( double ), own );
     }
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCHALL_THROW( NullPointerException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter::ByteArrayAdapter( float* array, std::size_t capacity, bool own )
-    throw( lang::exceptions::NullPointerException ) {
+ByteArrayAdapter::ByteArrayAdapter( float* array, int size, bool own )
+    throw( decaf::lang::exceptions::NullPointerException,
+           decaf::lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
         this->initialize( reinterpret_cast<unsigned char*>( array ),
-                          capacity * sizeof( float ), own );
+                          size * sizeof( float ), own );
     }
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCHALL_THROW( NullPointerException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter::ByteArrayAdapter( long long* array, std::size_t capacity, bool own )
-    throw( lang::exceptions::NullPointerException ) {
+ByteArrayAdapter::ByteArrayAdapter( long long* array, int size, bool own )
+    throw( decaf::lang::exceptions::NullPointerException,
+           decaf::lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
         this->initialize( reinterpret_cast<unsigned char*>( array ),
-                          capacity * sizeof( long long ), own );
+                          size * sizeof( long long ), own );
     }
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCHALL_THROW( NullPointerException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter::ByteArrayAdapter( int* array, std::size_t capacity, bool own )
-    throw( lang::exceptions::NullPointerException ) {
+ByteArrayAdapter::ByteArrayAdapter( int* array, int size, bool own )
+    throw( decaf::lang::exceptions::NullPointerException,
+           decaf::lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
         this->initialize( reinterpret_cast<unsigned char*>( array ),
-                          capacity * sizeof( int ), own );
+                          size * sizeof( int ), own );
     }
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCHALL_THROW( NullPointerException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter::ByteArrayAdapter( short* array, std::size_t capacity, bool own )
-    throw( lang::exceptions::NullPointerException ) {
+ByteArrayAdapter::ByteArrayAdapter( short* array, int size, bool own )
+    throw( decaf::lang::exceptions::NullPointerException,
+           decaf::lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
         this->initialize( reinterpret_cast<unsigned char*>( array ),
-                          capacity * sizeof( short ), own );
+                          size * sizeof( short ), own );
     }
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCHALL_THROW( NullPointerException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ByteArrayAdapter::initialize( unsigned char* array, std::size_t capacity, bool own )
{
+void ByteArrayAdapter::initialize( unsigned char* array, int size, bool own ) {
 
     try{
 
@@ -136,8 +156,13 @@ void ByteArrayAdapter::initialize( unsig
                 "ByteArrayAdapter::initialize - Passed Buffer is null" );
         }
 
+        if( size < 0 ) {
+            throw IndexOutOfBoundsException(
+                 __FILE__, __LINE__, "Array size given must be greater than zero." );
+        }
+
         this->array.bytes = array;
-        this->capacity = capacity;
+        this->size = size;
         this->own = own;
     }
     DECAF_CATCH_RETHROW( Exception )
@@ -158,8 +183,8 @@ ByteArrayAdapter::~ByteArrayAdapter() {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ByteArrayAdapter::read( unsigned char* buffer, std::size_t offset, std::size_t length
) const
-    throw( NullPointerException, BufferUnderflowException ) {
+void ByteArrayAdapter::read( unsigned char* buffer, int size, int offset, int length ) const
+    throw( IndexOutOfBoundsException, NullPointerException, BufferUnderflowException ) {
 
     try{
 
@@ -173,24 +198,39 @@ void ByteArrayAdapter::read( unsigned ch
                 "ByteArrayAdapter::write - Passed buffer is null" );
         }
 
-        if( ( offset + length ) > this->capacity ) {
+        if( size < 0 ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "size parameter out of Bounds: %d.", size );
+        }
+
+        if( offset < 0 ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "offset parameter out of Bounds: %d.", offset );
+        }
+
+        if( length < 0 || length > size ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "length parameter out of Bounds: %d.", length );
+        }
+
+        if( ( offset + length ) > this->size ) {
             throw BufferUnderflowException(
-                __FILE__, __LINE__,
-                "ByteArrayAdapter::read - Not enough data to fill request." );
+                __FILE__, __LINE__, "Not enough data to fill request." );
         }
 
         // Read, starting at offset, length number of bytes to Buffer
         memcpy( buffer, this->array.bytes + offset, length );
     }
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCH_RETHROW( BufferUnderflowException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
     DECAF_CATCHALL_THROW( BufferUnderflowException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ByteArrayAdapter::write( unsigned char* buffer, std::size_t offset, std::size_t length
)
-    throw( NullPointerException, BufferOverflowException ) {
+void ByteArrayAdapter::write( unsigned char* buffer, int size, int offset, int length )
+    throw( IndexOutOfBoundsException, NullPointerException, BufferOverflowException ) {
 
     try{
 
@@ -204,7 +244,22 @@ void ByteArrayAdapter::write( unsigned c
                 "ByteArrayAdapter::write - Passed buffer is null" );
         }
 
-        if( ( offset + length ) > this->capacity ) {
+        if( size < 0 ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "size parameter out of Bounds: %d.", size );
+        }
+
+        if( offset < 0 ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "offset parameter out of Bounds: %d.", offset );
+        }
+
+        if( length < 0 || length > size ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "length parameter out of Bounds: %d.", length );
+        }
+
+        if( ( offset + length ) > this->size ) {
             throw BufferOverflowException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::read - Not room in array to hold request." );
@@ -214,14 +269,15 @@ void ByteArrayAdapter::write( unsigned c
         memcpy( this->array.bytes + offset, buffer, length );
     }
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCH_RETHROW( BufferOverflowException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )
     DECAF_CATCHALL_THROW( BufferOverflowException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ByteArrayAdapter::resize( std::size_t capacity )
-    throw ( lang::exceptions::InvalidStateException ) {
+void ByteArrayAdapter::resize( int size )
+    throw ( IllegalArgumentException, InvalidStateException ) {
 
     try{
 
@@ -231,14 +287,19 @@ void ByteArrayAdapter::resize( std::size
                 "ByteArrayAdapter::resize - Not the array owner, can't resize" );
         }
 
+        if( size < 0 ) {
+            throw IllegalArgumentException(
+                __FILE__, __LINE__, "size parameter out of Bounds: %d.", size );
+        }
+
         // Save old state
-        std::size_t oldCapacity = this->capacity;
+        int oldCapacity = this->size;
         unsigned char* oldArray = this->array.bytes;
 
         // Resize and copy as much of the old as we can back and delete old array
-        this->array.bytes = new unsigned char[capacity];
-        this->capacity = capacity;
-        memcpy( this->array.bytes, oldArray, Math::min( (int)oldCapacity, (int)capacity
) );
+        this->array.bytes = new unsigned char[size];
+        this->size = size;
+        memcpy( this->array.bytes, oldArray, Math::min( (int)oldCapacity, (int)size )
);
         delete [] oldArray;
     }
     DECAF_CATCH_RETHROW( InvalidStateException )
@@ -246,20 +307,19 @@ void ByteArrayAdapter::resize( std::size
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ByteArrayAdapter::clear() {
-    memset( this->array.bytes, 0, this->capacity );
+void ByteArrayAdapter::clear() throw() {
+    memset( this->array.bytes, 0, this->size );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-unsigned char& ByteArrayAdapter::operator[]( std::size_t index )
+unsigned char& ByteArrayAdapter::operator[]( int index )
     throw ( IndexOutOfBoundsException ) {
 
     try{
 
-        if( index > this->capacity ) {
+        if( index < 0 || index > this->size ) {
             throw IndexOutOfBoundsException(
-                __FILE__, __LINE__,
-                "ByteArrayAdapter::operator[] - Index %d is out of bounds", index );
+                __FILE__, __LINE__, "Index %d is out of bounds", index );
         }
 
         return this->array.bytes[index];
@@ -269,15 +329,14 @@ unsigned char& ByteArrayAdapter::operato
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-const unsigned char& ByteArrayAdapter::operator[]( std::size_t index ) const
+const unsigned char& ByteArrayAdapter::operator[]( int index ) const
     throw ( decaf::lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
 
-        if( index > this->capacity ) {
+        if( index < 0 || index > this->size ) {
             throw IndexOutOfBoundsException(
-                __FILE__, __LINE__,
-                "ByteArrayAdapter::operator[] - Index %d is out of bounds", index );
+                __FILE__, __LINE__, "Index %d is out of bounds", index );
         }
 
         return this->array.bytes[index];
@@ -287,12 +346,12 @@ const unsigned char& ByteArrayAdapter::o
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-unsigned char ByteArrayAdapter::get( std::size_t index ) const
+unsigned char ByteArrayAdapter::get( int index ) const
     throw ( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
 
-        if( index >= this->getCapacity() ) {
+        if( index < 0 || index >= this->getCapacity() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::get - Not enough data to fill request." );
@@ -306,12 +365,24 @@ unsigned char ByteArrayAdapter::get( std
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-double ByteArrayAdapter::getDouble( std::size_t index ) const
+char ByteArrayAdapter::getChar( int index ) const
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+        return (char)this->get( index );
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+double ByteArrayAdapter::getDouble( int index ) const
     throw ( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
 
-        if( index >= this->getDoubleCapacity() ) {
+        if( index < 0 || index >= this->getDoubleCapacity() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::getDouble(i) - Not enough data to fill a long long." );
@@ -325,7 +396,7 @@ double ByteArrayAdapter::getDouble( std:
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-double ByteArrayAdapter::getDoubleAt( std::size_t index ) const
+double ByteArrayAdapter::getDoubleAt( int index ) const
     throw ( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
@@ -339,12 +410,12 @@ double ByteArrayAdapter::getDoubleAt( st
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-float ByteArrayAdapter::getFloat( std::size_t index ) const
+float ByteArrayAdapter::getFloat( int index ) const
     throw ( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
 
-        if( index >= this->getFloatCapacity() ) {
+        if( index < 0 || index >= this->getFloatCapacity() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::getFloat(i) - Not enough data to fill a long long." );
@@ -358,7 +429,7 @@ float ByteArrayAdapter::getFloat( std::s
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-float ByteArrayAdapter::getFloatAt( std::size_t index ) const
+float ByteArrayAdapter::getFloatAt( int index ) const
     throw ( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
@@ -372,12 +443,12 @@ float ByteArrayAdapter::getFloatAt( std:
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-long long ByteArrayAdapter::getLong( std::size_t index ) const
+long long ByteArrayAdapter::getLong( int index ) const
     throw ( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
 
-        if( index >= this->getLongCapacity() ) {
+        if( index < 0 || index >= this->getLongCapacity() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::getLong(i) - Not enough data to fill a long long." );
@@ -391,12 +462,12 @@ long long ByteArrayAdapter::getLong( std
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-long long ByteArrayAdapter::getLongAt( std::size_t index ) const
+long long ByteArrayAdapter::getLongAt( int index ) const
     throw ( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
 
-        if( ( index + sizeof( long long ) ) > this->getCapacity() ) {
+        if( ( index < 0 || index + sizeof( long long ) ) > this->getCapacity() )
{
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::getLong(i) - Not enough data to fill a long long." );
@@ -404,7 +475,7 @@ long long ByteArrayAdapter::getLongAt( s
 
         unsigned long long value = 0;
         unsigned char buffer[sizeof(value)] = {0};
-        this->read( buffer, index, sizeof(value) );
+        this->read( buffer, sizeof(value), index, sizeof(value) );
 
         // Have to do it this way because on Solaris and Cygwin we get all
         // kinds of warnings when shifting a byte up into a long long.
@@ -428,12 +499,12 @@ long long ByteArrayAdapter::getLongAt( s
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int ByteArrayAdapter::getInt( std::size_t index ) const
+int ByteArrayAdapter::getInt( int index ) const
     throw ( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
 
-        if( index >= this->getIntCapacity() ) {
+        if( index < 0 || index >= this->getIntCapacity() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::getInt(i) - Not enough data to fill an int." );
@@ -447,12 +518,12 @@ int ByteArrayAdapter::getInt( std::size_
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int ByteArrayAdapter::getIntAt( std::size_t index ) const
+int ByteArrayAdapter::getIntAt( int index ) const
     throw ( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
 
-        if( ( index + sizeof( int ) ) > this->getCapacity() ) {
+        if( index < 0 || ( index + (int)sizeof(int) ) > this->getCapacity() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::getInt(i) - Not enough data to fill an int." );
@@ -460,7 +531,7 @@ int ByteArrayAdapter::getIntAt( std::siz
 
         unsigned int value = 0;
         unsigned char buffer[sizeof(value)] = {0};
-        this->read( buffer, index, sizeof(value) );
+        this->read( buffer, sizeof(value), index, sizeof(value) );
         value |= (buffer[0] << 24 | buffer[1] << 16 |
                   buffer[2] << 8 | buffer[3] << 0);
 
@@ -472,12 +543,12 @@ int ByteArrayAdapter::getIntAt( std::siz
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-short ByteArrayAdapter::getShort( std::size_t index ) const
+short ByteArrayAdapter::getShort( int index ) const
     throw ( lang::exceptions::IndexOutOfBoundsException )  {
 
     try{
 
-        if( index >= this->getShortCapacity() ) {
+        if( index < 0 || index >= this->getShortCapacity() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::getShort(i) - Not enough data to fill a short." );
@@ -491,12 +562,12 @@ short ByteArrayAdapter::getShort( std::s
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-short ByteArrayAdapter::getShortAt( std::size_t index ) const
+short ByteArrayAdapter::getShortAt( int index ) const
     throw ( lang::exceptions::IndexOutOfBoundsException )  {
 
     try{
 
-        if( ( index + sizeof( short ) ) > this->getCapacity() ) {
+        if( index < 0 || ( index + (int)sizeof(short) ) > this->getCapacity() )
{
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::getShort(i) - Not enough data to fill a short." );
@@ -504,7 +575,7 @@ short ByteArrayAdapter::getShortAt( std:
 
         short value = 0;
         unsigned char buffer[sizeof(value)] = {0};
-        this->read( buffer, index, sizeof(value) );
+        this->read( buffer, sizeof(value), index, sizeof(value) );
         value |= (short)(buffer[0] << 8 | buffer[1] << 0);
 
         return value;
@@ -515,12 +586,12 @@ short ByteArrayAdapter::getShortAt( std:
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter& ByteArrayAdapter::put( std::size_t index, unsigned char value )
+ByteArrayAdapter& ByteArrayAdapter::put( int index, unsigned char value )
     throw( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
 
-        if( index >= this->getCapacity() ) {
+        if( index < 0 || index >= this->getCapacity() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::put(i,i) - Not enough data to fill request." );
@@ -536,7 +607,7 @@ ByteArrayAdapter& ByteArrayAdapter::put(
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter& ByteArrayAdapter::putChar( std::size_t index, char value )
+ByteArrayAdapter& ByteArrayAdapter::putChar( int index, char value )
     throw( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
@@ -550,12 +621,12 @@ ByteArrayAdapter& ByteArrayAdapter::putC
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter& ByteArrayAdapter::putDouble( std::size_t index, double value )
+ByteArrayAdapter& ByteArrayAdapter::putDouble( int index, double value )
     throw( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
 
-        if( index >= this->getDoubleCapacity() ) {
+        if( index < 0 || index >= this->getDoubleCapacity() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::putDouble(i,i) - Not enough data to fill request." );
@@ -570,7 +641,7 @@ ByteArrayAdapter& ByteArrayAdapter::putD
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter& ByteArrayAdapter::putDoubleAt( std::size_t index, double value )
+ByteArrayAdapter& ByteArrayAdapter::putDoubleAt( int index, double value )
     throw( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
@@ -584,12 +655,12 @@ ByteArrayAdapter& ByteArrayAdapter::putD
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter& ByteArrayAdapter::putFloat( std::size_t index, float value )
+ByteArrayAdapter& ByteArrayAdapter::putFloat( int index, float value )
     throw( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
 
-        if( index >= this->getFloatCapacity() ) {
+        if( index < 0 || index >= this->getFloatCapacity() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::putFloat(i,i) - Not enough data to fill request." );
@@ -604,7 +675,7 @@ ByteArrayAdapter& ByteArrayAdapter::putF
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter& ByteArrayAdapter::putFloatAt( std::size_t index, float value )
+ByteArrayAdapter& ByteArrayAdapter::putFloatAt( int index, float value )
     throw( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
@@ -618,12 +689,12 @@ ByteArrayAdapter& ByteArrayAdapter::putF
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter& ByteArrayAdapter::putLong( std::size_t index, long long value )
+ByteArrayAdapter& ByteArrayAdapter::putLong( int index, long long value )
     throw( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
 
-        if( index >= this->getLongCapacity() ) {
+        if( index < 0 || index >= this->getLongCapacity() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::putLong(i,i) - Not enough data to fill request." );
@@ -638,7 +709,7 @@ ByteArrayAdapter& ByteArrayAdapter::putL
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter& ByteArrayAdapter::putLongAt( std::size_t index, long long value )
+ByteArrayAdapter& ByteArrayAdapter::putLongAt( int index, long long value )
     throw( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
@@ -654,7 +725,7 @@ ByteArrayAdapter& ByteArrayAdapter::putL
         buffer[6] = (unsigned char)((value & 0x000000000000FF00ULL) >> 8);
         buffer[7] = (unsigned char)((value & 0x00000000000000FFULL) >> 0);
 
-        this->write( buffer, index, sizeof(value) );
+        this->write( buffer, sizeof(value), index, sizeof(value) );
 
         return *this;
     }
@@ -664,12 +735,12 @@ ByteArrayAdapter& ByteArrayAdapter::putL
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter& ByteArrayAdapter::putInt( std::size_t index, int value )
+ByteArrayAdapter& ByteArrayAdapter::putInt( int index, int value )
     throw( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
 
-        if( index >= this->getIntCapacity() ) {
+        if( index < 0 || index >= this->getIntCapacity() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::putInt(i,i) - Not enough data to fill request." );
@@ -684,7 +755,7 @@ ByteArrayAdapter& ByteArrayAdapter::putI
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter& ByteArrayAdapter::putIntAt( std::size_t index, int value )
+ByteArrayAdapter& ByteArrayAdapter::putIntAt( int index, int value )
     throw( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
@@ -696,7 +767,7 @@ ByteArrayAdapter& ByteArrayAdapter::putI
         buffer[2] = (unsigned char)((value & 0x0000FF00) >> 8);
         buffer[3] = (unsigned char)((value & 0x000000FF) >> 0);
 
-        this->write( buffer, index, sizeof(value) );
+        this->write( buffer, sizeof(value), index, sizeof(value) );
 
         return *this;
     }
@@ -706,12 +777,12 @@ ByteArrayAdapter& ByteArrayAdapter::putI
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter& ByteArrayAdapter::putShort( std::size_t index, short value )
+ByteArrayAdapter& ByteArrayAdapter::putShort( int index, short value )
     throw( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
 
-        if( index >= this->getShortCapacity() ) {
+        if( index < 0 || index >= this->getShortCapacity() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::putShort(i,i) - Not enough data to fill request." );
@@ -726,7 +797,7 @@ ByteArrayAdapter& ByteArrayAdapter::putS
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayAdapter& ByteArrayAdapter::putShortAt( std::size_t index, short value )
+ByteArrayAdapter& ByteArrayAdapter::putShortAt( int index, short value )
     throw( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
@@ -736,7 +807,7 @@ ByteArrayAdapter& ByteArrayAdapter::putS
         buffer[0] = (unsigned char)((value & 0xFF00) >> 8);
         buffer[1] = (unsigned char)((value & 0x00FF) >> 0);
 
-        this->write( buffer, index, sizeof(value) );
+        this->write( buffer, sizeof(value), index, sizeof(value) );
 
         return *this;
     }



Mime
View raw message