activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r591033 - in /activemq/activemq-cpp/decaf/trunk/src: main/decaf/io/BufferedInputStream.cpp main/decaf/io/BufferedInputStream.h main/decaf/io/FilterInputStream.h test/decaf/io/BufferedInputStreamTest.cpp test/decaf/io/BufferedInputStreamTest.h
Date Thu, 01 Nov 2007 14:53:56 GMT
Author: tabish
Date: Thu Nov  1 07:53:54 2007
New Revision: 591033

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

Modified:
    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/FilterInputStream.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/BufferedInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/BufferedInputStream.cpp?rev=591033&r1=591032&r2=591033&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
07:53:54 2007
@@ -22,32 +22,30 @@
 using namespace decaf;
 using namespace decaf::io;
 using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
 BufferedInputStream::BufferedInputStream( InputStream* stream, bool own )
-: FilterInputStream( stream, own )
-{
+: FilterInputStream( stream, own ) {
     // Default to a 1k buffer.
     init( 1024 );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 BufferedInputStream::BufferedInputStream( InputStream* stream,
-    std::size_t bufferSize,
-    bool own )
-: FilterInputStream( stream, own )
-{
-    init( bufferSize );
+                                          std::size_t bufferSize,
+                                          bool own )
+: FilterInputStream( stream, own ) {
+    this->init( bufferSize );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-BufferedInputStream::~BufferedInputStream()
-{
-    // Destroy the buffer.
-    if( buffer != NULL ){
-        delete [] buffer;
-        buffer = NULL;
+BufferedInputStream::~BufferedInputStream() {
+    try{
+        this->close();
     }
+    DECAF_CATCH_NOTHROW( IOException )
+    DECAF_CATCHALL_NOTHROW()
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -62,6 +60,19 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+void BufferedInputStream::close() throw( IOException ) {
+
+    // let parent close the inputStream
+    FilterInputStream::close();
+
+    // Destroy the buffer.
+    if( buffer != NULL ){
+        delete [] buffer;
+        buffer = NULL;
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
 unsigned char BufferedInputStream::read() throw ( IOException ){
 
     try{
@@ -189,8 +200,15 @@
 
     try{
         if( getUnusedBytes() == 0 ){
-            throw IOException( __FILE__, __LINE__,
+            throw IOException(
+                __FILE__, __LINE__,
                 "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

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=591033&r1=591032&r2=591033&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 07:53:54
2007
@@ -19,6 +19,7 @@
 #define _DECAF_IO_BUFFEREDINPUTSTREAM_H_
 
 #include <decaf/io/FilterInputStream.h>
+#include <decaf/lang/exceptions/IllegalArgumentException.h>
 #include <assert.h>
 
 namespace decaf{
@@ -30,8 +31,7 @@
      * in order to reduce the number of io operations on the
      * input stream.
      */
-    class DECAF_API BufferedInputStream : public FilterInputStream
-    {
+    class DECAF_API BufferedInputStream : public FilterInputStream {
     private:
 
         /**
@@ -68,10 +68,11 @@
          * @param stream the target input stream
          * @param bufferSize the size for the internal buffer.
          * @param own indicates if we own the stream object, defaults to false.
+         * @throws IllegalArgumentException is the size is negative.
          */
         BufferedInputStream( InputStream* stream,
                              std::size_t bufferSize,
-                             bool own = false);
+                             bool own = false );
 
         virtual ~BufferedInputStream();
 
@@ -82,8 +83,20 @@
          * input stream.
          */
         virtual std::size_t available() const throw ( IOException ) {
+            if( buffer == NULL ) {
+                throw IOException(
+                    __FILE__, __LINE__,
+                    "BufferedInputStream::available - Buffer was closed");
+            }
             return ( tail - head ) + inputStream->available();
         }
+
+        /**
+         * Close this BufferedInputStream. This implementation closes the target
+         * stream and releases any resources associated with it.
+         * @throws IOException If an error occurs attempting to close this stream.
+         */
+        virtual void close() throw( IOException );
 
         /**
          * Reads a single byte from the buffer.  Blocks until

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=591033&r1=591032&r2=591033&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 07:53:54
2007
@@ -61,7 +61,7 @@
 
         virtual ~FilterInputStream() {
             try {
-                if( own == true ) delete inputStream;
+                this->close();
             }
             DECAF_CATCH_NOTHROW( IOException )
             DECAF_CATCHALL_NOTHROW( )
@@ -125,7 +125,13 @@
          */
         virtual void close() throw ( lang::Exception ) {
             try {
-                inputStream->close();
+                if( inputStream != NULL ) {
+                    inputStream->close();
+                    if( own ) {
+                        delete inputStream;
+                    }
+                    inputStream = NULL;
+                }
             }
             DECAF_CATCH_RETHROW( IOException )
             DECAF_CATCHALL_THROW( IOException )
@@ -149,7 +155,7 @@
          */
         virtual std::size_t skip( std::size_t num ) throw ( io::IOException, lang::exceptions::UnsupportedOperationException
) {
             try {
-                return inputStream->skip(num);
+                return inputStream->skip( num );
             }
             DECAF_CATCH_RETHROW( lang::exceptions::UnsupportedOperationException )
             DECAF_CATCH_RETHROW( IOException )

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=591033&r1=591032&r2=591033&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 07:53:54 2007
@@ -100,6 +100,26 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+void BufferedInputStreamTest::testClose() {
+
+    try{
+        std::string testStr = "TEST12345678910";
+        MyInputStream myStream( testStr );
+
+        // Test for method void java.io.BufferedInputStream.close()
+        BufferedInputStream i1( &myStream );
+        BufferedInputStream i2( &myStream );
+
+        // Test a null stream
+        MyInputStream* ptr = NULL;
+        BufferedInputStream buf( ptr, (std::size_t)5 );
+        buf.close();
+    } catch(...) {
+        CPPUNIT_FAIL("Close shouldn't throw an error here" );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void BufferedInputStreamTest::testSmallerBuffer(){
 
     std::string testStr = "TEST12345678910";

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=591033&r1=591032&r2=591033&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 07:53:54 2007
@@ -34,10 +34,23 @@
         CPPUNIT_TEST( testBiggerBuffer );
         CPPUNIT_TEST( testConstructor );
         CPPUNIT_TEST( testAvailable );
+        CPPUNIT_TEST( testClose );
         CPPUNIT_TEST_SUITE_END();
 
     public:
 
+        virtual ~BufferedInputStreamTest(){}
+        virtual void setUp(){}
+        virtual void tearDown(){}
+
+        void testSmallerBuffer();
+        void testBiggerBuffer();
+        void testConstructor();
+        void testAvailable();
+        void testClose();
+
+    public:
+
         class MyInputStream : public InputStream{
         private:
             std::string data;
@@ -135,18 +148,6 @@
             virtual void notifyAll() throw(lang::Exception){
             }
         };
-
-    public:
-
-        virtual ~BufferedInputStreamTest(){}
-        virtual void setUp(){}
-        virtual void tearDown(){}
-
-        void testSmallerBuffer();
-        void testBiggerBuffer();
-        void testConstructor();
-        void testAvailable();
-
     };
 
 }}



Mime
View raw message