You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2010/03/20 22:57:24 UTC
svn commit: r925692 [5/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...
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ByteArrayAdapter.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ByteArrayAdapter.h?rev=925692&r1=925691&r2=925692&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ByteArrayAdapter.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/ByteArrayAdapter.h Sat Mar 20 21:57:20 2010
@@ -19,6 +19,7 @@
#define _DECAF_INTERNAL_UTIL_BYTEARRAYADAPTER_H_
#include <decaf/lang/exceptions/InvalidStateException.h>
+#include <decaf/lang/exceptions/IllegalArgumentException.h>
#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
#include <decaf/lang/exceptions/NullPointerException.h>
#include <decaf/nio/BufferUnderflowException.h>
@@ -33,9 +34,11 @@ namespace util{
* classes can inter-operate on the same base byte array without copying data.
* All the array types are mapped down to a byte array and methods are
* supplied for accessing the data in any of the primitive type forms.
- * <p>
+ *
* Methods in this class that do not return a specific value return a
* reference to this object so that calls can be chained.
+ *
+ * @since 1.0
*/
class DECAF_API ByteArrayAdapter {
private:
@@ -56,7 +59,7 @@ namespace util{
Array array;
// Size of the Buffer
- std::size_t capacity;
+ int size;
// Whether this object owns the buffer
bool own;
@@ -67,143 +70,196 @@ namespace util{
* Creates a byte array object that is 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 size
+ * The size of the array, this is the limit we read and write to.
+ *
+ * @throws IllegalArgumentException if size is negative.
*/
- ByteArrayAdapter( std::size_t capacity );
+ ByteArrayAdapter( int size ) throw( decaf::lang::exceptions::IllegalArgumentException );
/**
* Creates a byte array 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 capacity - size of the array, this is the limit we read and write to.
- * @param own - is this class now the owner of the pointer.
+ *
+ * @param array
+ * The physical array to wrap.
+ * @param size
+ * The size of the array, this is the limit we read and write to.
+ * @param own
+ * Indicates if this class is now the owner of the pointer.
+ *
* @throws NullPointerException if buffer is NULL
+ * @throws IndexOutOfBoundsException if the size is negative.
*/
- ByteArrayAdapter( unsigned char* array, std::size_t capacity, bool own = false )
- throw( lang::exceptions::NullPointerException );
+ ByteArrayAdapter( unsigned char* array, int size, bool own = false )
+ throw( decaf::lang::exceptions::NullPointerException,
+ decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Creates a byte array 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 capacity - size of the array, this is the limit we read and write to.
- * @param own - is this class now the owner of the pointer.
+ *
+ * @param array
+ * The physical array to wrap.
+ * @param size
+ * The size of the array, this is the limit we read and write to.
+ * @param own
+ * Indicates if this class is now the owner of the pointer.
+ *
* @throws NullPointerException if buffer is NULL
+ * @throws IndexOutOfBoundsException if the size is negative.
*/
- ByteArrayAdapter( char* array, std::size_t capacity, bool own = false )
- throw( lang::exceptions::NullPointerException );
+ ByteArrayAdapter( char* array, int size, bool own = false )
+ throw( decaf::lang::exceptions::NullPointerException,
+ decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Creates a byte array 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 capacity - size of the array, this is the limit we read and write to.
- * @param own - is this class now the owner of the pointer.
+ *
+ * @param array
+ * The physical array to wrap.
+ * @param size
+ * The size of the array, this is the limit we read and write to.
+ * @param own
+ * Indicates if this class is now the owner of the pointer.
+ *
* @throws NullPointerException if buffer is NULL
+ * @throws IndexOutOfBoundsException if the size is negative.
*/
- ByteArrayAdapter( double* array, std::size_t capacity, bool own = false )
- throw( lang::exceptions::NullPointerException );
+ ByteArrayAdapter( double* array, int size, bool own = false )
+ throw( decaf::lang::exceptions::NullPointerException,
+ decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Creates a byte array 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 capacity - size of the array, this is the limit we read and write to.
- * @param own - is this class now the owner of the pointer.
+ *
+ * @param array
+ * The physical array to wrap.
+ * @param size
+ * The size of the array, this is the limit we read and write to.
+ * @param own
+ * Indicates if this class is now the owner of the pointer.
+ *
* @throws NullPointerException if buffer is NULL
+ * @throws IndexOutOfBoundsException if the size is negative.
*/
- ByteArrayAdapter( float* array, std::size_t capacity, bool own = false )
- throw( lang::exceptions::NullPointerException );
+ ByteArrayAdapter( float* array, int size, bool own = false )
+ throw( decaf::lang::exceptions::NullPointerException,
+ decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Creates a byte array 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 capacity - size of the array, this is the limit we read and write to.
- * @param own - is this class now the owner of the pointer.
+ *
+ * @param array
+ * The physical array to wrap.
+ * @param size
+ * The size of the array, this is the limit we read and write to.
+ * @param own
+ * Indicates if this class is now the owner of the pointer.
+ *
* @throws NullPointerException if buffer is NULL
+ * @throws IndexOutOfBoundsException if the size is negative.
*/
- ByteArrayAdapter( long long* array, std::size_t capacity, bool own = false )
- throw( lang::exceptions::NullPointerException );
+ ByteArrayAdapter( long long* array, int size, bool own = false )
+ throw( decaf::lang::exceptions::NullPointerException,
+ decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Creates a byte array 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 capacity - size of the array, this is the limit we read and write to.
- * @param own - is this class now the owner of the pointer.
+ *
+ * @param array
+ * The physical array to wrap.
+ * @param size
+ * The size of the array, this is the limit we read and write to.
+ * @param own
+ * Indicates if this class is now the owner of the pointer.
+ *
* @throws NullPointerException if buffer is NULL
+ * @throws IndexOutOfBoundsException if the size is negative.
*/
- ByteArrayAdapter( int* array, std::size_t capacity, bool own = false )
- throw( lang::exceptions::NullPointerException );
+ ByteArrayAdapter( int* array, int size, bool own = false )
+ throw( decaf::lang::exceptions::NullPointerException,
+ decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Creates a byte array 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 capacity - size of the array, this is the limit we read and write to.
- * @param own - is this class now the owner of the pointer.
+ *
+ * @param array
+ * The physical array to wrap.
+ * @param size
+ * The size of the array, this is the limit we read and write to.
+ * @param own
+ * Indicates if this class is now the owner of the pointer.
+ *
* @throws NullPointerException if buffer is NULL
+ * @throws IndexOutOfBoundsException if the size is negative.
*/
- ByteArrayAdapter( short* array, std::size_t capacity, bool own = false )
- throw( lang::exceptions::NullPointerException );
+ ByteArrayAdapter( short* array, int size, bool own = false )
+ throw( decaf::lang::exceptions::NullPointerException,
+ decaf::lang::exceptions::IndexOutOfBoundsException );
virtual ~ByteArrayAdapter();
/**
- * Gets the capacity of the underlying array.
+ * Gets the size of the underlying array.
* @return the size the array.
*/
- virtual std::size_t getCapacity() const {
- return this->capacity;
+ virtual int getCapacity() const {
+ return this->size;
}
/**
- * Gets the capacity of the underlying array as if it contains chars
+ * Gets the size of the underlying array as if it contains chars
* @return the size the array.
*/
- virtual std::size_t getCharCapacity() const {
- return this->capacity;
+ virtual int getCharCapacity() const {
+ return this->size;
}
/**
- * Gets the capacity of the underlying array as if it contains doubles
+ * Gets the size of the underlying array as if it contains doubles
* @return the size the array.
*/
- virtual std::size_t getDoubleCapacity() const {
- return this->capacity / sizeof( double );
+ virtual int getDoubleCapacity() const {
+ return this->size / sizeof( double );
}
/**
- * Gets the capacity of the underlying array as if it contains doubles
+ * Gets the size of the underlying array as if it contains doubles
* @return the size the array.
*/
- virtual std::size_t getFloatCapacity() const {
- return this->capacity / sizeof( float );
+ virtual int getFloatCapacity() const {
+ return this->size / sizeof( float );
}
/**
- * Gets the capacity of the underlying array as if it contains doubles
+ * Gets the size of the underlying array as if it contains doubles
* @return the size the array.
*/
- virtual std::size_t getLongCapacity() const {
- return this->capacity / sizeof( long long );
+ virtual int getLongCapacity() const {
+ return this->size / sizeof( long long );
}
/**
- * Gets the capacity of the underlying array as if it contains ints
+ * Gets the size of the underlying array as if it contains ints
* @return the size the array.
*/
- virtual std::size_t getIntCapacity() const {
- return this->capacity / sizeof( int );
+ virtual int getIntCapacity() const {
+ return this->size / sizeof( int );
}
/**
- * Gets the capacity of the underlying array as if it contains shorts
+ * Gets the size of the underlying array as if it contains shorts
* @return the size the array.
*/
- virtual std::size_t getShortCapacity() const {
- return this->capacity / sizeof( short );
+ virtual int getShortCapacity() const {
+ return this->size / sizeof( short );
}
/**
@@ -271,364 +327,497 @@ namespace util{
/**
* Reads from the Byte array starting at the specified offset and reading
- * the specified length. If the length is greater than the capacity of this
+ * the specified length. If the length is greater than the size of this
* underlying byte array then an BufferUnderflowException is thrown.
- * @param buffer - the buffer to read data from this array into.
- * @param offset - position in this array to start reading from.
- * @param length - the amount of data to read from this array.
+ *
+ * @param buffer
+ * The buffer to read data from this array into.
+ * @param size
+ * The size of the buffer passed.
+ * @param offset
+ * The position in this array to start reading from.
+ * @param length
+ * The amount of data to read from this array.
+ *
+ * @throws IndexOutOfBoundsException if the offset + length exceeds the size.
* @throws NullPointerException if buffer is null
- * @throws BufferUnderflowException if there is not enought data to read
- * because the offset or the length is greater than the size of this array.
+ * @throws BufferUnderflowException if there is not enough data to read
+ * because the offset or the length is greater than the size of this array.
*/
- virtual void read( unsigned char* buffer, std::size_t offset, std::size_t length ) const
- throw( decaf::lang::exceptions::NullPointerException,
+ virtual void read( unsigned char* buffer, int size, int offset, int length ) const
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+ decaf::lang::exceptions::NullPointerException,
decaf::nio::BufferUnderflowException );
/**
* Writes from the Byte array given, starting at the specified offset and writing
* the specified amount of data into this objects internal array.. If the length
- * is greater than the capacity of this underlying byte array then an
+ * is greater than the size of this underlying byte array then an
* BufferOverflowException is thrown.
- * @param buffer - the buffer to write get data written into this array.
- * @param offset - position in this array to start writing from.
- * @param length - the amount of data to write to this array.
+ *
+ * @param buffer
+ * The buffer to read data from this array into.
+ * @param size
+ * The size of the buffer passed.
+ * @param offset
+ * The position in this array to start reading from.
+ * @param length
+ * The amount of data to read from this array.
+ *
+ * @throws IndexOutOfBoundsException if the offset + length exceeds the size.
* @throws NullPointerException if buffer is null
* @throws BufferOverflowException if the amount of data to be written to this
- * array or the offset given are larger than this array's capacity.
+ * array or the offset given are larger than this array's size.
*/
- virtual void write( unsigned char* buffer, std::size_t offset, std::size_t length )
- throw( decaf::lang::exceptions::NullPointerException,
+ virtual void write( unsigned char* buffer, int size, int offset, int length )
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+ decaf::lang::exceptions::NullPointerException,
decaf::nio::BufferOverflowException );
/**
- * Resizes the underlying array to the new given capacity, preserving all the
+ * Resizes the underlying array to the new given size, preserving all the
* Data that was previously in the array, unless the resize is smaller than the
* current size in which case only the data that will fit into the new array is
* preserved.
- * <p>
+ *
* A ByteArrayAdapter can only be resized when it owns the underlying array, if it does
- * not then it will throw an IllegalStateException.
- * @param capacity - the new capacity of the array.
+ * not then it will throw an InvalidStateException.
+ *
+ * @param size
+ * The new size of the array.
+ *
+ * @throws IllegalArgumentException if the size parameter is negative.
* @throws InvalidStateException if this object does not own the buffer.
*/
- virtual void resize( std::size_t capacity )
- throw ( lang::exceptions::InvalidStateException );
+ virtual void resize( int size )
+ throw( decaf::lang::exceptions::IllegalArgumentException,
+ decaf::lang::exceptions::InvalidStateException );
/**
* Clear all data from that Array, setting the underlying bytes to zero.
*/
- virtual void clear();
+ virtual void clear() throw();
/**
* Allows the ByteArrayAdapter to be indexed as a standard array. calling the
- * non const version allows the user to change the value at index
- * @param index - the position in the array to access
- * @throws IndexOutOfBoundsException
- */
- unsigned char& operator[]( std::size_t index )
- throw ( decaf::lang::exceptions::IndexOutOfBoundsException );
- const unsigned char& operator[]( std::size_t index ) const
- throw ( decaf::lang::exceptions::IndexOutOfBoundsException );
+ * non constant version allows the user to change the value at index
+ *
+ * @param index
+ * The position in the array to access, if the value is negative or
+ * greater than the size of the underlying array an IndexOutOfBoundsException
+ * is thrown.
+ *
+ * @throws IndexOutOfBoundsException if the preconditions of index are not met.
+ */
+ unsigned char& operator[]( int index )
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
+ const unsigned char& operator[]( int index ) const
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* 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
+ *
+ * @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 or is negative.
+ */
+ virtual unsigned char get( int index ) const
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
+
+ /**
+ * 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 byte that is located at the given index.
+ *
+ * @throws IndexOutOfBoundsException If index is not smaller than the
+ * buffer's limit or is negative.
*/
- virtual unsigned char get( std::size_t index ) const
- throw ( lang::exceptions::IndexOutOfBoundsException );
-
- /**
- * 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 ) const
- throw ( lang::exceptions::IndexOutOfBoundsException ) {
-
- return (char)this->get( index );
- }
+ virtual char getChar( int index ) const
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Reads eight bytes at the given index and returns it. The index is a
- * relative to the size of the type to be read, in otherwords when accessing
+ * relative to the size of the type to be read, in other words when accessing
* the element in the array index * sizeof( type ) if the actual start index
* of the type to be read.
- * @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 ) const
- throw ( lang::exceptions::IndexOutOfBoundsException );
-
- /**
- * Reads eight bytes at the given byte 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
+ *
+ * @param index
+ * The index in the Buffer where the bytes are to be read.
+ *
+ * @returns the value at the given index in the buffer.
+ *
+ * @throws IndexOutOfBoundsException if there are not enough bytes remaining
+ * to fill the requested Data Type, or index is negative.
+ */
+ virtual double getDouble( int index ) const
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
+
+ /**
+ * Reads eight bytes at the given byte index and returns it.
+ *
+ * @param index
+ * The index in the Buffer where the bytes are to be read
+ *
+ * @returns the value at the given index in the buffer.
+ *
+ * @throws IndexOutOfBoundsException if there are not enough bytes remaining
+ * to fill the requested Data Type, or index is negative.
*/
- virtual double getDoubleAt( std::size_t index ) const
- throw ( lang::exceptions::IndexOutOfBoundsException );
+ virtual double getDoubleAt( int index ) const
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Reads four bytes at the given index and returns it. The index is a
* relative to the size of the type to be read, in other words when accessing
* the element in the array index * sizeof( type ) if the actual start index
* of the type to be read.
- * @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
+ *
+ * @param index
+ * The index in the Buffer where the bytes are to be read.
+ *
+ * @returns the value at the given index in the buffer.
+ *
+ * @throws IndexOutOfBoundsException if there are not enough bytes remaining
+ * to fill the requested Data Type, or index is negative.
*/
- virtual float getFloat( std::size_t index ) const
- throw ( lang::exceptions::IndexOutOfBoundsException );
+ virtual float getFloat( int index ) const
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Reads four bytes at the given byte 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
+ *
+ * @param index
+ * The index in the Buffer where the bytes are to be read
+ *
+ * @returns the value at the given index in the buffer.
+ *
+ * @throws IndexOutOfBoundsException if there are not enough bytes remaining
+ * to fill the requested Data Type, or index is negative.
*/
- virtual float getFloatAt( std::size_t index ) const
- throw ( lang::exceptions::IndexOutOfBoundsException );
+ virtual float getFloatAt( int index ) const
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Reads eight bytes at the given index and returns it. The index is a
* relative to the size of the type to be read, in other words when accessing
* the element in the array index * sizeof( type ) if the actual start index
* of the type to be read.
- * @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
+ *
+ * @param index
+ * The index in the Buffer where the bytes are to be read.
+ *
+ * @returns the value at the given index in the buffer.
+ *
+ * @throws IndexOutOfBoundsException if there are not enough bytes remaining
+ * to fill the requested Data Type, or index is negative.
*/
- virtual long long getLong( std::size_t index ) const
- throw ( lang::exceptions::IndexOutOfBoundsException );
+ virtual long long getLong( int index ) const
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Reads eight bytes at the given byte 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
+ *
+ * @param index
+ * The index in the Buffer where the bytes are to be read
+ *
+ * @returns the value at the given index in the buffer.
+ *
+ * @throws IndexOutOfBoundsException if there are not enough bytes remaining
+ * to fill the requested Data Type, or index is negative.
*/
- virtual long long getLongAt( std::size_t index ) const
- throw ( lang::exceptions::IndexOutOfBoundsException );
+ virtual long long getLongAt( int index ) const
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Reads four bytes at the given index and returns it. The index is a
* relative to the size of the type to be read, in other words when accessing
* the element in the array index * sizeof( type ) if the actual start index
* of the type to be read.
- * @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
+ *
+ * @param index
+ * The index in the Buffer where the bytes are to be read.
+ *
+ * @returns the value at the given index in the buffer.
+ *
+ * @throws IndexOutOfBoundsException if there are not enough bytes remaining
+ * to fill the requested Data Type, or index is negative.
*/
- virtual int getInt( std::size_t index ) const
- throw ( lang::exceptions::IndexOutOfBoundsException );
+ virtual int getInt( int index ) const
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Reads four bytes at the given byte 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
+ *
+ * @param index
+ * The index in the Buffer where the bytes are to be read
+ *
+ * @returns the value at the given index in the buffer.
+ *
+ * @throws IndexOutOfBoundsException if there are not enough bytes remaining
+ * to fill the requested Data Type, or index is negative.
*/
- virtual int getIntAt( std::size_t index ) const
- throw ( lang::exceptions::IndexOutOfBoundsException );
+ virtual int getIntAt( int index ) const
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Reads two bytes at the given index and returns it. The index is a
* relative to the size of the type to be read, in other words when accessing
* the element in the array index * sizeof( type ) if the actual start index
* of the type to be read.
- * @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
+ *
+ * @param index
+ * The index in the Buffer where the bytes are to be read.
+ *
+ * @returns the value at the given index in the buffer.
+ *
+ * @throws IndexOutOfBoundsException if there are not enough bytes remaining
+ * to fill the requested Data Type, or index is negative.
*/
- virtual short getShort( std::size_t index ) const
- throw ( lang::exceptions::IndexOutOfBoundsException );
+ virtual short getShort( int index ) const
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Reads two bytes at the given byte 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
+ *
+ * @param index
+ * The index in the Buffer where the bytes are to be read
+ *
+ * @returns the value at the given index in the buffer.
+ *
+ * @throws IndexOutOfBoundsException if there are not enough bytes remaining
+ * to fill the requested Data Type, or index is negative.
*/
- virtual short getShortAt( std::size_t index ) const
- throw ( lang::exceptions::IndexOutOfBoundsException );
+ virtual short getShortAt( int index ) const
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Writes the given byte into this buffer at the given index. The index is a
* relative to the size of the type to be read, in other words when accessing
* the element in the array index * sizeof( type ) if the actual start index
* of the type to be read.
- * @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.
+ *
+ * @param index
+ * The position in the Buffer to write the data.
+ * @param value
+ * The value to write to the array.
+ *
+ * @returns a reference to this buffer.
+ *
+ * @throw IndexOutOfBoundsException if index greater than the buffer's limit
+ * minus the size of the type being written, or index is negative.
*/
- virtual ByteArrayAdapter& put( std::size_t index, unsigned char value )
- throw( lang::exceptions::IndexOutOfBoundsException );
+ virtual ByteArrayAdapter& put( int index, unsigned char value )
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Writes one byte containing the given value, into this buffer at the
* given index. The index is a relative to the size of the type to be read,
* in other words when accessing the element in the array index * sizeof( type )
* if the actual start index of the type to be read.
- * @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.
+ *
+ * @param index
+ * The position in the Buffer to write the data.
+ * @param value
+ * The value to write to the array.
+ *
+ * @returns a reference to this buffer.
+ *
+ * @throw IndexOutOfBoundsException if index greater than the buffer's limit
+ * minus the size of the type being written, or index is negative.
*/
- virtual ByteArrayAdapter& putChar( std::size_t index, char value )
- throw( lang::exceptions::IndexOutOfBoundsException );
+ virtual ByteArrayAdapter& putChar( int index, char value )
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Writes eight bytes containing the given value, into this buffer at the
* given index. The index is a relative to the size of the type to be read,
* in other words when accessing the element in the array index * sizeof( type )
* if the actual start index of the type to be read.
- * @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.
+ *
+ * @param index
+ * The position in the Buffer to write the data.
+ * @param value
+ * The value to write to the array.
+ *
+ * @returns a reference to this buffer.
+ *
+ * @throw IndexOutOfBoundsException if index greater than the buffer's limit
+ * minus the size of the type being written, or index is negative.
*/
- virtual ByteArrayAdapter& putDouble( std::size_t index, double value )
- throw( lang::exceptions::IndexOutOfBoundsException );
+ virtual ByteArrayAdapter& putDouble( int index, double value )
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Writes eight bytes containing the given value, into this buffer at the
* given byte 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.
+ *
+ * @param index
+ * The 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, or index is negative.
*/
- virtual ByteArrayAdapter& putDoubleAt( std::size_t index, double value )
- throw( lang::exceptions::IndexOutOfBoundsException );
+ virtual ByteArrayAdapter& putDoubleAt( int index, double value )
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Writes four bytes containing the given value, into this buffer at the
* given index. The index is a relative to the size of the type to be read,
* in other words when accessing the element in the array index * sizeof( type )
* if the actual start index of the type to be read.
- * @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.
+ *
+ * @param index
+ * The position in the Buffer to write the data.
+ * @param value
+ * The value to write to the array.
+ *
+ * @returns a reference to this buffer.
+ *
+ * @throw IndexOutOfBoundsException if index greater than the buffer's limit
+ * minus the size of the type being written, or index is negative.
*/
- virtual ByteArrayAdapter& putFloat( std::size_t index, float value )
- throw( lang::exceptions::IndexOutOfBoundsException );
+ virtual ByteArrayAdapter& putFloat( int index, float value )
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Writes four bytes containing the given value, into this buffer at the
* given byte 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.
+ *
+ * @param index
+ * The 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, or index is negative.
*/
- virtual ByteArrayAdapter& putFloatAt( std::size_t index, float value )
- throw( lang::exceptions::IndexOutOfBoundsException );
+ virtual ByteArrayAdapter& putFloatAt( int index, float value )
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Writes eight bytes containing the given value, into this buffer at the
* given index. The index is a relative to the size of the type to be read,
* in other words when accessing the element in the array index * sizeof( type )
* if the actual start index of the type to be read.
- * @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.
+ *
+ * @param index
+ * The position in the Buffer to write the data.
+ * @param value
+ * The value to write to the array.
+ *
+ * @returns a reference to this buffer.
+ *
+ * @throw IndexOutOfBoundsException if index greater than the buffer's limit
+ * minus the size of the type being written, or index is negative.
*/
- virtual ByteArrayAdapter& putLong( std::size_t index, long long value )
- throw( lang::exceptions::IndexOutOfBoundsException );
+ virtual ByteArrayAdapter& putLong( int index, long long value )
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Writes eight bytes containing the given value, into this buffer at the
* given byte 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.
+ *
+ * @param index
+ * The 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, or index is negative.
*/
- virtual ByteArrayAdapter& putLongAt( std::size_t index, long long value )
- throw( lang::exceptions::IndexOutOfBoundsException );
+ virtual ByteArrayAdapter& putLongAt( int index, long long value )
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Writes four bytes containing the given value, into this buffer at the
* given index. The index is a relative to the size of the type to be read,
* in other words when accessing the element in the array index * sizeof( type )
* if the actual start index of the type to be read.
- * @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.
+ *
+ * @param index
+ * The position in the Buffer to write the data.
+ * @param value
+ * The value to write to the array.
+ *
+ * @returns a reference to this buffer.
+ *
+ * @throw IndexOutOfBoundsException if index greater than the buffer's limit
+ * minus the size of the type being written, or index is negative.
*/
- virtual ByteArrayAdapter& putInt( std::size_t index, int value )
- throw( lang::exceptions::IndexOutOfBoundsException );
+ virtual ByteArrayAdapter& putInt( int index, int value )
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Writes four bytes containing the given value, into this buffer at the
* given byte 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.
+ *
+ * @param index
+ * The 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, or index is negative.
*/
- virtual ByteArrayAdapter& putIntAt( std::size_t index, int value )
- throw( lang::exceptions::IndexOutOfBoundsException );
+ virtual ByteArrayAdapter& putIntAt( int index, int value )
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Writes two bytes containing the given value, into this buffer at the
* given index. The index is a relative to the size of the type to be read,
* in other words when accessing the element in the array index * sizeof( type )
* if the actual start index of the type to be read.
- * @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.
+ *
+ * @param index
+ * The position in the Buffer to write the data.
+ * @param value
+ * The value to write to the array.
+ *
+ * @returns a reference to this buffer.
+ *
+ * @throw IndexOutOfBoundsException if index greater than the buffer's limit
+ * minus the size of the type being written, or index is negative.
*/
- virtual ByteArrayAdapter& putShort( std::size_t index, short value )
- throw( lang::exceptions::IndexOutOfBoundsException );
+ virtual ByteArrayAdapter& putShort( int index, short value )
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
/**
* Writes two bytes containing the given value, into this buffer at the
* given byte 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.
+ *
+ * @param index
+ * The 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, or index is negative.
*/
- virtual ByteArrayAdapter& putShortAt( std::size_t index, short value )
- throw( lang::exceptions::IndexOutOfBoundsException );
+ virtual ByteArrayAdapter& putShortAt( int index, short value )
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
private:
- void initialize( unsigned char* buffer, std::size_t capacity, bool own );
+ void initialize( unsigned char* buffer, int size, bool own );
};
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BlockingByteArrayInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BlockingByteArrayInputStream.cpp?rev=925692&r1=925691&r2=925692&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BlockingByteArrayInputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BlockingByteArrayInputStream.cpp Sat Mar 20 21:57:20 2010
@@ -32,8 +32,7 @@ BlockingByteArrayInputStream::BlockingBy
////////////////////////////////////////////////////////////////////////////////
BlockingByteArrayInputStream::BlockingByteArrayInputStream(
- const unsigned char* buffer,
- std::size_t bufferSize ){
+ const unsigned char* buffer, int bufferSize ){
closing = false;
setByteArray( buffer, bufferSize );
@@ -44,8 +43,8 @@ BlockingByteArrayInputStream::~BlockingB
}
////////////////////////////////////////////////////////////////////////////////
-void BlockingByteArrayInputStream::setByteArray( const unsigned char* lbuffer,
- std::size_t lbufferSize ){
+void BlockingByteArrayInputStream::setByteArray( const unsigned char* lbuffer, int lbufferSize ){
+
synchronized( this ){
// Remove old data
@@ -64,8 +63,8 @@ void BlockingByteArrayInputStream::setBy
}
////////////////////////////////////////////////////////////////////////////////
-std::size_t BlockingByteArrayInputStream::available() const throw ( decaf::io::IOException ){
- return std::distance( pos, buffer.end() );
+int BlockingByteArrayInputStream::available() const throw ( decaf::io::IOException ){
+ return (int)std::distance( pos, buffer.end() );
}
////////////////////////////////////////////////////////////////////////////////
@@ -111,8 +110,7 @@ int BlockingByteArrayInputStream::doRead
}
////////////////////////////////////////////////////////////////////////////////
-int BlockingByteArrayInputStream::doReadArrayBounded( unsigned char* buffer, std::size_t size,
- std::size_t offset, std::size_t length )
+int BlockingByteArrayInputStream::doReadArrayBounded( unsigned char* buffer, int size, int offset, int length )
throw ( decaf::io::IOException,
decaf::lang::exceptions::IndexOutOfBoundsException,
decaf::lang::exceptions::NullPointerException ) {
@@ -127,17 +125,26 @@ int BlockingByteArrayInputStream::doRead
"BlockingByteArrayInputStream::read - Passed buffer is Null" );
}
- if( length > size - offset ) {
+ if( size < 0 ) {
throw IndexOutOfBoundsException(
- __FILE__, __LINE__,
- "Given size{%d} - offset{%d} is less than length{%d}.", size, offset, length );
+ __FILE__, __LINE__, "size parameter out of Bounds: %d.", size );
+ }
+
+ if( offset > size || offset < 0 ) {
+ throw IndexOutOfBoundsException(
+ __FILE__, __LINE__, "offset parameter out of Bounds: %d.", offset );
+ }
+
+ if( length < 0 || length > size - offset ) {
+ throw IndexOutOfBoundsException(
+ __FILE__, __LINE__, "length parameter out of Bounds: %d.", length );
}
try {
synchronized( this ){
- std::size_t ix = 0;
+ int ix = 0;
for( ; ix < length && !closing; ++ix ) {
@@ -170,10 +177,10 @@ int BlockingByteArrayInputStream::doRead
}
////////////////////////////////////////////////////////////////////////////////
-std::size_t BlockingByteArrayInputStream::skip( std::size_t num )
+long long BlockingByteArrayInputStream::skip( long long num )
throw ( io::IOException, lang::exceptions::UnsupportedOperationException ){
- std::size_t ix = 0;
+ long long ix = 0;
synchronized( this ){
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BlockingByteArrayInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BlockingByteArrayInputStream.h?rev=925692&r1=925691&r2=925692&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BlockingByteArrayInputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BlockingByteArrayInputStream.h Sat Mar 20 21:57:20 2010
@@ -59,53 +59,29 @@ namespace io{
* Constructor that initializes the internal buffer.
* @see setByteArray.
*/
- BlockingByteArrayInputStream( const unsigned char* buffer,
- std::size_t bufferSize );
+ BlockingByteArrayInputStream( const unsigned char* buffer, int bufferSize );
virtual ~BlockingByteArrayInputStream();
/**
- * Sets the data that this reader uses. Replaces any existing
- * data and resets the read index to the beginning of the buffer.
- * When this method is called, it notifies any other threads that
- * data is now available to be read.
- * @param buffer The new data to be copied to the internal buffer.
- * @param bufferSize The size of the new buffer.
+ * {@inheritDoc}
*/
- virtual void setByteArray( const unsigned char* buffer,
- std::size_t bufferSize );
+ virtual void setByteArray( const unsigned char* buffer, int bufferSize );
/**
- * Indicates the number of bytes available to be read without
- * blocking.
- * @return the data available in the internal buffer.
- * @throws IOException if an error occurs.
+ * {@inheritDoc}
*/
- virtual std::size_t available() const throw ( decaf::io::IOException );
+ virtual int available() const throw ( decaf::io::IOException );
/**
- * Closes the target input stream.
- * @throws IOException if an error occurs.
+ * {@inheritDoc}
*/
virtual void close() throw ( decaf::io::IOException );
/**
- * Skips over and discards n bytes of data from this input stream. The
- * skip method may, for a variety of reasons, end up skipping over some
- * smaller number of bytes, possibly 0. This may result from any of a
- * number of conditions; reaching end of file before n bytes have been
- * skipped is only one possibility. The actual number of bytes skipped
- * is returned. If n is negative, no bytes are skipped.
- * <p>
- * The skip method of InputStream creates a byte array and then
- * repeatedly reads into it until n bytes have been read or the end
- * of the stream has been reached. Subclasses are encouraged to
- * provide a more efficient implementation of this method.
- * @param num - the number of bytes to skip
- * @returns total butes skipped
- * @throws IOException if an error occurs
+ * {@inheritDoc}
*/
- virtual std::size_t skip( std::size_t num )
+ virtual long long skip( long long num )
throw ( decaf::io::IOException,
decaf::lang::exceptions::UnsupportedOperationException );
@@ -113,8 +89,7 @@ namespace io{
virtual int doReadByte() throw ( IOException );
- virtual int doReadArrayBounded( unsigned char* buffer, std::size_t size,
- std::size_t offset, std::size_t length )
+ virtual int doReadArrayBounded( unsigned char* buffer, int size, int offset, int length )
throw ( decaf::io::IOException,
decaf::lang::exceptions::IndexOutOfBoundsException,
decaf::lang::exceptions::NullPointerException );
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.cpp?rev=925692&r1=925691&r2=925692&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.cpp Sat Mar 20 21:57:20 2010
@@ -35,15 +35,15 @@ namespace io{
private:
unsigned char* buffer;
- std::size_t bufferSize;
- std::size_t pos;
- std::size_t count;
- std::size_t markLimit;
- long long markPos;
+ int bufferSize;
+ int pos;
+ int count;
+ int markLimit;
+ int markPos;
public:
- StreamBuffer( std::size_t bufferSize ) {
+ StreamBuffer( int bufferSize ) {
this->buffer = new unsigned char[bufferSize];
this->bufferSize = bufferSize;
@@ -57,7 +57,7 @@ namespace io{
delete [] this->buffer;
}
- void resize( std::size_t newSize ) {
+ void resize( int newSize ) {
unsigned char* temp = new unsigned char[newSize];
System::arraycopy( temp, 0, buffer, 0, count );
std::swap( temp, buffer );
@@ -65,11 +65,11 @@ namespace io{
this->bufferSize = newSize;
}
- std::size_t getUnusedBytes() const{
+ int getUnusedBytes() const{
return bufferSize - count;
}
- std::size_t available() const {
+ int available() const {
return this->count - this->pos;
}
@@ -77,19 +77,19 @@ namespace io{
return this->buffer[this->pos++];
}
- void advance( std::size_t amount ) {
+ void advance( int amount ) {
this->pos += amount;
}
- void reverse( std::size_t amount ) {
+ void reverse( int amount ) {
this->pos -= amount;
}
- void advanceTail( std::size_t amount ) {
+ void advanceTail( int amount ) {
this->count += amount;
}
- std::size_t getBufferSize() {
+ int getBufferSize() {
return this->bufferSize;
}
@@ -97,19 +97,19 @@ namespace io{
return this->buffer;
}
- std::size_t getCount() const{
+ int getCount() const{
return count;
}
- void setCount( std::size_t count ) {
+ void setCount( int count ) {
this->count = count;
}
- std::size_t getPos() const{
+ int getPos() const{
return pos;
}
- void setPos( std::size_t pos ) {
+ void setPos( int pos ) {
this->pos = pos;
}
@@ -126,7 +126,7 @@ namespace io{
}
void reset() {
- this->pos = (std::size_t)this->markPos;
+ this->pos = this->markPos;
}
void normalizeBuffer() {
@@ -149,15 +149,15 @@ namespace io{
return pos - markPos >= markLimit;
}
- std::size_t getMarkPos() const {
- return (std::size_t)this->markPos;
+ int getMarkPos() const {
+ return this->markPos;
}
- void setMarkPos( std::size_t markPos ) {
+ void setMarkPos( int markPos ) {
this->markPos = markPos;
}
- std::size_t getMarkLimit() const {
+ int getMarkLimit() const {
return this->markLimit;
}
};
@@ -173,13 +173,12 @@ BufferedInputStream::BufferedInputStream
}
////////////////////////////////////////////////////////////////////////////////
-BufferedInputStream::BufferedInputStream( InputStream* stream, std::size_t bufferSize, bool own )
+BufferedInputStream::BufferedInputStream( InputStream* stream, int bufferSize, bool own )
throw ( lang::exceptions::IllegalArgumentException ) : FilterInputStream( stream, own ) {
- if( bufferSize == 0 ) {
+ if( bufferSize < 0 ) {
throw new IllegalArgumentException(
- __FILE__, __LINE__,
- "BufferedInputStream::init - Size must be greater than zero");
+ __FILE__, __LINE__, "Size must be greater than zero");
}
this->buffer.reset( new StreamBuffer( bufferSize ) );
@@ -202,11 +201,11 @@ void BufferedInputStream::close() throw(
// Free the class reference, read operation may still be
// holding onto the buffer while blocked.
- this->buffer.release();
+ this->buffer.reset( NULL );
}
////////////////////////////////////////////////////////////////////////////////
-std::size_t BufferedInputStream::available() const throw ( IOException ) {
+int BufferedInputStream::available() const throw ( IOException ) {
if( buffer == NULL || this->isClosed() ) {
throw IOException(
@@ -280,8 +279,8 @@ int BufferedInputStream::doReadByte() th
}
////////////////////////////////////////////////////////////////////////////////
-int BufferedInputStream::doReadArrayBounded( unsigned char* buffer, std::size_t size,
- std::size_t offset, std::size_t length )
+int BufferedInputStream::doReadArrayBounded( unsigned char* buffer, int size,
+ int offset, int length )
throw ( decaf::io::IOException,
decaf::lang::exceptions::IndexOutOfBoundsException,
decaf::lang::exceptions::NullPointerException ) {
@@ -302,10 +301,19 @@ int BufferedInputStream::doReadArrayBoun
"Buffer passed was NULL." );
}
- if( offset + length > size ) {
+ if( offset > size || offset < 0 ) {
throw IndexOutOfBoundsException(
- __FILE__, __LINE__,
- "Given size{%d} - offset{%d} is less than length{%d}.", size, offset, length );
+ __FILE__, __LINE__, "offset parameter out of Bounds: %d.", offset );
+ }
+
+ if( length < 0 || length > size - offset ) {
+ throw IndexOutOfBoundsException(
+ __FILE__, __LINE__, "length parameter out of Bounds: %d.", length );
+ }
+
+ if( buffer == NULL ) {
+ throw NullPointerException(
+ __FILE__, __LINE__, "Buffer pointer passed was NULL." );
}
// For zero, do nothing
@@ -321,14 +329,14 @@ int BufferedInputStream::doReadArrayBoun
__FILE__, __LINE__, "Stream is closed" );
}
- std::size_t required = 0;
+ int required = 0;
// There are bytes available in the buffer so use them up first and
// then we check to see if any are available on the stream, if not
// then just return what we had.
if( !streamBuffer->isEmpty() ) {
- std::size_t copylength =
+ int copylength =
streamBuffer->available() >= length ? length : streamBuffer->available();
System::arraycopy( streamBuffer->getBuffer(), streamBuffer->getPos(),
@@ -397,7 +405,7 @@ int BufferedInputStream::doReadArrayBoun
}
////////////////////////////////////////////////////////////////////////////////
-std::size_t BufferedInputStream::skip( std::size_t amount )
+long long BufferedInputStream::skip( long long amount )
throw ( IOException, lang::exceptions::UnsupportedOperationException ){
try{
@@ -421,7 +429,7 @@ std::size_t BufferedInputStream::skip( s
return amount;
}
- int read = (int)streamBuffer->available();
+ int read = streamBuffer->available();
streamBuffer->advance( streamBuffer->getCount() );
@@ -439,7 +447,7 @@ std::size_t BufferedInputStream::skip( s
}
// Couldn't get all the bytes, skip what we read
- read += (int)streamBuffer->available();
+ read += streamBuffer->available();
streamBuffer->advance( streamBuffer->getCount() );
return read;
@@ -470,13 +478,13 @@ int BufferedInputStream::bufferData( Inp
return result;
}
- std::size_t markPos = buffer->getMarkPos();
- std::size_t markLimit = buffer->getMarkLimit();
+ int markPos = buffer->getMarkPos();
+ int markLimit = buffer->getMarkLimit();
if( markPos == 0 && markLimit > buffer->getBufferSize() ) {
// Increase buffer size to accommodate the readlimit.
- std::size_t newLength = buffer->getBufferSize() * 2;
+ int newLength = buffer->getBufferSize() * 2;
if( newLength > markLimit ) {
newLength = markLimit;
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.h?rev=925692&r1=925691&r2=925692&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.h Sat Mar 20 21:57:20 2010
@@ -64,92 +64,42 @@ namespace io{
* @param own
* Indicates if we own the stream object, defaults to false.
*
- * @throws IllegalArgumentException is the size is zero.
+ * @throws IllegalArgumentException is the size is zero or negative.
*/
- BufferedInputStream( InputStream* stream, std::size_t bufferSize, bool own = false )
+ BufferedInputStream( InputStream* stream, int bufferSize, bool own = false )
throw ( lang::exceptions::IllegalArgumentException );
virtual ~BufferedInputStream();
/**
- * Indicates the number of bytes available.
- * @return the sum of the amount of data available
- * in the buffer and the data available on the target
- * input stream.
+ * {@inheritDoc}
*/
- virtual std::size_t available() const throw ( decaf::io::IOException );
+ virtual int available() const throw ( decaf::io::IOException );
/**
- * Close this BufferedInputStream. This implementation closes the target
- * stream and releases any resources associated with it.
- * @throws IOException If an error occurs attempting to close this stream.
+ * {@inheritDoc}
*/
virtual void close() throw( decaf::io::IOException );
/**
- * Skips over and discards n bytes of data from this input stream. The
- * skip method may, for a variety of reasons, end up skipping over some
- * smaller number of bytes, possibly 0. This may result from any of a
- * number of conditions; reaching end of file before n bytes have been
- * skipped is only one possibility. The actual number of bytes skipped
- * is returned. If n is negative, no bytes are skipped.
- * <p>
- * The skip method of InputStream creates a byte array and then
- * repeatedly reads into it until n bytes have been read or the end
- * of the stream has been reached. Subclasses are encouraged to
- * provide a more efficient implementation of this method.
- * @param num - the number of bytes to skip
- * @returns total butes skipped
- * @throws IOException if an error occurs
+ * {@inheritDoc}
*/
- virtual std::size_t skip( std::size_t num )
+ virtual long long skip( long long num )
throw ( decaf::io::IOException,
decaf::lang::exceptions::UnsupportedOperationException );
/**
- * Marks the current position in the stream A subsequent call to the
- * reset method repositions this stream at the last marked position so
- * that subsequent reads re-read the same bytes.
- *
- * If a stream instance reports that marks are supported then the stream
- * will ensure that the same bytes can be read again after the reset method
- * is called so long the readLimit is not reached.
- *
- * @param readLimit
- * max bytes read before marked position is invalid.
+ * {@inheritDoc}
*/
virtual void mark( int readLimit );
/**
- * Repositions this stream to the position at the time the mark method was
- * last called on this input stream.
- *
- * If the method markSupported returns true, then:
- * * If the method mark has not been called since the stream was created,
- * or the number of bytes read from the stream since mark was last called
- * is larger than the argument to mark at that last call, then an
- * IOException might be thrown.
- * * If such an IOException is not thrown, then the stream is reset to a
- * state such that all the bytes read since the most recent call to mark
- * (or since the start of the file, if mark has not been called) will be
- * resupplied to subsequent callers of the read method, followed by any
- * bytes that otherwise would have been the next input data as of the
- * time of the call to reset.
- * If the method markSupported returns false, then:
- * * The call to reset may throw an IOException.
- * * If an IOException is not thrown, then the stream is reset to a fixed
- * state that depends on the particular type of the input stream and how
- * it was created. The bytes that will be supplied to subsequent callers
- * of the read method depend on the particular type of the input stream.
- * @throws IOException
+ * {@inheritDoc}
*/
virtual void reset() throw ( decaf::io::IOException );
/**
- * Determines if this input stream supports the mark and reset methods.
- * Whether or not mark and reset are supported is an invariant property of
- * a particular input stream instance.
- * @returns true if this stream instance supports marks
+ * {@inheritDoc}
*/
virtual bool markSupported() const{ return true; }
@@ -157,8 +107,7 @@ namespace io{
virtual int doReadByte() throw ( decaf::io::IOException );
- virtual int doReadArrayBounded( unsigned char* buffer, std::size_t size,
- std::size_t offset, std::size_t length )
+ virtual int doReadArrayBounded( unsigned char* buffer, int size, int offset, int length )
throw ( decaf::io::IOException,
decaf::lang::exceptions::IndexOutOfBoundsException,
decaf::lang::exceptions::NullPointerException );
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedOutputStream.cpp?rev=925692&r1=925691&r2=925692&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedOutputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedOutputStream.cpp Sat Mar 20 21:57:20 2010
@@ -35,8 +35,8 @@ BufferedOutputStream::BufferedOutputStre
}
////////////////////////////////////////////////////////////////////////////////
-BufferedOutputStream::BufferedOutputStream( OutputStream* stream, std::size_t bufSize, bool own )
- : FilterOutputStream( stream, own ) {
+BufferedOutputStream::BufferedOutputStream( OutputStream* stream, int bufSize, bool own )
+ throw( IllegalArgumentException ) : FilterOutputStream( stream, own ) {
try {
this->init( bufSize );
@@ -61,7 +61,12 @@ BufferedOutputStream::~BufferedOutputStr
}
////////////////////////////////////////////////////////////////////////////////
-void BufferedOutputStream::init( std::size_t bufSize ) {
+void BufferedOutputStream::init( int bufSize ) {
+
+ if( bufSize < 0 ) {
+ throw IllegalArgumentException(
+ __FILE__, __LINE__, "Size of Buffer cannot be negative." );
+ }
this->bufferSize = bufSize;
@@ -128,7 +133,7 @@ void BufferedOutputStream::doWriteByte(
}
////////////////////////////////////////////////////////////////////////////////
-void BufferedOutputStream::doWriteArray( const unsigned char* buffer, std::size_t size )
+void BufferedOutputStream::doWriteArray( const unsigned char* buffer, int size )
throw ( decaf::io::IOException ) {
try{
@@ -150,8 +155,8 @@ void BufferedOutputStream::doWriteArray(
}
////////////////////////////////////////////////////////////////////////////////
-void BufferedOutputStream::doWriteArrayBounded( const unsigned char* buffer, std::size_t size,
- std::size_t offset, std::size_t length )
+void BufferedOutputStream::doWriteArrayBounded( const unsigned char* buffer, int size,
+ int offset, int length )
throw ( decaf::io::IOException,
decaf::lang::exceptions::NullPointerException,
decaf::lang::exceptions::IndexOutOfBoundsException ) {
@@ -174,22 +179,30 @@ void BufferedOutputStream::doWriteArrayB
"BufferedOutputStream::write - Buffer passed is Null.");
}
- if( ( offset + length ) > size ) {
- throw decaf::lang::exceptions::IndexOutOfBoundsException(
- __FILE__, __LINE__,
- "DataOutputStream::write - given offset + length is greater than buffer size.");
+ if( size < 0 ) {
+ throw IndexOutOfBoundsException(
+ __FILE__, __LINE__, "size parameter out of Bounds: %d.", size );
+ }
+
+ if( offset > size || offset < 0 ) {
+ throw IndexOutOfBoundsException(
+ __FILE__, __LINE__, "offset parameter out of Bounds: %d.", offset );
+ }
+
+ if( length < 0 || length > size - offset ) {
+ throw IndexOutOfBoundsException(
+ __FILE__, __LINE__, "length parameter out of Bounds: %d.", length );
}
// Iterate until all the data is written.
- for( std::size_t pos=0; pos < length; ){
+ for( int pos = 0; pos < length; ){
if( tail >= bufferSize ){
emptyBuffer();
}
// Get the number of bytes left to write.
- std::size_t bytesToWrite = Math::min( (int)( bufferSize - tail ),
- (int)( length - pos ) );
+ int bytesToWrite = Math::min( bufferSize - tail, length - pos );
System::arraycopy( buffer, offset + pos, this->buffer, this->tail, bytesToWrite );
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedOutputStream.h?rev=925692&r1=925691&r2=925692&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedOutputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedOutputStream.h Sat Mar 20 21:57:20 2010
@@ -39,17 +39,17 @@ namespace io{
/**
* The size of the internal buffer.
*/
- std::size_t bufferSize;
+ int bufferSize;
/**
* The current head of the buffer.
*/
- std::size_t head;
+ int head;
/**
* The current tail of the buffer.
*/
- std::size_t tail;
+ int tail;
public:
@@ -72,14 +72,16 @@ namespace io{
* The size for the internal buffer.
* @param own
* Indicates if this class owns the stream pointer.
+ *
+ * @throws IllegalArgumentException if the bufferSize given is negative.
*/
- BufferedOutputStream( OutputStream* stream, std::size_t bufferSize, bool own = false );
+ BufferedOutputStream( OutputStream* stream, int bufferSize, bool own = false )
+ throw( decaf::lang::exceptions::IllegalArgumentException );
virtual ~BufferedOutputStream();
/**
- * Invokes flush on the target output stream.
- * @throws IOException thrown if an error occurs.
+ * @{inheritDoc}
*/
virtual void flush() throw ( decaf::io::IOException );
@@ -87,11 +89,10 @@ namespace io{
virtual void doWriteByte( unsigned char c ) throw ( decaf::io::IOException );
- virtual void doWriteArray( const unsigned char* buffer, std::size_t size )
+ virtual void doWriteArray( const unsigned char* buffer, int size )
throw ( decaf::io::IOException );
- virtual void doWriteArrayBounded( const unsigned char* buffer, std::size_t size,
- std::size_t offset, std::size_t length )
+ virtual void doWriteArrayBounded( const unsigned char* buffer, int size, int offset, int length )
throw ( decaf::io::IOException,
decaf::lang::exceptions::NullPointerException,
decaf::lang::exceptions::IndexOutOfBoundsException );
@@ -100,10 +101,11 @@ namespace io{
/**
* Initializes the internal structures.
+ *
* @param bufferSize
* How large to make the initial buffer when creating it.
*/
- void init( std::size_t bufferSize );
+ void init( int bufferSize );
/**
* Writes the contents of the buffer to the output stream.
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.cpp?rev=925692&r1=925691&r2=925692&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.cpp Sat Mar 20 21:57:20 2010
@@ -35,8 +35,10 @@ ByteArrayInputStream::ByteArrayInputStre
}
////////////////////////////////////////////////////////////////////////////////
-ByteArrayInputStream::ByteArrayInputStream( const unsigned char* buffer,
- std::size_t bufferSize ){
+ByteArrayInputStream::ByteArrayInputStream( const unsigned char* buffer, int bufferSize )
+ throw( decaf::lang::exceptions::NullPointerException,
+ decaf::lang::exceptions::IllegalArgumentException ) {
+
setByteArray( buffer, bufferSize );
}
@@ -56,13 +58,20 @@ void ByteArrayInputStream::setBuffer( co
}
////////////////////////////////////////////////////////////////////////////////
-void ByteArrayInputStream::setByteArray( const unsigned char* buffer, std::size_t bufferSize ) {
+void ByteArrayInputStream::setByteArray( const unsigned char* buffer, int bufferSize )
+ throw( decaf::lang::exceptions::NullPointerException,
+ decaf::lang::exceptions::IllegalArgumentException ) {
if( buffer == NULL ) {
throw NullPointerException(
__FILE__, __LINE__, "Input Buffer cannot be NULL." );
}
+ if( bufferSize < 0 ) {
+ throw IllegalArgumentException(
+ __FILE__, __LINE__, "Size given for input buffer was negative." );
+ }
+
// We're using the default buffer.
this->activeBuffer = &this->defaultBuffer;
@@ -79,7 +88,7 @@ void ByteArrayInputStream::setByteArray(
}
////////////////////////////////////////////////////////////////////////////////
-std::size_t ByteArrayInputStream::available() const throw ( IOException ) {
+int ByteArrayInputStream::available() const throw ( IOException ) {
if( activeBuffer == NULL ){
throw IOException(
@@ -87,7 +96,7 @@ std::size_t ByteArrayInputStream::availa
"buffer has not been initialized");
}
- return std::distance( pos, activeBuffer->end() );
+ return (int)std::distance( pos, activeBuffer->end() );
}
////////////////////////////////////////////////////////////////////////////////
@@ -137,8 +146,8 @@ int ByteArrayInputStream::doReadByte() t
}
////////////////////////////////////////////////////////////////////////////////
-int ByteArrayInputStream::doReadArrayBounded( unsigned char* buffer, std::size_t size,
- std::size_t offset, std::size_t length )
+int ByteArrayInputStream::doReadArrayBounded( unsigned char* buffer, int size,
+ int offset, int length )
throw ( decaf::io::IOException,
decaf::lang::exceptions::IndexOutOfBoundsException,
decaf::lang::exceptions::NullPointerException ) {
@@ -161,20 +170,29 @@ int ByteArrayInputStream::doReadArrayBou
"ByteArrayInputStream::read - Buffer passed is Null" );
}
- if( length > size - offset ) {
+ if( size < 0 ) {
throw IndexOutOfBoundsException(
- __FILE__, __LINE__,
- "Given size{%d} - offset{%d} is less than length{%d}.", size, offset, length );
+ __FILE__, __LINE__, "size parameter out of Bounds: %d.", size );
}
- std::size_t ix = 0;
+ if( offset > size || offset < 0 ) {
+ throw IndexOutOfBoundsException(
+ __FILE__, __LINE__, "offset parameter out of Bounds: %d.", offset );
+ }
+
+ if( length < 0 || length > size - offset ) {
+ throw IndexOutOfBoundsException(
+ __FILE__, __LINE__, "length parameter out of Bounds: %d.", length );
+ }
+
+ int ix = 0;
if( pos == activeBuffer->end() ) {
return -1;
}
// How far are we from end
- std::size_t remaining = (std::size_t)distance( pos, activeBuffer->end() );
+ int remaining = (int)distance( pos, activeBuffer->end() );
// We only read as much as is left if the amount remaining is less than
// the amount of data asked for.
@@ -184,7 +202,7 @@ int ByteArrayInputStream::doReadArrayBou
buffer[ix + offset] = *(pos);
}
- return (int)ix;
+ return ix;
}
DECAF_CATCH_RETHROW( IOException )
DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
@@ -193,7 +211,7 @@ int ByteArrayInputStream::doReadArrayBou
}
////////////////////////////////////////////////////////////////////////////////
-std::size_t ByteArrayInputStream::skip( std::size_t num )
+long long ByteArrayInputStream::skip( long long num )
throw ( IOException, lang::exceptions::UnsupportedOperationException ){
try{
@@ -204,7 +222,7 @@ std::size_t ByteArrayInputStream::skip(
"ByteArrayInputStream::skip - Buffer has not been initialized" );
}
- std::size_t ix = 0;
+ long long ix = 0;
// Increment the position until we've skipped the desired number
// or we've hit the end of the buffer.