activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r911562 [2/3] - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/activemq/commands/ main/activemq/io/ main/activemq/wireformat/openwire/ main/activemq/wireformat/openwire/marshal/v1/ main/activemq/wireformat/openwire/marshal/v2/ main/...
Date Thu, 18 Feb 2010 20:34:51 GMT
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=911562&r1=911561&r2=911562&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 Thu Feb 18 20:34:48 2010
@@ -100,7 +100,7 @@
     }
 
     if( head != tail ){
-        outputStream->write( buffer+head, 0, tail-head );
+        outputStream->write( buffer+head, tail-head, 0, tail-head );
     }
     head = tail = 0;
 }
@@ -163,21 +163,22 @@
                 "BufferedOutputStream::write - Stream is clsoed" );
         }
 
-        this->write( &buffer[0], 0, buffer.size() );
+        this->write( &buffer[0], buffer.size(), 0, buffer.size() );
     }
     DECAF_CATCH_RETHROW( IOException )
     DECAF_CATCHALL_THROW( IOException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void BufferedOutputStream::write( const unsigned char* buffer,
-                                  std::size_t offset, std::size_t len )
-    throw ( IOException, lang::exceptions::NullPointerException ) {
+void BufferedOutputStream::write( const unsigned char* buffer, std::size_t size,
+                                  std::size_t offset, std::size_t length )
+    throw ( decaf::io::IOException,
+            decaf::lang::exceptions::NullPointerException,
+            decaf::lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
 
-        // Fast exit.
-        if( len == 0 ) {
+        if( length == 0 ) {
             return;
         }
 
@@ -193,15 +194,21 @@
                 "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.");
+        }
+
         // Iterate until all the data is written.
-        for( std::size_t pos=0; pos < len; ){
+        for( std::size_t pos=0; pos < length; ){
 
             if( tail >= bufferSize ){
                 emptyBuffer();
             }
 
             // Get the number of bytes left to write.
-            std::size_t bytesToWrite = min( (int)bufferSize-tail, len-pos );
+            std::size_t bytesToWrite = min( (int)bufferSize-tail, length-pos );
 
             // Copy the data.
             memcpy( this->buffer+tail, buffer+offset+pos, bytesToWrite );
@@ -215,5 +222,6 @@
     }
     DECAF_CATCH_RETHROW( IOException )
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCHALL_THROW( IOException )
 }

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=911562&r1=911561&r2=911562&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 Thu Feb 18 20:34:48 2010
@@ -97,17 +97,28 @@
             throw ( IOException );
 
         /**
-         * Writes an array of bytes to the output stream.
-         * @param buffer The array of bytes to write.
-         * @param offset the position to start writing in buffer.
-         * @param len The number of bytes from the buffer to be written.
-         * @throws IOException thrown if an error occurs.
+         * Writes an array of bytes to the output stream in order starting at buffer[offset]
+         * and proceeding until the number of bytes specified by the length argument are
+         * written or an error occurs.
+         *
+         * @param buffer
+         *      The array of bytes to write.
+         * @param size
+         *      The size of the buffer array passed.
+         * @param offset
+         *      The position to start writing in buffer.
+         * @param length
+         *      The number of bytes from the buffer to be written.
+         *
+         * @throws IOException if an I/O error occurs.
          * @throws NullPointerException thrown if buffer is Null.
+         * @throws IndexOutOfBoundsException if the offset + length > size.
          */
-        virtual void write( const unsigned char* buffer,
-                            std::size_t offset,
-                            std::size_t len )
-            throw ( IOException, lang::exceptions::NullPointerException );
+        virtual void write( const unsigned char* buffer, std::size_t size,
+                            std::size_t offset, std::size_t length )
+            throw ( decaf::io::IOException,
+                    decaf::lang::exceptions::NullPointerException,
+                    decaf::lang::exceptions::IndexOutOfBoundsException );
 
         /**
          * Invokes flush on the target 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=911562&r1=911561&r2=911562&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 Thu Feb 18 20:34:48 2010
@@ -117,11 +117,17 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int ByteArrayInputStream::read( unsigned char* buffer, std::size_t offset, std::size_t bufferSize )
-    throw ( IOException, lang::exceptions::NullPointerException ){
+int ByteArrayInputStream::read( unsigned char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+    throw ( decaf::io::IOException,
+            decaf::lang::exceptions::IndexOutOfBoundsException,
+            decaf::lang::exceptions::NullPointerException ) {
 
     try{
 
+        if( size == 0 || length == 0 ) {
+            return 0;
+        }
+
         if( activeBuffer == NULL ){
             throw IOException(
                 __FILE__, __LINE__,
@@ -134,6 +140,12 @@
                 "ByteArrayInputStream::read - Buffer passed is Null" );
         }
 
+        if( length > size - offset ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "Given size{%d} - offset{%d} is less than length{%d}.", size, offset, length );
+        }
+
         std::size_t ix = 0;
 
         if( pos == activeBuffer->end() ) {
@@ -145,9 +157,9 @@
 
         // We only read as much as is left if the amount remaining is less than
         // the amount of data asked for.
-        bufferSize = remaining < bufferSize ? remaining : bufferSize;
+        length = remaining < length ? remaining : length;
 
-        for( ; ix < bufferSize; ++ix, ++pos) {
+        for( ; ix < length; ++ix, ++pos) {
             buffer[ix + offset] = *(pos);
         }
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.h?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.h Thu Feb 18 20:34:48 2010
@@ -134,10 +134,11 @@
          * @return The number of bytes read.
          * @throws IOException thrown if an error occurs.
          */
-        virtual int read( unsigned char* buffer,
-                          std::size_t offset,
-                          std::size_t bufferSize )
-            throw ( IOException, lang::exceptions::NullPointerException );
+        virtual int read( unsigned char* buffer, std::size_t size,
+                          std::size_t offset, std::size_t length )
+            throw ( decaf::io::IOException,
+                    decaf::lang::exceptions::IndexOutOfBoundsException,
+                    decaf::lang::exceptions::NullPointerException );
 
         /**
          * Closes the target input stream.

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayOutputStream.cpp?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayOutputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayOutputStream.cpp Thu Feb 18 20:34:48 2010
@@ -65,17 +65,22 @@
             return;
         }
 
-        this->write( &buffer[0], 0, buffer.size() );
+        this->write( &buffer[0], buffer.size(), 0, buffer.size() );
     }
     DECAF_CATCH_RETHROW( IOException )
     DECAF_CATCHALL_THROW( IOException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ByteArrayOutputStream::write( const unsigned char* buffer,
-                                   std::size_t offset,
-                                   std::size_t len )
-    throw ( IOException, lang::exceptions::NullPointerException ) {
+void ByteArrayOutputStream::write( const unsigned char* buffer, std::size_t size,
+                                   std::size_t offset, std::size_t length )
+    throw ( decaf::io::IOException,
+            decaf::lang::exceptions::NullPointerException,
+            decaf::lang::exceptions::IndexOutOfBoundsException ) {
+
+    if( length == 0 ) {
+        return;
+    }
 
     if( buffer == NULL ) {
         throw NullPointerException(
@@ -83,8 +88,14 @@
             "ByteArrayOutputStream::write - passed buffer is null" );
     }
 
+    if( ( offset + length ) > size ) {
+        throw decaf::lang::exceptions::IndexOutOfBoundsException(
+            __FILE__, __LINE__,
+            "ByteArrayOutputStream::write - given offset + length is greater than buffer size.");
+    }
+
     try{
-        activeBuffer->insert( activeBuffer->end(), buffer + offset, buffer + offset + len );
+        activeBuffer->insert( activeBuffer->end(), buffer + offset, buffer + offset + length );
     }
     DECAF_CATCH_RETHROW( IOException )
     DECAF_CATCHALL_THROW( IOException )
@@ -116,7 +127,7 @@
                 "ByteArrayOutputStream::writeTo - Passed stream pointer is null" );
         }
 
-        out->write( this->toByteArray(), 0, this->size() );
+        out->write( this->toByteArray(), this->size(), 0, this->size() );
     }
     DECAF_CATCH_RETHROW( IOException )
     DECAF_CATCH_RETHROW( NullPointerException )

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayOutputStream.h?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayOutputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayOutputStream.h Thu Feb 18 20:34:48 2010
@@ -116,17 +116,28 @@
             throw ( IOException );
 
         /**
-         * Writes an array of bytes to the output stream.
-         * @param buffer The array of bytes to write.
-         * @param offset the position to start writing in buffer.
-         * @param len The number of bytes from the buffer to be written.
-         * @throws IOException thrown if an error occurs.
+         * Writes an array of bytes to the output stream in order starting at buffer[offset]
+         * and proceeding until the number of bytes specified by the length argument are
+         * written or an error occurs.
+         *
+         * @param buffer
+         *      The array of bytes to write.
+         * @param size
+         *      The size of the buffer array passed.
+         * @param offset
+         *      The position to start writing in buffer.
+         * @param length
+         *      The number of bytes from the buffer to be written.
+         *
+         * @throws IOException if an I/O error occurs.
          * @throws NullPointerException thrown if buffer is Null.
+         * @throws IndexOutOfBoundsException if the offset + length > size.
          */
-        virtual void write( const unsigned char* buffer,
-                            std::size_t offset,
-                            std::size_t len )
-            throw ( IOException, lang::exceptions::NullPointerException );
+        virtual void write( const unsigned char* buffer, std::size_t size,
+                            std::size_t offset, std::size_t length )
+            throw ( decaf::io::IOException,
+                    decaf::lang::exceptions::NullPointerException,
+                    decaf::lang::exceptions::IndexOutOfBoundsException );
 
         /**
          * Invokes flush on the target output stream, has no affect.

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp Thu Feb 18 20:34:48 2010
@@ -42,17 +42,15 @@
 int DataInputStream::read( std::vector<unsigned char>& buffer ) throw ( io::IOException ) {
 
     try {
-        return this->read( &buffer[0], 0, buffer.size() );
+        return this->read( &buffer[0], buffer.size(), 0, buffer.size() );
     }
     DECAF_CATCH_RETHROW( IOException )
     DECAF_CATCHALL_THROW( IOException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int DataInputStream::read( unsigned char* buffer,
-                           std::size_t offset,
-                           std::size_t length )
-    throw ( IOException, NullPointerException ) {
+int DataInputStream::read( unsigned char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+    throw ( IOException, NullPointerException, IndexOutOfBoundsException ) {
 
     try {
 
@@ -72,7 +70,13 @@
                 "DataInputStream::readFully - Base input stream is null" );
         }
 
-        return inputStream->read( &buffer[offset], 0, length );
+        if( length > size - offset ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "Given size{%d} - offset{%d} is less than length{%d}.", size, offset, length );
+        }
+
+        return inputStream->read( buffer, size, offset, length );
     }
     DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCH_RETHROW( NullPointerException )
@@ -246,7 +250,7 @@
 
         while( true ) {
 
-            if( inputStream->read( (unsigned char*)( &buffer[pos] ), 0, 1 ) == -1 ) {
+            if( inputStream->read( (unsigned char*)( &buffer[0] ), size, pos, 1 ) == -1 ) {
                 throw EOFException(
                     __FILE__, __LINE__,
                     "DataInputStream::readString - Reached EOF" );
@@ -409,7 +413,7 @@
 
         std::size_t n = 0;
         while( n < length ) {
-            int count = inputStream->read( &buffer[offset + n], 0, (length - n) );
+            int count = inputStream->read( buffer, length, offset + n, length - n );
             if( count == -1 ) {
                 throw EOFException(
                     __FILE__, __LINE__,
@@ -450,3 +454,19 @@
     DECAF_CATCH_RETHROW( IOException )
     DECAF_CATCHALL_THROW( IOException )
 }
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStream::readAllData( unsigned char* buffer, std::size_t length )
+    throw ( decaf::io::IOException, decaf::io::EOFException ) {
+
+    std::size_t n = 0;
+    do{
+        int count = inputStream->read( buffer, length, n, length - n );
+        if( count == -1 ) {
+            throw EOFException(
+                __FILE__, __LINE__,
+                "DataInputStream::readLong - Reached EOF" );
+        }
+        n += count;
+    } while( n < length );
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.h?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.h Thu Feb 18 20:34:48 2010
@@ -135,19 +135,27 @@
          * If the first byte cannot be read for any reason other than end of
          * file, then an IOException is thrown. In particular, an IOException
          * is thrown if the input stream has been closed.
-         * @param buffer - byte array to insert read data into
-         * @param offset - location in buffer to start writing
-         * @param length - number of bytes to read
-         * @returns the total number of bytes read, or -1 if there is no
-         *          more data because the stream is EOF.
-         * @throws IOException
-         * @throws NullPointerException if the buffer is null
-         */
-        virtual int read( unsigned char* buffer,
-                          std::size_t offset,
-                          std::size_t length )
-            throw ( io::IOException,
-                    lang::exceptions::NullPointerException );
+         *
+         * @param buffer
+         *      The target buffer to write the read in data to.
+         * @param size
+         *      The size in bytes of the target buffer.
+         * @param offset
+         *      The position in the buffer to start inserting the read in data.
+         * @param length
+         *      The maximum number of bytes that should be read into buffer.
+         *
+         * @return The number of bytes read or -1 if EOF is detected
+         *
+         * @throws IOException if an I/O error occurs.
+         * @throws NullPointerException if buffer passed is NULL.
+         * @throws IndexOutOfBoundsException if length > size - offset.
+         */
+        virtual int read( unsigned char* buffer, std::size_t size,
+                          std::size_t offset, std::size_t length )
+            throw ( decaf::io::IOException,
+                    decaf::lang::exceptions::IndexOutOfBoundsException,
+                    decaf::lang::exceptions::NullPointerException );
 
         /**
          * Reads one input byte and returns true if that byte is nonzero,
@@ -368,23 +376,9 @@
 
     private:
 
-        // Used internally to reliable get data from the underlying stream
-        inline void readAllData( unsigned char* buffer,
-                                 std::size_t length )
-            throw ( io::IOException,
-                    io::EOFException ) {
-
-            std::size_t n = 0;
-            do{
-                int count = inputStream->read( &buffer[n], 0, length - n );
-                if( count == -1 ) {
-                    throw EOFException(
-                        __FILE__, __LINE__,
-                        "DataInputStream::readLong - Reached EOF" );
-                }
-                n += count;
-            } while( n < length );
-        }
+        // Used internally to reliably get data from the underlying stream
+        void readAllData( unsigned char* buffer, std::size_t length )
+            throw ( decaf::io::IOException, decaf::io::EOFException );
 
     };
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutputStream.cpp?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutputStream.cpp Thu Feb 18 20:34:48 2010
@@ -71,7 +71,7 @@
                 "DataOutputStream::write - Base stream is Null");
         }
 
-        outputStream->write( &buffer[0], 0, buffer.size() );
+        outputStream->write( &buffer[0], buffer.size(), 0, buffer.size() );
         written += buffer.size();
     }
     DECAF_CATCH_RETHROW( IOException )
@@ -79,15 +79,15 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void DataOutputStream::write( const unsigned char* buffer,
-                              std::size_t offset,
-                              std::size_t len )
-    throw ( IOException, lang::exceptions::NullPointerException )
-{
+void DataOutputStream::write( const unsigned char* buffer, std::size_t size,
+                              std::size_t offset, std::size_t length )
+    throw ( decaf::io::IOException,
+            decaf::lang::exceptions::NullPointerException,
+            decaf::lang::exceptions::IndexOutOfBoundsException ) {
 
     try {
 
-        if( len == 0 ) {
+        if( length == 0 ) {
             return;
         }
 
@@ -103,11 +103,18 @@
                 "DataOutputStream::write - passed buffer is Null" );
         }
 
-        outputStream->write( buffer+offset, 0, len );
-        written += len;
+        if( ( offset + length ) > size ) {
+            throw decaf::lang::exceptions::IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "DataOutputStream::write - given offset + length is greater than buffer size.");
+        }
+
+        outputStream->write( buffer, size, offset, length );
+        written += length;
     }
     DECAF_CATCH_RETHROW( IOException )
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCHALL_THROW( IOException )
 }
 
@@ -177,7 +184,7 @@
         buffer[0] = (value & 0xFF00) >> 8;
         buffer[1] = (value & 0x00FF) >> 0;
 
-        outputStream->write( buffer, 0, sizeof(value) );
+        outputStream->write( buffer, sizeof(value), 0, sizeof(value) );
         written += sizeof( value );
     }
     DECAF_CATCH_RETHROW( IOException )
@@ -199,7 +206,7 @@
         buffer[0] = (value & 0xFF00) >> 8;
         buffer[1] = (value & 0x00FF) >> 0;
 
-        outputStream->write( buffer, 0, sizeof(value) );
+        outputStream->write( buffer, sizeof(value), 0, sizeof(value) );
         written += sizeof( value );
     }
     DECAF_CATCH_RETHROW( IOException )
@@ -221,7 +228,7 @@
         buffer[2] = (value & 0x0000FF00) >> 8;
         buffer[3] = (value & 0x000000FF) >> 0;
 
-        outputStream->write( buffer, 0, sizeof(value) );
+        outputStream->write( buffer, sizeof(value), 0, sizeof(value) );
         written += sizeof( value );
     }
     DECAF_CATCH_RETHROW( IOException )
@@ -247,7 +254,7 @@
         buffer[6] = (unsigned char)((value & 0x000000000000FF00ULL) >> 8);
         buffer[7] = (unsigned char)((value & 0x00000000000000FFULL) >> 0);
 
-        outputStream->write( buffer, 0, sizeof(value) );
+        outputStream->write( buffer, sizeof(value), 0, sizeof(value) );
         written += sizeof( value );
     }
     DECAF_CATCH_RETHROW( IOException )
@@ -285,7 +292,7 @@
         }
 
         // do not add one so that we don't write the NULL
-        this->write( (const unsigned char*)value.c_str(), 0, value.length() );
+        this->write( (const unsigned char*)value.c_str(), value.length(), 0, value.length() );
     }
     DECAF_CATCH_RETHROW( IOException )
     DECAF_CATCHALL_THROW( IOException )
@@ -300,7 +307,7 @@
         }
 
         // add one so that we write the NULL
-        this->write( (const unsigned char*)value.c_str(), 0, value.length() + 1 );
+        this->write( (const unsigned char*)value.c_str(), value.length() + 1, 0, value.length() + 1 );
     }
     DECAF_CATCH_RETHROW( IOException )
     DECAF_CATCHALL_THROW( IOException )
@@ -346,7 +353,7 @@
 
         this->writeUnsignedShort( (unsigned short)utfLength );
         if( utfLength > 0 ) {
-            this->write( &utfBytes[0], 0, utfIndex );
+            this->write( &utfBytes[0], utfIndex, 0, utfIndex );
         }
     }
     DECAF_CATCH_RETHROW( UTFDataFormatException )

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutputStream.h?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutputStream.h Thu Feb 18 20:34:48 2010
@@ -71,18 +71,28 @@
         virtual void write( unsigned char c ) throw ( IOException );
 
         /**
-         * Writes an array of bytes to the output stream.  the counter
-         * written is incremented by len.
-         * @param buffer The array of bytes to write.
-         * @param offset the position in buffer to start writing from.
-         * @param len The number of bytes from the buffer to be written.
-         * @throws IOException thrown if an error occurs.
-         * @throws NullPointerException if buffer is Null
-         */
-        virtual void write( const unsigned char* buffer,
-                            std::size_t offset,
-                            std::size_t len )
-            throw ( IOException, lang::exceptions::NullPointerException );
+         * Writes an array of bytes to the output stream in order starting at buffer[offset]
+         * and proceeding until the number of bytes specified by the length argument are
+         * written or an error occurs.
+         *
+         * @param buffer
+         *      The array of bytes to write.
+         * @param size
+         *      The size of the buffer array passed.
+         * @param offset
+         *      The position to start writing in buffer.
+         * @param length
+         *      The number of bytes from the buffer to be written.
+         *
+         * @throws IOException if an I/O error occurs.
+         * @throws NullPointerException thrown if buffer is Null.
+         * @throws IndexOutOfBoundsException if the offset + length > size.
+         */
+        virtual void write( const unsigned char* buffer, std::size_t size,
+                            std::size_t offset, std::size_t length )
+            throw ( decaf::io::IOException,
+                    decaf::lang::exceptions::NullPointerException,
+                    decaf::lang::exceptions::IndexOutOfBoundsException );
 
         /**
          * Writes an array of bytes to the output stream.

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterInputStream.h?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterInputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterInputStream.h Thu Feb 18 20:34:48 2010
@@ -134,12 +134,12 @@
          * @throws IOException thrown if an error occurs.
          * @throws NullPointerException
          */
-        virtual int read( unsigned char* buffer,
-                          std::size_t offset,
-                          std::size_t bufferSize )
-            throw ( IOException,
-                    lang::exceptions::NullPointerException )
-        {
+        virtual int read( unsigned char* buffer, std::size_t size,
+                          std::size_t offset, std::size_t length )
+            throw ( decaf::io::IOException,
+                    decaf::lang::exceptions::IndexOutOfBoundsException,
+                    decaf::lang::exceptions::NullPointerException ) {
+
             try {
 
                 if( isClosed() ) {
@@ -148,7 +148,7 @@
                         "FilterInputStream::read - Stream is closed" );
                 }
 
-                return inputStream->read( buffer, offset, bufferSize );
+                return inputStream->read( buffer, size, offset, length );
             }
             DECAF_CATCH_RETHROW( IOException )
             DECAF_CATCH_RETHROW( lang::exceptions::NullPointerException )

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterOutputStream.h?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterOutputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/FilterOutputStream.h Thu Feb 18 20:34:48 2010
@@ -135,20 +135,29 @@
         }
 
         /**
-         * Writes an array of bytes to the output stream.  The write method of
-         * FilterOutputStream calls the write method of one argument on each
-         * byte to output.
-         * @param buffer The array of bytes to write.
-         * @param offset, the position to start writing in buffer.
-         * @param len The number of bytes from the buffer to be written.
-         * @throws IOException thrown if an error occurs.
+         * Writes an array of bytes to the output stream in order starting at buffer[offset]
+         * and proceeding until the number of bytes specified by the length argument are
+         * written or an error occurs.
+         *
+         * @param buffer
+         *      The array of bytes to write.
+         * @param size
+         *      The size of the buffer array passed.
+         * @param offset
+         *      The position to start writing in buffer.
+         * @param length
+         *      The number of bytes from the buffer to be written.
+         *
+         * @throws IOException if an I/O error occurs.
          * @throws NullPointerException thrown if buffer is Null.
+         * @throws IndexOutOfBoundsException if the offset + length > size.
          */
-        virtual void write( const unsigned char* buffer,
-                            std::size_t offset DECAF_UNUSED,
-                            std::size_t len )
-            throw ( IOException,
-                    lang::exceptions::NullPointerException ) {
+        virtual void write( const unsigned char* buffer, std::size_t size,
+                            std::size_t offset, std::size_t length )
+            throw ( decaf::io::IOException,
+                    decaf::lang::exceptions::NullPointerException,
+                    decaf::lang::exceptions::IndexOutOfBoundsException ) {
+
             try {
 
                 if( isClosed() ) {
@@ -158,13 +167,19 @@
                 }
 
                 if( buffer == NULL ) {
-                    throw lang::exceptions::NullPointerException(
+                    throw decaf::lang::exceptions::NullPointerException(
                         __FILE__, __LINE__,
                         "FilterOutputStream::write - Buffer passed is Null.");
                 }
 
-                for( std::size_t ix = 0; ix < len; ++ix ) {
-                    outputStream->write( buffer[ix] );
+                if( ( offset + length ) > size ) {
+                    throw decaf::lang::exceptions::IndexOutOfBoundsException(
+                        __FILE__, __LINE__,
+                        "FilterOutputStream::write - given offset + length is greater than buffer size.");
+                }
+
+                for( std::size_t ix = 0; ix < length; ++ix ) {
+                    outputStream->write( buffer[offset + ix] );
                 }
             }
             DECAF_CATCH_RETHROW( IOException )

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStream.h?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStream.h Thu Feb 18 20:34:48 2010
@@ -23,17 +23,20 @@
 #include <decaf/util/concurrent/Synchronizable.h>
 #include <decaf/lang/exceptions/UnsupportedOperationException.h>
 #include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
 #include <decaf/util/Config.h>
 
 namespace decaf{
 namespace io{
 
     /**
-     * Base interface for an input stream.
+     * A base class that must be implemented by all classes wishing to provide a
+     * class that reads in a stream of bytes
+     *
+     * @since 1.0
      */
     class DECAF_API InputStream : public Closeable,
-                                  public util::concurrent::Synchronizable
-    {
+                                  public util::concurrent::Synchronizable {
     public:
 
         virtual ~InputStream(){}
@@ -46,7 +49,11 @@
          * 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.
+         *
+         * Calling mark on a closed stream instance should have no effect.
+         *
+         * @param readLimit
+         *      The max bytes read before marked position is invalid.
          */
         virtual void mark( int readLimit ) = 0;
 
@@ -65,30 +72,39 @@
          *     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
+         *
+         * @throws IOException if an I/O error occurs.
          */
-        virtual void reset() throw ( IOException ) = 0;
+        virtual void reset() throw ( decaf::io::IOException ) = 0;
 
         /**
          * 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
          */
         virtual bool markSupported() const = 0;
 
         /**
-         * Indicates the number of bytes available.
+         * Indicates the number of bytes available.  The default implementation of this
+         * methods returns 0.  Classes that override this method may return the total
+         * number of bytes that are currently available for reading and others may simply
+         * return a value of one indicating that there is some data avaiable.  The caller
+         * should view the result of this method as an absolute.
+         *
          * @return the number of bytes available on this input stream.
-         * @throws IOException if an error occurs.
+         *
+         * @throws IOException if an I/O error occurs.
          */
-        virtual std::size_t available() const throw ( IOException ) = 0;
+        virtual std::size_t available() const throw ( decaf::io::IOException ) = 0;
 
         /**
          * Reads a single byte from the buffer.  The value byte is returned as an int in the
@@ -97,44 +113,76 @@
          * the stream is detected, or an exception is thrown.
          *
          * @return The next byte or -1 if the end of stream is reached.
-         * @throws IOException thrown if an error occurs.
+         * @throws IOException if an I/O error occurs.
          */
-        virtual int read() throw ( IOException ) = 0;
+        virtual int read() throw ( decaf::io::IOException ) = 0;
 
         /**
-         * Reads an array of bytes from the buffer.  Blocks until
-         * the requested number of bytes are available.
-         * @param buffer (out) the target buffer.
-         * @param offset the position in the buffer to start reading from.
-         * @param bufferSize the size of the output buffer.
+         * Reads up to length bytes of data from the input stream into an array of bytes. An
+         * attempt is made to read as many as len bytes, but a smaller number may be read.
+         * The number of bytes actually read is returned as an integer.
+         *
+         * This method blocks until input data is available, end of file is detected, or
+         * an exception is thrown.
+         *
+         * If len is zero, then no bytes are read and 0 is returned; otherwise, there is an
+         * attempt to read at least one byte. If no byte is available because the stream is
+         * at end of file, the value -1 is returned; otherwise, at least one byte is read and
+         * stored into b.
+         *
+         * The first byte read is stored into element b[off], the next one into b[off+1], and
+         * so on. The number of bytes read is, at most, equal to len. Let k be the number of
+         * bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1],
+         * leaving elements b[off+k] through b[off+len-1] unaffected.
+         *
+         * In every case, elements b[0] through b[off] and elements b[off+len] through b[b.length-1]
+         * are unaffected.
+         *
+         * @param buffer
+         *      The target buffer to write the read in data to.
+         * @param size
+         *      The size in bytes of the target buffer.
+         * @param offset
+         *      The position in the buffer to start inserting the read in data.
+         * @param length
+         *      The maximum number of bytes that should be read into buffer.
+         *
          * @return The number of bytes read or -1 if EOF is detected
-         * @throws IOException thrown if an error occurs.
-         * @throws NullPointerException if buffer is null
-         */
-        virtual int read( unsigned char* buffer,
-                          std::size_t offset,
-                          std::size_t bufferSize )
-            throw ( IOException,
-                    lang::exceptions::NullPointerException ) = 0;
-
-        /**
-         * 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
+         *
+         * @throws IOException if an I/O error occurs.
+         * @throws NullPointerException if buffer passed is NULL.
+         * @throws IndexOutOfBoundsException if length > size - offset.
+         */
+        virtual int read( unsigned char* buffer, std::size_t size,
+                          std::size_t offset, std::size_t length )
+            throw ( decaf::io::IOException,
+                    decaf::lang::exceptions::IndexOutOfBoundsException,
+                    decaf::lang::exceptions::NullPointerException ) = 0;
+
+        /**
+         * 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.
+         *
+         * 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 bytes skipped
-         * @throws IOException if an error occurs
+         *
+         * @throws IOException if an I/O error occurs.
+         * @throws UnsupportedOperationException if the concrete stream class does
+         *         not support skipping bytes.
          */
         virtual std::size_t skip( std::size_t num )
-            throw ( io::IOException, lang::exceptions::UnsupportedOperationException ) = 0;
+            throw ( decaf::io::IOException,
+                    decaf::lang::exceptions::UnsupportedOperationException ) = 0;
 
     };
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStreamReader.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStreamReader.cpp?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStreamReader.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStreamReader.cpp Thu Feb 18 20:34:48 2010
@@ -84,8 +84,11 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int InputStreamReader::read( char* buffer, std::size_t offset, std::size_t length )
-    throw( IOException, lang::exceptions::NullPointerException ) {
+int InputStreamReader::doReadArraySizeOffsetLength(
+    char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+        throw( decaf::io::IOException,
+               decaf::lang::exceptions::NullPointerException,
+               decaf::lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
         checkClosed();
@@ -94,9 +97,11 @@
             return 0;
         }
 
-        return this->stream->read( (unsigned char*)buffer, offset, length );
+        return this->stream->read( (unsigned char*)buffer, size, offset, length );
     }
     DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCHALL_THROW( IOException )
 }
 
@@ -106,40 +111,3 @@
         throw IOException( __FILE__, __LINE__, "This Reader is Closed" );
     }
 }
-
-////////////////////////////////////////////////////////////////////////////////
-int InputStreamReader::read( std::vector<char>& buffer )
-    throw( decaf::io::IOException ) {
-
-    try{
-        checkClosed();
-        return Reader::read( buffer );
-    }
-    DECAF_CATCH_RETHROW( IOException )
-    DECAF_CATCHALL_THROW( IOException )
-}
-
-////////////////////////////////////////////////////////////////////////////////
-int InputStreamReader::read() throw( decaf::io::IOException ) {
-
-    try{
-        checkClosed();
-        return Reader::read();
-    }
-    DECAF_CATCH_RETHROW( IOException )
-    DECAF_CATCHALL_THROW( IOException )
-}
-
-////////////////////////////////////////////////////////////////////////////////
-int InputStreamReader::read( decaf::nio::CharBuffer* charBuffer )
-         throw( decaf::io::IOException,
-                decaf::lang::exceptions::NullPointerException,
-                decaf::nio::ReadOnlyBufferException ) {
-
-    try{
-        checkClosed();
-        return Reader::read( charBuffer );
-    }
-    DECAF_CATCH_RETHROW( IOException )
-    DECAF_CATCHALL_THROW( IOException )
-}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStreamReader.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStreamReader.h?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStreamReader.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStreamReader.h Thu Feb 18 20:34:48 2010
@@ -69,23 +69,16 @@
 
         virtual void close() throw( decaf::io::IOException );
 
-        virtual int read( char* buffer, std::size_t offset, std::size_t count )
-            throw( IOException, lang::exceptions::NullPointerException );
-
         virtual bool ready() const throw( decaf::io::IOException );
 
-        virtual int read( std::vector<char>& buffer )
-            throw( decaf::io::IOException );
-
-        virtual int read() throw( decaf::io::IOException );
-
-        virtual int read( decaf::nio::CharBuffer* charBuffer )
-                 throw( decaf::io::IOException,
-                        decaf::lang::exceptions::NullPointerException,
-                        decaf::nio::ReadOnlyBufferException );
-
     protected:
 
+        virtual int doReadArraySizeOffsetLength( char* buffer, std::size_t size,
+                                                 std::size_t offset, std::size_t length )
+            throw( decaf::io::IOException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException,
+                   decaf::lang::exceptions::NullPointerException );
+
         virtual void checkClosed() const throw( decaf::io::IOException );
 
     };

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStream.h?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStream.h Thu Feb 18 20:34:48 2010
@@ -23,13 +23,17 @@
 #include <decaf/io/IOException.h>
 #include <decaf/util/concurrent/Synchronizable.h>
 #include <decaf/util/Config.h>
+
 #include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
 
 namespace decaf{
 namespace io{
 
     /**
-     * Base interface for an output stream.
+     * Base interface for any class that wants to represent an output stream of bytes.
+     *
+     * @since 1.0
      */
     class DECAF_API OutputStream : public Closeable,
                                    public Flushable,
@@ -37,35 +41,53 @@
     {
     public:
 
-        virtual ~OutputStream(){}
+        virtual ~OutputStream() {}
 
         /**
          * Writes a single byte to the output stream.
-         * @param c the byte.
-         * @throws IOException thrown if an error occurs.
+         *
+         * @param c
+         *      The byte to write to the sink.
+         *
+         * @throws IOException if an I/O error occurs.
          */
         virtual void write( unsigned char c ) throw ( IOException ) = 0;
 
         /**
-         * Writes an array of bytes to the output stream.
-         * @param buffer The bytes to write.
-         * @throws IOException thrown if an error occurs.
+         * Writes an array of bytes to the output stream.  The entire contents of
+         * the given vector are written to the output stream.
+         *
+         * @param buffer
+         *      The vector of bytes to write.
+         *
+         * @throws IOException if an I/O error occurs.
          */
         virtual void write( const std::vector<unsigned char>& buffer )
             throw ( IOException ) = 0;
 
         /**
-         * Writes an array of bytes to the output stream.
-         * @param buffer The array of bytes to write.
-         * @param offset the position to start writing in buffer.
-         * @param len The number of bytes from the buffer to be written.
-         * @throws IOException thrown if an error occurs.
+         * Writes an array of bytes to the output stream in order starting at buffer[offset]
+         * and proceeding until the number of bytes specified by the length argument are
+         * written or an error occurs.
+         *
+         * @param buffer
+         *      The array of bytes to write.
+         * @param size
+         *      The size of the buffer array passed.
+         * @param offset
+         *      The position to start writing in buffer.
+         * @param length
+         *      The number of bytes from the buffer to be written.
+         *
+         * @throws IOException if an I/O error occurs.
          * @throws NullPointerException thrown if buffer is Null.
+         * @throws IndexOutOfBoundsException if the offset + length > size.
          */
-        virtual void write( const unsigned char* buffer,
-                            std::size_t offset,
-                            std::size_t len )
-            throw ( IOException, lang::exceptions::NullPointerException ) = 0;
+        virtual void write( const unsigned char* buffer, std::size_t size,
+                            std::size_t offset, std::size_t length )
+            throw ( decaf::io::IOException,
+                    decaf::lang::exceptions::NullPointerException,
+                    decaf::lang::exceptions::IndexOutOfBoundsException ) = 0;
 
     };
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStreamWriter.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStreamWriter.cpp?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStreamWriter.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStreamWriter.cpp Thu Feb 18 20:34:48 2010
@@ -80,8 +80,11 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void OutputStreamWriter::write( const char* buffer, std::size_t offset, std::size_t count )
-    throw( IOException, NullPointerException ) {
+void OutputStreamWriter::doWriteArraySizeOffsetLength( const char* buffer, std::size_t size,
+                                                       std::size_t offset, std::size_t length )
+    throw( decaf::io::IOException,
+           decaf::lang::exceptions::NullPointerException,
+           decaf::lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
         checkClosed();
@@ -91,7 +94,7 @@
                 __FILE__, __LINE__, "Given buffer was NULL." );
         }
 
-        this->stream->write( (const unsigned char*)buffer, offset, count );
+        this->stream->write( (const unsigned char*)buffer, size, offset, length );
     }
     DECAF_CATCH_RETHROW( IOException )
     DECAF_CATCH_RETHROW( NullPointerException )
@@ -99,52 +102,6 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void OutputStreamWriter::write( char v ) throw( IOException ) {
-
-    try{
-        checkClosed();
-        Writer::write( v );
-    }
-    DECAF_CATCH_RETHROW( IOException )
-    DECAF_CATCHALL_THROW( IOException )
-}
-
-////////////////////////////////////////////////////////////////////////////////
-void OutputStreamWriter::write( const std::vector<char>& buffer ) throw( IOException ) {
-
-    try{
-        checkClosed();
-        Writer::write( buffer );
-    }
-    DECAF_CATCH_RETHROW( IOException )
-    DECAF_CATCHALL_THROW( IOException )
-}
-
-////////////////////////////////////////////////////////////////////////////////
-void OutputStreamWriter::write( const std::string& str ) throw( IOException ) {
-
-    try{
-        checkClosed();
-        Writer::write( str );
-    }
-    DECAF_CATCH_RETHROW( IOException )
-    DECAF_CATCHALL_THROW( IOException )
-}
-
-////////////////////////////////////////////////////////////////////////////////
-void OutputStreamWriter::write( const std::string& str, std::size_t offset, std::size_t length )
-    throw( IOException, IndexOutOfBoundsException ) {
-
-    try{
-        checkClosed();
-        Writer::write( str, offset, length );
-    }
-    DECAF_CATCH_RETHROW( IOException )
-    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
-    DECAF_CATCHALL_THROW( IOException )
-}
-
-////////////////////////////////////////////////////////////////////////////////
 void OutputStreamWriter::checkClosed() const throw( decaf::io::IOException ) {
     if( closed ) {
         throw IOException( __FILE__, __LINE__, "This Writer is Closed" );

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStreamWriter.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStreamWriter.h?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStreamWriter.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStreamWriter.h Thu Feb 18 20:34:48 2010
@@ -66,22 +66,14 @@
 
         virtual void flush() throw( decaf::io::IOException );
 
-        virtual void write( char v ) throw( decaf::io::IOException );
-
-        virtual void write( const std::vector<char>& buffer )
-            throw( decaf::io::IOException );
-
-        virtual void write( const std::string& str )
-            throw( decaf::io::IOException );
-
-        virtual void write( const std::string& str, std::size_t offset, std::size_t count )
-            throw( decaf::io::IOException, decaf::lang::exceptions::IndexOutOfBoundsException );
-
-        virtual void write( const char* buffer, std::size_t offset, std::size_t count )
-            throw( decaf::io::IOException, decaf::lang::exceptions::NullPointerException );
-
     protected:
 
+        virtual void doWriteArraySizeOffsetLength( const char* buffer, std::size_t size,
+                                                   std::size_t offset, std::size_t length )
+            throw( decaf::io::IOException,
+                   decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException );
+
         // Used to check state and throw error when closed.
         virtual void checkClosed() const throw( decaf::io::IOException );
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Reader.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Reader.cpp?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Reader.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Reader.cpp Thu Feb 18 20:34:48 2010
@@ -72,14 +72,19 @@
 
         while( skipped < count ) {
 
-            int read = this->read( &charsSkipped[0], 0, toRead );
+            int read = this->doReadArraySizeOffsetLength(
+                            &charsSkipped[0], charsSkipped.size(), 0, toRead );
+
             if( read == -1 ) {
                 return skipped;
             }
+
             skipped += read;
+
             if( read < toRead ) {
                 return skipped;
             }
+
             if( count - skipped < (std::size_t)toRead ) {
                 toRead = (int)( count - skipped );
             }
@@ -95,24 +100,104 @@
 int Reader::read( std::vector<char>& buffer ) throw( decaf::io::IOException ) {
 
     try{
+        return this->doReadVector( buffer );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Reader::read( char* buffer, std::size_t length )
+   throw( decaf::io::IOException,
+          decaf::lang::exceptions::NullPointerException ) {
+
+    try{
+        return this->doReadArraySize( buffer, length );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Reader::read( char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+    throw( decaf::io::IOException,
+           decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::NullPointerException ) {
+
+    try{
+        return this->doReadArraySizeOffsetLength( buffer, size, offset, length );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Reader::read() throw( IOException ) {
+
+    try{
+        return this->doReadChar();
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Reader::read( decaf::nio::CharBuffer* charBuffer )
+         throw( decaf::io::IOException,
+                decaf::lang::exceptions::NullPointerException,
+                decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+        // Error checking is done in the Impl.
+        return this->doReadCharBuffer( charBuffer );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Reader::doReadVector( std::vector<char>& buffer )
+    throw( decaf::io::IOException ) {
+
+    try{
 
         if( buffer.size() == 0 ) {
             return -1;
         }
 
-        return this->read( &buffer[0], 0, buffer.size() );
+        return this->doReadArraySizeOffsetLength( &buffer[0], buffer.size(), 0, buffer.size() );
     }
     DECAF_CATCH_RETHROW( IOException )
     DECAF_CATCHALL_THROW( IOException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Reader::read() throw( IOException ) {
+int Reader::doReadArraySize( char* buffer, std::size_t length )
+    throw( decaf::io::IOException,
+           decaf::lang::exceptions::NullPointerException ) {
 
     try{
+
+        if( length == 0 ) {
+            return 0;
+        }
+
+        return this->doReadArraySizeOffsetLength( buffer, length, 0, length );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Reader::doReadChar() throw( decaf::io::IOException ) {
+
+    try{
+
         char buffer;
 
-        if( this->read( &buffer, 0, 1 ) == -1 ) {
+        if( this->doReadArraySizeOffsetLength( &buffer, 1, 0, 1 ) == -1 ) {
             return -1;
         }
 
@@ -123,10 +208,10 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int Reader::read( decaf::nio::CharBuffer* charBuffer )
-         throw( decaf::io::IOException,
-                decaf::lang::exceptions::NullPointerException,
-                decaf::nio::ReadOnlyBufferException ) {
+int Reader::doReadCharBuffer( decaf::nio::CharBuffer* charBuffer )
+    throw( decaf::io::IOException,
+           decaf::lang::exceptions::NullPointerException,
+           decaf::nio::ReadOnlyBufferException ) {
 
     try{
 
@@ -143,7 +228,7 @@
 
         std::vector<char> buffer( length );
 
-        length = Math::min( length, this->read( buffer ) );
+        length = Math::min( length, this->doReadVector( buffer ) );
 
         if( length > 0 ) {
             charBuffer->put( &buffer[0], 0, length );

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Reader.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Reader.h?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Reader.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Reader.h Thu Feb 18 20:34:48 2010
@@ -22,6 +22,8 @@
 #include <decaf/io/Closeable.h>
 #include <decaf/io/IOException.h>
 #include <decaf/io/InputStream.h>
+
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
 #include <decaf/lang/exceptions/NullPointerException.h>
 
 namespace decaf{
@@ -56,8 +58,7 @@
          *
          * @throw IOException if an I/O error occurs, or the stream does not support mark.
          */
-        virtual void mark( std::size_t readAheadLimit )
-            throw( decaf::io::IOException );
+        virtual void mark( std::size_t readAheadLimit ) throw( decaf::io::IOException );
 
         /**
          * Tells whether this stream supports the mark() operation. The default implementation
@@ -101,22 +102,39 @@
          *
          * @throw IOException if an I/O error occurs.
          */
-       virtual std::size_t skip( std::size_t count )
-           throw( decaf::io::IOException );
+        virtual std::size_t skip( std::size_t count ) throw( decaf::io::IOException );
 
-       /**
-        * Reads characters into an array. This method will block until some input is available,
-        * an I/O error occurs, or the end of the stream is reached.
-        *
-        * @param buffer
-        *       The buffer to read characters into.
-        *
-        * @return The number of characters read, or -1 if the end of the stream has been reached
-        *
-         * @throw IOException if an I/O error occurs.
-        */
-       virtual int read( std::vector<char>& buffer )
-           throw( decaf::io::IOException );
+        /**
+         * Reads characters into an array. This method will block until some input is available,
+         * an I/O error occurs, or the end of the stream is reached.
+         *
+         * @param buffer
+         *       The buffer to read characters into.
+         *
+         * @return The number of characters read, or -1 if the end of the stream has been reached
+         *
+         * @throws IOException thrown if an I/O error occurs.
+         */
+        int read( std::vector<char>& buffer ) throw( decaf::io::IOException );
+
+        /**
+         * Reads characters into an array, the method will attempt to read as much data as the size
+         * of the array. This method will block until some input is available, an I/O error occurs,
+         * or the end of the stream is reached.
+         *
+         * @param buffer
+         *      The target char buffer.
+         * @param size
+         *      The size in bytes of the target buffer.
+         *
+         * @return The number of bytes read or -1 if the end of stream is reached.
+         *
+         * @throws IOException thrown if an I/O error occurs.
+         * @throws NullPointerException if buffer is NULL.
+         */
+        int read( char* buffer, std::size_t length )
+           throw( decaf::io::IOException,
+                  decaf::lang::exceptions::NullPointerException );
 
         /**
          * Reads characters into a portion of an array. This method will block until some input
@@ -124,6 +142,8 @@
          *
          * @param buffer
          *      The target char buffer.
+         * @param size
+         *      The size in bytes of the target buffer.
          * @param offset
          *      The position in the buffer to start filling.
          * @param length
@@ -131,12 +151,14 @@
          *
          * @return The number of bytes read or -1 if the end of stream is reached.
          *
-         * @throws IOException thrown if an error occurs.
+         * @throws IOException thrown if an I/O error occurs.
          * @throws NullPointerException if buffer is NULL.
+         * @throws IndexOutOfBoundsException if the offset + length is greater than the array size.
          */
-        virtual int read( char* buffer, std::size_t offset, std::size_t length )
+        int read( char* buffer, std::size_t size, std::size_t offset, std::size_t length )
             throw( decaf::io::IOException,
-                   decaf::lang::exceptions::NullPointerException ) = 0;
+                   decaf::lang::exceptions::IndexOutOfBoundsException,
+                   decaf::lang::exceptions::NullPointerException );
 
         /**
          * Reads a single character. This method will block until a character is available,
@@ -148,15 +170,62 @@
          * @return The character read, as an integer in the range 0 to 65535 (0x00-0xffff),
          *         or -1 if the end of the stream has been reached.
          *
-         * @throws IOException thrown if an error occurs.
+         * @throws IOException thrown if an I/O error occurs.
          */
-        virtual int read() throw( decaf::io::IOException );
+        int read() throw( decaf::io::IOException );
 
-        virtual int read( decaf::nio::CharBuffer* charBuffer )
+        int read( decaf::nio::CharBuffer* charBuffer )
                  throw( decaf::io::IOException,
                         decaf::lang::exceptions::NullPointerException,
                         decaf::nio::ReadOnlyBufferException );
 
+    protected:
+
+        /**
+         * Override this method to customize the functionality of the method
+         * read( char* buffer, std::size_t offset, std::size_t length ).
+         *
+         * All subclasses must override this method to provide the basic Reader
+         * functionality.
+         */
+        virtual int doReadArraySizeOffsetLength( char* buffer, std::size_t size,
+                                                 std::size_t offset, std::size_t length )
+            throw( decaf::io::IOException,
+                   decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException ) = 0;
+
+    protected:
+
+        /**
+         * Override this method to customize the functionality of the method
+         * read( std::vector<char>& buffer ).
+         */
+        virtual int doReadVector( std::vector<char>& buffer )
+            throw( decaf::io::IOException );
+
+        /**
+         * Override this method to customize the functionality of the method
+         * read( char* buffer, std::size_t length ).
+         */
+        virtual int doReadArraySize( char* buffer, std::size_t length )
+            throw( decaf::io::IOException,
+                   decaf::lang::exceptions::NullPointerException );
+
+        /**
+         * Override this method to customize the functionality of the method
+         * read().
+         */
+        virtual int doReadChar() throw( decaf::io::IOException );
+
+        /**
+         * Override this method to customize the functionality of the method
+         * read( CharBuffer* charBuffer ).
+         */
+        virtual int doReadCharBuffer( decaf::nio::CharBuffer* charBuffer )
+            throw( decaf::io::IOException,
+                   decaf::lang::exceptions::NullPointerException,
+                   decaf::nio::ReadOnlyBufferException );
+
     };
 
 }}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Writer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Writer.cpp?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Writer.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Writer.cpp Thu Feb 18 20:34:48 2010
@@ -17,6 +17,8 @@
 
 #include "Writer.h"
 
+#include <memory>
+
 #include <decaf/lang/CharSequence.h>
 
 using namespace std;
@@ -29,10 +31,9 @@
 void Writer::write( char v ) throw( IOException ) {
 
     try {
-        this->write( (const char*)&v, 0, 1 );
+        this->doWriteChar( v );
     }
     DECAF_CATCH_RETHROW( IOException )
-    DECAF_CATCH_RETHROW( NullPointerException )
     DECAF_CATCHALL_THROW( IOException )
 }
 
@@ -40,10 +41,37 @@
 void Writer::write( const std::vector<char>& buffer ) throw( IOException ) {
 
     try {
-        this->write( &buffer[0], 0, buffer.size() );
+        this->doWriteVector( buffer );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Writer::write( const char* buffer, std::size_t size )
+    throw( decaf::io::IOException,
+           decaf::lang::exceptions::NullPointerException ) {
+
+    try {
+        this->doWriteArraySize( buffer, size );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Writer::write( const char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+    throw( decaf::io::IOException,
+           decaf::lang::exceptions::NullPointerException,
+           decaf::lang::exceptions::IndexOutOfBoundsException ) {
+
+    try {
+        this->doWriteArraySizeOffsetLength( buffer, size, offset, length );
     }
     DECAF_CATCH_RETHROW( IOException )
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCHALL_THROW( IOException )
 }
 
@@ -51,7 +79,7 @@
 void Writer::write( const std::string& str ) throw( IOException ) {
 
     try {
-        this->write( str.c_str(), 0, str.length() );
+        this->doWriteString( str );
     }
     DECAF_CATCH_RETHROW( IOException )
     DECAF_CATCHALL_THROW( IOException )
@@ -68,7 +96,7 @@
                 __FILE__, __LINE__, "Given Offset + Length value greater than the String length." );
         }
 
-        this->write( str.c_str(), offset, length );
+        this->doWriteStringOffsetLength( str.c_str(), offset, length );
     }
     DECAF_CATCH_RETHROW( IOException )
     DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
@@ -79,8 +107,7 @@
 Appendable& Writer::append( char value ) throw( decaf::io::IOException ) {
 
     try {
-        this->write( value );
-        return *this;
+        return this->doAppendChar( value );
     }
     DECAF_CATCH_RETHROW( IOException )
     DECAF_CATCHALL_THROW( IOException )
@@ -91,11 +118,103 @@
     throw ( decaf::io::IOException ) {
 
     try {
+        return this->doAppendCharSequence( csq );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Appendable& Writer::append( const decaf::lang::CharSequence* csq, std::size_t start, std::size_t end )
+    throw( decaf::io::IOException,
+           decaf::lang::exceptions::IndexOutOfBoundsException ) {
+
+    try {
+        return this->doAppendCharSequenceStartEnd( csq, start, end );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Writer::doWriteChar( char v ) throw( decaf::io::IOException ) {
+
+    try {
+        this->doWriteArraySizeOffsetLength( (const char*)&v, 1, 0, 1 );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Writer::doWriteVector( const std::vector<char>& buffer )
+    throw( decaf::io::IOException ) {
+
+    try {
+        this->doWriteArraySizeOffsetLength( &buffer[0], buffer.size(), 0, buffer.size() );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Writer::doWriteArraySize( const char* buffer, std::size_t size )
+    throw( decaf::io::IOException,
+           decaf::lang::exceptions::NullPointerException ) {
+
+    try {
+        this->doWriteArraySizeOffsetLength( buffer, size, 0, size );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Writer::doWriteString( const std::string& str ) throw( decaf::io::IOException ) {
+
+    try {
+        this->doWriteArraySizeOffsetLength( str.c_str(), str.length(), 0, str.length() );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Writer::doWriteStringOffsetLength( const std::string& str, std::size_t offset, std::size_t length )
+    throw( decaf::io::IOException,
+           decaf::lang::exceptions::IndexOutOfBoundsException ) {
+
+    try {
+        this->doWriteArraySizeOffsetLength( str.c_str(), str.length(), offset, length );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+decaf::lang::Appendable& Writer::doAppendChar( char value ) throw( decaf::io::IOException ) {
+
+    try {
+        this->doWriteChar( value );
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+decaf::lang::Appendable& Writer::doAppendCharSequence( const decaf::lang::CharSequence* csq )
+    throw ( decaf::io::IOException ) {
+
+    try {
 
         if( csq == NULL ) {
-            this->write( std::string( "null" ) );
+            this->doWriteString( std::string( "null" ) );
         } else {
-            this->write( csq->toString() );
+            this->doWriteString( csq->toString() );
         }
 
         return *this;
@@ -105,18 +224,18 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Appendable& Writer::append( const decaf::lang::CharSequence* csq, std::size_t start, std::size_t end )
+decaf::lang::Appendable& Writer::doAppendCharSequenceStartEnd( const decaf::lang::CharSequence* csq,
+                                                               std::size_t start, std::size_t end )
     throw( decaf::io::IOException,
            decaf::lang::exceptions::IndexOutOfBoundsException ) {
 
     try {
 
         if( csq == NULL ) {
-            this->write( string( "null" ).substr( start, end - start ) );
+            this->doWriteString( string( "null" ).substr( start, end - start ) );
         } else {
-            CharSequence* result = csq->subSequence( start, end );
-            this->write( result->toString() );
-            delete result;
+            std::auto_ptr<CharSequence> result( csq->subSequence( start, end ) );
+            this->doWriteString( result->toString() );
         }
 
         return *this;
@@ -125,4 +244,3 @@
     DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCHALL_THROW( IOException )
 }
-

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Writer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Writer.h?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Writer.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Writer.h Thu Feb 18 20:34:48 2010
@@ -53,7 +53,7 @@
          *
          * @throws IOException thrown if an error occurs.
          */
-        virtual void write( char v ) throw( decaf::io::IOException );
+        void write( char v ) throw( decaf::io::IOException );
 
         /**
          * Writes an array of Chars
@@ -63,7 +63,7 @@
          *
          * @throws IOException thrown if an error occurs.
          */
-        virtual void write( const std::vector<char>& buffer )
+        void write( const std::vector<char>& buffer )
             throw( decaf::io::IOException );
 
         /**
@@ -71,6 +71,23 @@
          *
          * @param buffer
          *      The byte array to write (cannot be NULL).
+         * @param size
+         *      The size in bytes of the buffer passed.
+         *
+         * @throws IOException if an I/O error occurs.
+         * @throws NullPointerException if buffer is NULL.
+         */
+        void write( const char* buffer, std::size_t size )
+            throw( decaf::io::IOException,
+                   decaf::lang::exceptions::NullPointerException );
+
+        /**
+         * Writes a byte array to the output stream.
+         *
+         * @param buffer
+         *      The byte array to write (cannot be NULL).
+         * @param size
+         *      The size in bytes of the buffer passed.
          * @param offset
          *      The position in the array to start writing from.
          * @param length
@@ -78,9 +95,12 @@
          *
          * @throws IOException if an I/O error occurs.
          * @throws NullPointerException if buffer is NULL.
+         * @throws IndexOutOfBoundsException if offset + length > size of the buffer.
          */
-        virtual void write( const char* buffer, std::size_t offset, std::size_t length )
-            throw( decaf::io::IOException, decaf::lang::exceptions::NullPointerException ) = 0;
+        void write( const char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+            throw( decaf::io::IOException,
+                   decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException );
 
         /**
          * Writes a string
@@ -90,7 +110,7 @@
          *
          * @throws IOException thrown if an error occurs.
          */
-        virtual void write( const std::string& str ) throw( decaf::io::IOException );
+        void write( const std::string& str ) throw( decaf::io::IOException );
 
         /**
          * Writes a string
@@ -105,20 +125,62 @@
          * @throws IOException thrown if an error occurs.
          * @throws IndexOutOfBoundsException if offset+length is greater than the string length.
          */
-        virtual void write( const std::string& str, std::size_t offset, std::size_t length )
+        void write( const std::string& str, std::size_t offset, std::size_t length )
             throw( decaf::io::IOException,
                    decaf::lang::exceptions::IndexOutOfBoundsException );
 
-        virtual decaf::lang::Appendable& append( char value ) throw( decaf::io::IOException );
+        decaf::lang::Appendable& append( char value ) throw( decaf::io::IOException );
 
-        virtual decaf::lang::Appendable& append( const decaf::lang::CharSequence* csq )
+        decaf::lang::Appendable& append( const decaf::lang::CharSequence* csq )
             throw ( decaf::io::IOException );
 
-        virtual decaf::lang::Appendable& append( const decaf::lang::CharSequence* csq,
+        decaf::lang::Appendable& append( const decaf::lang::CharSequence* csq,
                                                  std::size_t start, std::size_t end )
             throw( decaf::io::IOException,
                    decaf::lang::exceptions::IndexOutOfBoundsException );
 
+    protected:
+
+        /**
+         * Override this method to customize the functionality of the method
+         * write( char* buffer, std::size_t offset, std::size_t length ).
+         *
+         * All subclasses must override this method to provide the basic Writer
+         * functionality.
+         */
+        virtual void doWriteArraySizeOffsetLength( const char* buffer, std::size_t size,
+                                                   std::size_t offset, std::size_t length )
+            throw( decaf::io::IOException,
+                   decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException ) = 0;
+
+    protected:
+
+        virtual void doWriteChar( char v ) throw( decaf::io::IOException );
+
+        virtual void doWriteVector( const std::vector<char>& buffer )
+            throw( decaf::io::IOException );
+
+        virtual void doWriteArraySize( const char* buffer, std::size_t size )
+            throw( decaf::io::IOException,
+                   decaf::lang::exceptions::NullPointerException );
+
+        virtual void doWriteString( const std::string& str ) throw( decaf::io::IOException );
+
+        virtual void doWriteStringOffsetLength( const std::string& str, std::size_t offset, std::size_t length )
+            throw( decaf::io::IOException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException );
+
+        virtual decaf::lang::Appendable& doAppendChar( char value ) throw( decaf::io::IOException );
+
+        virtual decaf::lang::Appendable& doAppendCharSequence( const decaf::lang::CharSequence* csq )
+            throw ( decaf::io::IOException );
+
+        virtual decaf::lang::Appendable& doAppendCharSequenceStartEnd( const decaf::lang::CharSequence* csq,
+                                                                       std::size_t start, std::size_t end )
+            throw( decaf::io::IOException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException );
+
     };
 
 }}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketInputStream.cpp?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketInputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketInputStream.cpp Thu Feb 18 20:34:48 2010
@@ -52,6 +52,7 @@
 using namespace decaf::io;
 using namespace decaf::util;
 using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
 using namespace std;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -159,10 +160,10 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int SocketInputStream::read( unsigned char* buffer,
-                             std::size_t offset,
-                             std::size_t bufferSize )
-    throw ( IOException, lang::exceptions::NullPointerException ) {
+int SocketInputStream::read( unsigned char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+    throw ( decaf::io::IOException,
+            decaf::lang::exceptions::IndexOutOfBoundsException,
+            decaf::lang::exceptions::NullPointerException ) {
 
     // Check for a closed call from socket class, if closed then this read fails.
     if( closed ){
@@ -171,17 +172,29 @@
             "decaf::io::SocketInputStream::read - The Stream has been closed" );
     }
 
-    apr_size_t size = (apr_size_t)bufferSize;
+    if( buffer == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__,
+            "SocketInputStream::read - Buffer passed is Null" );
+    }
+
+    if( length > size - offset ) {
+        throw IndexOutOfBoundsException(
+            __FILE__, __LINE__,
+            "Given size{%d} - offset{%d} is less than length{%d}.", size, offset, length );
+    }
+
+    apr_size_t aprSize = (apr_size_t)length;
     apr_status_t result = APR_SUCCESS;
 
     // Read data from the socket, size on input is size of buffer, when done
     // size is the number of bytes actually read, can be <= bufferSize.
-    result = apr_socket_recv( socket, (char*)buffer + offset, &size );
+    result = apr_socket_recv( socket, (char*)buffer + offset, &aprSize );
 
     // Check for EOF, on windows we only get size==0 so check that to, if we
     // were closed though then we throw an IOException so the caller knows we
     // aren't usable anymore.
-    if( ( APR_STATUS_IS_EOF( result ) || size == 0 ) && !closed ) {
+    if( ( APR_STATUS_IS_EOF( result ) || aprSize == 0 ) && !closed ) {
         return -1;
     }
 
@@ -200,7 +213,7 @@
             SocketError::getErrorString().c_str() );
     }
 
-    return (int)size;
+    return (int)aprSize;
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketInputStream.h?rev=911562&r1=911561&r2=911562&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketInputStream.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketInputStream.h Thu Feb 18 20:34:48 2010
@@ -78,10 +78,11 @@
          * @return the number of bytes read. or -1 if EOF
          * @throws IOException f an error occurs.
          */
-        virtual int read( unsigned char* buffer,
-                          std::size_t offset,
-                          std::size_t bufferSize )
-            throw ( io::IOException, lang::exceptions::NullPointerException );
+        virtual int read( unsigned char* buffer, std::size_t size,
+                          std::size_t offset, std::size_t length )
+            throw ( decaf::io::IOException,
+                    decaf::lang::exceptions::IndexOutOfBoundsException,
+                    decaf::lang::exceptions::NullPointerException );
 
         /**
          * Close - does nothing.  It is the responsibility of the owner



Mime
View raw message