activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r591636 - in /activemq/activemq-cpp/decaf/trunk/src: main/decaf/io/ test/decaf/io/
Date Sat, 03 Nov 2007 15:40:40 GMT
Author: tabish
Date: Sat Nov  3 08:40:39 2007
New Revision: 591636

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

Modified:
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayInputStream.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayInputStream.h
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.h
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayInputStreamTest.cpp

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayInputStream.cpp?rev=591636&r1=591635&r2=591636&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayInputStream.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayInputStream.cpp Sat Nov 
3 08:40:39 2007
@@ -26,6 +26,7 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 ByteArrayInputStream::ByteArrayInputStream(){
+    this->activeBuffer = NULL;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -47,25 +48,26 @@
 void ByteArrayInputStream::setBuffer( const vector<unsigned char>& buffer ){
 
     // We're using the default buffer.
-    activeBuffer = &buffer;
+    this->activeBuffer = &buffer;
 
     // Begin at the Beginning.
     reset();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ByteArrayInputStream::setByteArray( const unsigned char* lbuffer,
-                                         std::size_t lbufferSize ){
+void ByteArrayInputStream::setByteArray( const unsigned char* buffer,
+                                         std::size_t bufferSize ) {
+
     // We're using the default buffer.
-    activeBuffer = &defaultBuffer;
+    this->activeBuffer = &this->defaultBuffer;
 
     // Remove old data
-    defaultBuffer.clear();
-    defaultBuffer.reserve( lbufferSize );
+    this->defaultBuffer.clear();
+    this->defaultBuffer.reserve( bufferSize );
 
     // Copy data to internal buffer.
-    std::back_insert_iterator< std::vector<unsigned char> > iter( defaultBuffer
);
-    std::copy( lbuffer, lbuffer + lbufferSize, iter );
+    std::back_insert_iterator< std::vector<unsigned char> > iter( this->defaultBuffer
);
+    std::copy( buffer, buffer + bufferSize, iter );
 
     // Begin at the Beginning.
     reset();
@@ -83,8 +85,17 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 unsigned char ByteArrayInputStream::read() throw ( IOException ){
+
+    if( activeBuffer == NULL ){
+        throw IOException(
+            __FILE__, __LINE__,
+            "ByteArrayInputStream::read - Buffer has not been initialized" );
+    }
+
     if( pos == activeBuffer->end() ){
-        throw IOException( __FILE__, __LINE__, "Buffer is empty" );
+        throw IOException(
+            __FILE__, __LINE__,
+            "ByteArrayInputStream::read - Buffer is empty" );
     }
 
     return *(pos++);
@@ -95,29 +106,53 @@
                                 std::size_t bufferSize )
     throw ( IOException, lang::exceptions::NullPointerException ){
 
-    std::size_t 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() );
+    try{
 
-    // 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;
+        if( activeBuffer == NULL ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "ByteArrayInputStream::read - Buffer has not been initialized" );
+        }
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "ByteArrayInputStream::read - Buffer passed is Null" );
+        }
+
+        std::size_t 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() );
+
+        // 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;
+
+        for( ; ix < bufferSize; ++ix, ++pos) {
+            buffer[ix] = *(pos);
+        }
 
-    for( ; ix < bufferSize; ++ix, ++pos) {
-        buffer[ix] = *(pos);
+        return ix;
     }
-
-    return ix;
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCHALL_THROW( IOException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 std::size_t ByteArrayInputStream::skip( std::size_t num )
     throw ( IOException, lang::exceptions::UnsupportedOperationException ){
+
+    if( activeBuffer == NULL ){
+        throw IOException(
+            __FILE__, __LINE__,
+            "ByteArrayInputStream::skip - Buffer has not been initialized" );
+    }
 
     std::size_t ix = 0;
 

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayInputStream.h?rev=591636&r1=591635&r2=591636&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayInputStream.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayInputStream.h Sat Nov  3
08:40:39 2007
@@ -101,67 +101,6 @@
                                    std::size_t bufferSize );
 
         /**
-         * Waits on a signal from this object, which is generated
-         * by a call to Notify.  Must have this object locked before
-         * calling.
-         * @throws Exception
-         */
-        virtual void lock() throw( lang::Exception ){
-            mutex.lock();
-        }
-
-        /**
-         * Unlocks the object.
-         * @throws Exception
-         */
-        virtual void unlock() throw( lang::Exception ){
-            mutex.unlock();
-        }
-
-        /**
-         * Waits on a signal from this object, which is generated
-         * by a call to Notify.  Must have this object locked before
-         * calling.
-         * @throws Exception
-         */
-        virtual void wait() throw( lang::Exception ){
-            mutex.wait();
-        }
-
-        /**
-         * Waits on a signal from this object, which is generated
-         * by a call to Notify.  Must have this object locked before
-         * calling.  This wait will timeout after the specified time
-         * interval.
-         * @param millisecs the time in millisecsonds to wait, or
-         * WAIT_INIFINITE
-         * @throws Exception
-         */
-        virtual void wait( unsigned long millisecs ) throw( lang::Exception ){
-            mutex.wait( millisecs );
-        }
-
-        /**
-         * Signals a waiter on this object that it can now wake
-         * up and continue.  Must have this object locked before
-         * calling.
-         * @throws Exception
-         */
-        virtual void notify() throw( lang::Exception ){
-            mutex.notify();
-        }
-
-        /**
-         * Signals the waiters on this object that it can now wake
-         * up and continue.  Must have this object locked before
-         * calling.
-         * @throws Exception
-         */
-        virtual void notifyAll() throw( lang::Exception ){
-            mutex.notifyAll();
-        }
-
-        /**
          * Indcates the number of bytes avaialable.
          * @return The number of bytes until the end of the internal buffer.
          */
@@ -222,6 +161,69 @@
          */
         virtual std::size_t skip( std::size_t num )
             throw ( io::IOException, lang::exceptions::UnsupportedOperationException );
+
+    protected:
+
+        /**
+         * Waits on a signal from this object, which is generated
+         * by a call to Notify.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void lock() throw( lang::Exception ){
+            mutex.lock();
+        }
+
+        /**
+         * Unlocks the object.
+         * @throws Exception
+         */
+        virtual void unlock() throw( lang::Exception ){
+            mutex.unlock();
+        }
+
+        /**
+         * Waits on a signal from this object, which is generated
+         * by a call to Notify.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void wait() throw( lang::Exception ){
+            mutex.wait();
+        }
+
+        /**
+         * Waits on a signal from this object, which is generated
+         * by a call to Notify.  Must have this object locked before
+         * calling.  This wait will timeout after the specified time
+         * interval.
+         * @param millisecs the time in millisecsonds to wait, or
+         * WAIT_INIFINITE
+         * @throws Exception
+         */
+        virtual void wait( unsigned long millisecs ) throw( lang::Exception ){
+            mutex.wait( millisecs );
+        }
+
+        /**
+         * Signals a waiter on this object that it can now wake
+         * up and continue.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void notify() throw( lang::Exception ){
+            mutex.notify();
+        }
+
+        /**
+         * Signals the waiters on this object that it can now wake
+         * up and continue.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void notifyAll() throw( lang::Exception ){
+            mutex.notifyAll();
+        }
 
     };
 

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.cpp?rev=591636&r1=591635&r2=591636&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.cpp Sat Nov
 3 08:40:39 2007
@@ -22,44 +22,46 @@
 using namespace decaf;
 using namespace decaf::io;
 using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayOutputStream::ByteArrayOutputStream()
-{
+ByteArrayOutputStream::ByteArrayOutputStream() {
     activeBuffer = &defaultBuffer;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteArrayOutputStream::ByteArrayOutputStream( vector<unsigned char>& buffer)
-{
+ByteArrayOutputStream::ByteArrayOutputStream( vector<unsigned char>& buffer) {
     setBuffer( buffer );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ByteArrayOutputStream::setBuffer( vector<unsigned char>& buffer)
-{
+void ByteArrayOutputStream::setBuffer( vector<unsigned char>& buffer) {
     activeBuffer = &buffer;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ByteArrayOutputStream::clear() throw ( IOException )
-{
+void ByteArrayOutputStream::clear() throw ( IOException ) {
     // Empty the contents of the buffer to the output stream.
     activeBuffer->clear();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void ByteArrayOutputStream::write( unsigned char c )
-   throw ( IOException )
-{
+    throw ( IOException ) {
     activeBuffer->push_back( c );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void ByteArrayOutputStream::write( const unsigned char* buffer,
                                    std::size_t len )
-   throw ( IOException )
-{
+    throw ( IOException, lang::exceptions::NullPointerException ) {
+
+    if( buffer == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__,
+            "ByteArrayOutputStream::write - passed buffer is null" );
+    }
+
     std::back_insert_iterator< std::vector<unsigned char> > iter( *activeBuffer
);
     std::copy( buffer, buffer + len, iter );
 }

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.h?rev=591636&r1=591635&r2=591636&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.h Sat Nov  3
08:40:39 2007
@@ -25,8 +25,7 @@
 namespace decaf{
 namespace io{
 
-    class DECAF_API ByteArrayOutputStream : public OutputStream
-    {
+    class DECAF_API ByteArrayOutputStream : public OutputStream {
     private:
 
         /**
@@ -92,6 +91,44 @@
         }
 
         /**
+         * Writes a single byte to the output stream.
+         * @param c the byte.
+         * @throws IOException thrown if an error occurs.
+         */
+        virtual void write( unsigned char c )
+           throw ( IOException );
+
+        /**
+         * Writes an array of bytes to the output stream.
+         * @param buffer The array of bytes to write.
+         * @param len The number of bytes from the buffer to be written.
+         * @throws IOException thrown if an error occurs.
+         * @throws NullPointerException thrown if buffer is Null.
+         */
+        virtual void write( const unsigned char* buffer, std::size_t len )
+            throw ( IOException, lang::exceptions::NullPointerException );
+
+        /**
+         * Invokes flush on the target output stream, has no affect.
+         * @throws IOException
+         */
+        virtual void flush() throw ( IOException ){ /* do nothing */ }
+
+        /**
+         * Clear current Stream contents
+         * @throws IOException
+         */
+        virtual void clear() throw ( IOException );
+
+        /**
+         * Invokes close on the target output stream.
+         * @throws CMSException
+         */
+        void close() throw( lang::Exception ){ /* do nothing */ }
+
+    public:
+
+        /**
          * Waits on a signal from this object, which is generated
          * by a call to Notify.  Must have this object locked before
          * calling.
@@ -150,43 +187,7 @@
         virtual void notifyAll() throw( lang::Exception ){
             mutex.notifyAll();
         }
-
-        /**
-         * Writes a single byte to the output stream.
-         * @param c the byte.
-         * @throws IOException thrown if an error occurs.
-         */
-        virtual void write( unsigned char c )
-           throw ( IOException );
-
-        /**
-         * Writes an array of bytes to the output stream.
-         * @param buffer The array of bytes to write.
-         * @param len The number of bytes from the buffer to be written.
-         * @throws IOException thrown if an error occurs.
-         */
-        virtual void write( const unsigned char* buffer, std::size_t len )
-            throw ( IOException );
-
-        /**
-         * Invokes flush on the target output stream, has no affect.
-         * @throws IOException
-         */
-        virtual void flush() throw ( IOException ){ /* do nothing */ }
-
-        /**
-         * Clear current Stream contents
-         * @throws IOException
-         */
-        virtual void clear() throw ( IOException );
-
-        /**
-         * Invokes close on the target output stream.
-         * @throws CMSException
-         */
-        void close() throw( lang::Exception ){ /* do nothing */ }
-
-   };
+    };
 
 }}
 

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayInputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayInputStreamTest.cpp?rev=591636&r1=591635&r2=591636&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayInputStreamTest.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayInputStreamTest.cpp Sat Nov
 3 08:40:39 2007
@@ -40,6 +40,12 @@
                             stream_a.available() == testBuffer.size() );
     CPPUNIT_ASSERT_MESSAGE( "Unable to create ByteArrayInputStream",
                             stream_b.available() == testBuffer.size() );
+
+    ByteArrayInputStream nullStream;
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should have thrown an IO Exception",
+        nullStream.read(),
+        IOException );
 }
 
 ////////////////////////////////////////////////////////////////////////////////



Mime
View raw message