activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r591137 - in /activemq/activemq-cpp/decaf/trunk/src: main/decaf/io/ test/decaf/io/
Date Thu, 01 Nov 2007 19:54:45 GMT
Author: tabish
Date: Thu Nov  1 12:54:44 2007
New Revision: 591137

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

Modified:
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BlockingByteArrayInputStream.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BlockingByteArrayInputStream.h
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BufferedInputStream.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BufferedInputStream.h
    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/FilterInputStream.h
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/InputStream.h
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.cpp
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.h

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BlockingByteArrayInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BlockingByteArrayInputStream.cpp?rev=591137&r1=591136&r2=591137&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BlockingByteArrayInputStream.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BlockingByteArrayInputStream.cpp Thu
Nov  1 12:54:44 2007
@@ -103,7 +103,8 @@
 ////////////////////////////////////////////////////////////////////////////////
 int BlockingByteArrayInputStream::read( unsigned char* buffer,
                                         std::size_t bufferSize )
-                                            throw ( IOException ){
+    throw ( IOException, lang::exceptions::NullPointerException ){
+
     synchronized( this ){
 
         std::size_t ix = 0;

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BlockingByteArrayInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BlockingByteArrayInputStream.h?rev=591137&r1=591136&r2=591137&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BlockingByteArrayInputStream.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BlockingByteArrayInputStream.h Thu
Nov  1 12:54:44 2007
@@ -175,7 +175,7 @@
          * @throws IOException f an error occurs.
          */
         virtual int read( unsigned char* buffer, std::size_t bufferSize )
-            throw ( IOException );
+            throw ( IOException, lang::exceptions::NullPointerException );
 
         /**
          * Closes the target input stream.

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BufferedInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BufferedInputStream.cpp?rev=591137&r1=591136&r2=591137&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BufferedInputStream.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BufferedInputStream.cpp Thu Nov  1
12:54:44 2007
@@ -76,6 +76,13 @@
 unsigned char BufferedInputStream::read() throw ( IOException ){
 
     try{
+
+        if( isClosed() ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "BufferedInputStream::bufferData - Stream is clsoed" );
+        }
+
         // If there's no data left, reset to pointers to the beginning of the
         // buffer.
         normalizeBuffer();
@@ -103,15 +110,28 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 int BufferedInputStream::read( unsigned char* targetBuffer,
-                               std::size_t targetBufferSize ) throw ( IOException ){
+                               std::size_t targetBufferSize )
+    throw ( IOException, NullPointerException ){
 
     try{
 
+        if( isClosed() ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "BufferedInputStream::bufferData - Stream is clsoed" );
+        }
+
         // For zero, do nothing
         if( targetBufferSize == 0 ) {
             return 0;
         }
 
+        if( targetBuffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "BufferedInputStream::read - Passed NULL for target Buffer");
+        }
+
         // If there's no data left, reset to pointers to the beginning of the
         // buffer.
         normalizeBuffer();
@@ -152,6 +172,7 @@
         return totalRead;
     }
     DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
     DECAF_CATCHALL_THROW( IOException )
 }
 
@@ -160,6 +181,13 @@
     throw ( IOException, lang::exceptions::UnsupportedOperationException ){
 
     try{
+
+        if( isClosed() ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "BufferedInputStream::skip - Stream is clsoed" );
+        }
+
         // If there's no data left, reset to pointers to the beginning of the
         // buffer.
         normalizeBuffer();
@@ -205,12 +233,6 @@
                 "BufferedInputStream::bufferData - buffer full" );
         }
 
-        if( inputStream == NULL ){
-            throw IOException(
-                __FILE__, __LINE__,
-                "BufferedInputStream::bufferData - Stream is clsoed" );
-        }
-
         // Get the number of bytes currently available on the input stream
         // that could be read without blocking.
         std::size_t available = inputStream->available();
@@ -221,7 +243,8 @@
         // Read the bytes from the input stream.
         int bytesRead = inputStream->read( getTail(), bytesToRead );
         if( bytesRead == 0 ){
-            throw IOException( __FILE__, __LINE__,
+            throw IOException(
+                __FILE__, __LINE__,
                 "BufferedInputStream::read() - failed reading bytes from stream");
         }
 

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BufferedInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BufferedInputStream.h?rev=591137&r1=591136&r2=591137&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BufferedInputStream.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BufferedInputStream.h Thu Nov  1 12:54:44
2007
@@ -113,9 +113,11 @@
          * @param bufferSize the size of the output buffer.
          * @return The number of bytes read or -1 if EOF
          * @throws IOException thrown if an error occurs.
+         * @throws NullPointerException if buffer is NULL
          */
         virtual int read( unsigned char* buffer, std::size_t bufferSize )
-            throw ( IOException );
+            throw ( IOException,
+                    lang::exceptions::NullPointerException );
 
         /**
          * Skips over and discards n bytes of data from this input stream. The

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=591137&r1=591136&r2=591137&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 Thu Nov 
1 12:54:44 2007
@@ -93,7 +93,8 @@
 ////////////////////////////////////////////////////////////////////////////////
 int ByteArrayInputStream::read( unsigned char* buffer,
                                 std::size_t bufferSize )
-                                   throw ( IOException ){
+    throw ( IOException, lang::exceptions::NullPointerException ){
+
     std::size_t ix = 0;
 
     if( pos == activeBuffer->end() ) {

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=591137&r1=591136&r2=591137&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 Thu Nov  1
12:54:44 2007
@@ -188,7 +188,7 @@
          * @throws IOException thrown if an error occurs.
          */
         virtual int read( unsigned char* buffer, std::size_t bufferSize )
-            throw ( IOException );
+            throw ( IOException, lang::exceptions::NullPointerException );
 
         /**
          * Closes the target input stream.

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/FilterInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/FilterInputStream.h?rev=591137&r1=591136&r2=591137&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/FilterInputStream.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/FilterInputStream.h Thu Nov  1 12:54:44
2007
@@ -21,6 +21,8 @@
 #include <decaf/io/InputStream.h>
 #include <decaf/io/IOException.h>
 #include <decaf/util/concurrent/Mutex.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
 
 namespace decaf{
 namespace io{
@@ -47,6 +49,9 @@
         // Indicates if we own the wrapped stream
         bool own;
 
+        // Indicates that this stream was closed
+        bool closed;
+
     public:
 
         /**
@@ -57,6 +62,7 @@
         FilterInputStream( InputStream* inputStream, bool own = false ) {
             this->inputStream = inputStream;
             this->own = own;
+            this->closed = false;
         }
 
         virtual ~FilterInputStream() {
@@ -107,14 +113,17 @@
          * @param bufferSize the size of the output buffer.
          * @return The number of bytes read or -1 if EOF is detected
          * @throws IOException thrown if an error occurs.
+         * @throws NullPointerException
          */
         virtual int read( unsigned char* buffer, std::size_t bufferSize )
-            throw ( IOException )
+            throw ( IOException,
+                    lang::exceptions::NullPointerException )
         {
             try {
                 return inputStream->read( buffer, bufferSize );
             }
             DECAF_CATCH_RETHROW( IOException )
+            DECAF_CATCH_RETHROW( lang::exceptions::NullPointerException )
             DECAF_CATCHALL_THROW( IOException )
         }
 
@@ -132,6 +141,7 @@
                     }
                     inputStream = NULL;
                 }
+                this->closed = true;
             }
             DECAF_CATCH_RETHROW( IOException )
             DECAF_CATCHALL_THROW( IOException )
@@ -222,6 +232,15 @@
          */
         virtual void notifyAll() throw( lang::Exception ){
             mutex.notifyAll();
+        }
+
+    protected:
+
+        /**
+         * @returns true if this stream has been closed.
+         */
+        virtual bool isClosed() const {
+            return this->closed;
         }
 
     };

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/InputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/InputStream.h?rev=591137&r1=591136&r2=591137&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/InputStream.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/InputStream.h Thu Nov  1 12:54:44
2007
@@ -22,6 +22,7 @@
 #include <decaf/io/Closeable.h>
 #include <decaf/util/concurrent/Synchronizable.h>
 #include <decaf/lang/exceptions/UnsupportedOperationException.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
 #include <decaf/util/Config.h>
 
 namespace decaf{
@@ -61,7 +62,8 @@
          * @throws IOException thrown if an error occurs.
          */
         virtual int read( unsigned char* buffer, std::size_t bufferSize )
-            throw ( IOException ) = 0;
+            throw ( IOException,
+                    lang::exceptions::NullPointerException ) = 0;
 
         /**
          * Skips over and discards n bytes of data from this input stream. The

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.cpp?rev=591137&r1=591136&r2=591137&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.cpp Thu Nov
 1 12:54:44 2007
@@ -17,10 +17,12 @@
 
 #include "BufferedInputStreamTest.h"
 #include <decaf/io/ByteArrayInputStream.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
 
 using namespace std;
 using namespace decaf;
 using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
 using namespace decaf::io;
 using namespace decaf::util;
 
@@ -162,6 +164,24 @@
     } catch( IOException& e ) {
         CPPUNIT_FAIL("Exception during read test");
     }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedInputStreamTest::testReadException() {
+
+    BufferedInputStream bis( NULL );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "should throw NullPointerException",
+        bis.read( NULL, -1 ),
+        NullPointerException );
+
+    bis.close();
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "should throw IOException",
+        bis.read( NULL, 1 ),
+        IOException );
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.h?rev=591137&r1=591136&r2=591137&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.h Thu Nov
 1 12:54:44 2007
@@ -36,6 +36,7 @@
         CPPUNIT_TEST( testAvailable );
         CPPUNIT_TEST( testClose );
         CPPUNIT_TEST( testRead );
+        CPPUNIT_TEST( testReadException );
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -50,6 +51,7 @@
         void testAvailable();
         void testClose();
         void testRead();
+        void testReadException();
 
     public:
 



Mime
View raw message