You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2012/10/03 23:02:44 UTC

svn commit: r1393764 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main: activemq/transport/tcp/TcpTransport.cpp decaf/io/BufferedInputStream.cpp decaf/io/BufferedOutputStream.cpp

Author: tabish
Date: Wed Oct  3 21:02:44 2012
New Revision: 1393764

URL: http://svn.apache.org/viewvc?rev=1393764&view=rev
Log:
Polish up some of the code a bit, better destructor impls.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransport.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedOutputStream.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransport.cpp?rev=1393764&r1=1393763&r2=1393764&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransport.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransport.cpp Wed Oct  3 21:02:44 2012
@@ -42,19 +42,15 @@ using namespace decaf::lang;
 using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
-TcpTransport::TcpTransport( const Pointer<Transport>& next ) :
+TcpTransport::TcpTransport(const Pointer<Transport>& next) :
     TransportFilter(next), connectTimeout(0), closed(false), socket(), dataInputStream(), dataOutputStream() {
-
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 TcpTransport::~TcpTransport() {
-
     try {
         close();
     }
-    AMQ_CATCH_NOTHROW( ActiveMQException )
-    AMQ_CATCH_NOTHROW( Exception )
     AMQ_CATCHALL_NOTHROW()
 }
 
@@ -66,58 +62,52 @@ void TcpTransport::close() {
         this->closed = true;
 
         // Close the socket.
-        if( socket.get() != NULL ) {
+        if (socket.get() != NULL) {
             socket->close();
         }
 
         // Invoke the paren't close first.
         TransportFilter::close();
     }
-    AMQ_CATCH_RETHROW( IOException )
-    AMQ_CATCH_EXCEPTION_CONVERT( Exception, IOException )
-    AMQ_CATCHALL_THROW( IOException )
+    AMQ_CATCH_RETHROW( IOException)
+    AMQ_CATCH_EXCEPTION_CONVERT( Exception, IOException)
+    AMQ_CATCHALL_THROW( IOException)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void TcpTransport::connect( const decaf::net::URI& uri,
-                            const decaf::util::Properties& properties ) {
+void TcpTransport::connect(const decaf::net::URI& uri, const decaf::util::Properties& properties) {
 
     try {
 
-        socket.reset( this->createSocket() );
+        socket.reset(this->createSocket());
 
         // Set all Socket Options from the URI options.
-        this->configureSocket( socket.get(), properties );
+        this->configureSocket(socket.get(), properties);
 
         // Ensure something is actually passed in for the URI
-        if( uri.getAuthority() == "" ) {
-            throw SocketException( __FILE__, __LINE__,
-                "Connection URI was not provided or is invalid: %s", uri.toString().c_str() );
+        if (uri.getAuthority() == "") {
+            throw SocketException(__FILE__, __LINE__, "Connection URI was not provided or is invalid: %s", uri.toString().c_str());
         }
 
         // Connect the socket.
         string host = uri.getHost();
         int port = uri.getPort();
 
-        socket->connect( host, port, connectTimeout );
+        socket->connect(host, port, connectTimeout);
 
         // Cast it to an IO transport so we can wire up the socket
         // input and output streams.
-        IOTransport* ioTransport = dynamic_cast<IOTransport*>( next.get() );
-        if( ioTransport == NULL ){
-            throw ActiveMQException(
-                __FILE__, __LINE__,
-                "TcpTransport::TcpTransport - "
-                "transport must be of type IOTransport");
+        IOTransport* ioTransport = dynamic_cast<IOTransport*>(next.get());
+        if (ioTransport == NULL) {
+            throw ActiveMQException(__FILE__, __LINE__, "TcpTransport::TcpTransport - "
+                    "transport must be of type IOTransport");
         }
 
         // Get the read buffer size.
-        int inputBufferSize = Integer::parseInt(
-            properties.getProperty( "inputBufferSize", "8192" ) );
+        int inputBufferSize = Integer::parseInt(properties.getProperty("inputBufferSize", "8192"));
 
         // Get the write buffer size.
-        int outputBufferSize = Integer::parseInt(
-            properties.getProperty( "outputBufferSize", "8192" ) );
+        int outputBufferSize = Integer::parseInt(properties.getProperty("outputBufferSize", "8192"));
 
         Pointer<InputStream> inputStream(socket->getInputStream());
         Pointer<OutputStream> outputStream(socket->getOutputStream());
@@ -144,12 +134,12 @@ void TcpTransport::connect( const decaf:
         this->dataOutputStream.reset(new DataOutputStream(outputStream.release(), true));
 
         // Give the IOTransport the streams.
-        ioTransport->setInputStream( dataInputStream.get() );
-        ioTransport->setOutputStream( dataOutputStream.get() );
+        ioTransport->setInputStream(dataInputStream.get());
+        ioTransport->setOutputStream(dataOutputStream.get());
     }
-    AMQ_CATCH_RETHROW( ActiveMQException )
-    AMQ_CATCH_EXCEPTION_CONVERT( Exception, ActiveMQException )
-    AMQ_CATCHALL_THROW( ActiveMQException )
+    AMQ_CATCH_RETHROW( ActiveMQException)
+    AMQ_CATCH_EXCEPTION_CONVERT( Exception, ActiveMQException)
+    AMQ_CATCHALL_THROW( ActiveMQException)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -159,59 +149,53 @@ Socket* TcpTransport::createSocket() {
         SocketFactory* factory = SocketFactory::getDefault();
         return factory->createSocket();
     }
-    DECAF_CATCH_RETHROW( IOException )
-    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IOException )
-    DECAF_CATCHALL_THROW( IOException )
+    DECAF_CATCH_RETHROW( IOException)
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IOException)
+    DECAF_CATCHALL_THROW( IOException)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void TcpTransport::configureSocket( Socket* socket, const Properties& properties ) {
+void TcpTransport::configureSocket(Socket* socket, const Properties& properties) {
 
     try {
 
         // Get the linger flag.
-        int soLinger = Integer::parseInt(
-            properties.getProperty( "soLinger", "-1" ) );
+        int soLinger = Integer::parseInt(properties.getProperty("soLinger", "-1"));
 
         // Get the keepAlive flag.
-        bool soKeepAlive = Boolean::parseBoolean(
-            properties.getProperty( "soKeepAlive", "false" ) );
+        bool soKeepAlive = Boolean::parseBoolean(properties.getProperty("soKeepAlive", "false"));
 
         // Get the socket receive buffer size.
-        int soReceiveBufferSize = Integer::parseInt(
-            properties.getProperty( "soReceiveBufferSize", "-1" ) );
+        int soReceiveBufferSize = Integer::parseInt(properties.getProperty("soReceiveBufferSize", "-1"));
 
         // Get the socket send buffer size.
-        int soSendBufferSize = Integer::parseInt(
-            properties.getProperty( "soSendBufferSize", "-1" ) );
+        int soSendBufferSize = Integer::parseInt(properties.getProperty("soSendBufferSize", "-1"));
 
         // Get the socket TCP_NODELAY flag.
-        bool tcpNoDelay = Boolean::parseBoolean(
-            properties.getProperty( "tcpNoDelay", "true" ) );
+        bool tcpNoDelay = Boolean::parseBoolean(properties.getProperty("tcpNoDelay", "true"));
 
         // Get the socket connect timeout in microseconds. (default to infinite wait).
-        this->connectTimeout = Integer::parseInt(
-            properties.getProperty( "soConnectTimeout", "0" ) );
+        this->connectTimeout = Integer::parseInt(properties.getProperty("soConnectTimeout", "0"));
 
         // Set the socket options.
-        socket->setKeepAlive( soKeepAlive );
-        socket->setTcpNoDelay( tcpNoDelay );
+        socket->setKeepAlive(soKeepAlive);
+        socket->setTcpNoDelay(tcpNoDelay);
 
-        if( soLinger > 0 ) {
-            socket->setSoLinger( true, soLinger );
+        if (soLinger > 0) {
+            socket->setSoLinger(true, soLinger);
         }
 
-        if( soReceiveBufferSize > 0 ){
-            socket->setReceiveBufferSize( soReceiveBufferSize );
+        if (soReceiveBufferSize > 0) {
+            socket->setReceiveBufferSize(soReceiveBufferSize);
         }
 
-        if( soSendBufferSize > 0 ){
-            socket->setSendBufferSize( soSendBufferSize );
+        if (soSendBufferSize > 0) {
+            socket->setSendBufferSize(soSendBufferSize);
         }
     }
-    DECAF_CATCH_RETHROW( NullPointerException )
-    DECAF_CATCH_RETHROW( IllegalArgumentException )
-    DECAF_CATCH_RETHROW( SocketException )
-    DECAF_CATCH_EXCEPTION_CONVERT( Exception, SocketException )
-    DECAF_CATCHALL_THROW( SocketException )
+    DECAF_CATCH_RETHROW( NullPointerException)
+    DECAF_CATCH_RETHROW( IllegalArgumentException)
+    DECAF_CATCH_RETHROW( SocketException)
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, SocketException)
+    DECAF_CATCHALL_THROW( SocketException)
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.cpp?rev=1393764&r1=1393763&r2=1393764&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/BufferedInputStream.cpp Wed Oct  3 21:02:44 2012
@@ -28,21 +28,16 @@ using namespace decaf::lang;
 using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
-BufferedInputStream::BufferedInputStream( InputStream* stream, bool own ) :
-    FilterInputStream( stream, own ),
-    pos(0), count(0), markLimit(-1), markPos(-1), bufferSize(8192),
-    buff( new unsigned char[bufferSize] ), proxyBuffer( buff ) {
-
+BufferedInputStream::BufferedInputStream(InputStream* stream, bool own) :
+    FilterInputStream(stream, own), pos(0), count(0), markLimit(-1), markPos(-1), bufferSize(8192), buff(new unsigned char[bufferSize]), proxyBuffer(buff) {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-BufferedInputStream::BufferedInputStream( InputStream* stream, int bufferSize, bool own ) :
-        FilterInputStream( stream, own ),
-        pos(0), count(0), markLimit(-1), markPos(-1), bufferSize(bufferSize), buff(NULL), proxyBuffer(NULL) {
+BufferedInputStream::BufferedInputStream(InputStream* stream, int bufferSize, bool own) :
+    FilterInputStream(stream, own), pos(0), count(0), markLimit(-1), markPos(-1), bufferSize(bufferSize), buff(NULL), proxyBuffer(NULL) {
 
-    if( bufferSize < 0 ) {
-        throw new IllegalArgumentException(
-            __FILE__, __LINE__, "Size must be greater than zero");
+    if (bufferSize < 0) {
+        throw new IllegalArgumentException(__FILE__, __LINE__, "Size must be greater than zero");
     }
 
     this->buff = new unsigned char[bufferSize];
@@ -51,41 +46,42 @@ BufferedInputStream::BufferedInputStream
 
 ////////////////////////////////////////////////////////////////////////////////
 BufferedInputStream::~BufferedInputStream() {
-    try{
+    try {
         this->close();
-        delete [] this->buff;
     }
-    DECAF_CATCH_NOTHROW( IOException )
     DECAF_CATCHALL_NOTHROW()
+
+    delete[] this->buff;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void BufferedInputStream::close() {
 
-    // let parent close the inputStream
-    FilterInputStream::close();
-
-    // Clear the proxy to the buffer, but don't actually delete the buffer yet since
-    // other methods holding onto the buffer while blocked.
-    this->proxyBuffer = NULL;
+    try {
+        // let parent close the inputStream
+        FilterInputStream::close();
+
+        // Clear the proxy to the buffer, but don't actually delete the buffer yet since
+        // other methods holding onto the buffer while blocked.
+        this->proxyBuffer = NULL;
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 int BufferedInputStream::available() const {
 
-    if( this->proxyBuffer == NULL || this->isClosed() ) {
-        throw IOException(
-            __FILE__, __LINE__,
-            "BufferedInputStream::available - Buffer was closed");
+    if (this->proxyBuffer == NULL || this->isClosed()) {
+        throw IOException(__FILE__, __LINE__, "BufferedInputStream::available - Buffer was closed");
     }
 
-    return ( this->count - this->pos ) + inputStream->available();
+    return (this->count - this->pos) + inputStream->available();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void BufferedInputStream::mark( int readLimit ) {
-
-    if( this->proxyBuffer != NULL ) {
+void BufferedInputStream::mark(int readLimit) {
+    if (this->proxyBuffer != NULL) {
         this->markLimit = readLimit;
         this->markPos = this->pos;
     }
@@ -94,16 +90,12 @@ void BufferedInputStream::mark( int read
 ////////////////////////////////////////////////////////////////////////////////
 void BufferedInputStream::reset() {
 
-    if( this->proxyBuffer == NULL ) {
-        throw IOException(
-            __FILE__, __LINE__,
-            "BufferedInputStream::reset - This stream has been closed." );
+    if (this->proxyBuffer == NULL) {
+        throw IOException(__FILE__, __LINE__, "BufferedInputStream::reset - This stream has been closed.");
     }
 
-    if( this->markPos == -1 ) {
-        throw IOException(
-            __FILE__, __LINE__,
-            "BufferedInputStream::reset - The mark position was invalidated." );
+    if (this->markPos == -1) {
+        throw IOException(__FILE__, __LINE__, "BufferedInputStream::reset - The mark position was invalidated.");
     }
 
     this->pos = this->markPos;
@@ -112,79 +104,70 @@ void BufferedInputStream::reset() {
 ////////////////////////////////////////////////////////////////////////////////
 int BufferedInputStream::doReadByte() {
 
-    try{
+    try {
 
         // Use a local reference in case of unsynchronized close.
         InputStream* inputStream = this->inputStream;
         unsigned char* buffer = this->proxyBuffer;
 
-        if( isClosed() || buffer == NULL ){
-            throw IOException(
-                __FILE__, __LINE__,
-                "BufferedInputStream::bufferData - Stream is closed" );
+        if (isClosed() || buffer == NULL) {
+            throw IOException(__FILE__, __LINE__, "BufferedInputStream::bufferData - Stream is closed");
         }
 
         // Are there buffered bytes available?  Or can we read more?
-        if( this->pos >= this->count && bufferData( inputStream, buffer ) == -1 ) {
+        if (this->pos >= this->count && bufferData(inputStream, buffer) == -1) {
             return -1;
         }
 
         // Stream might have closed while we were buffering.
-        if( isClosed() ) {
-            throw IOException(
-                __FILE__, __LINE__,
-                "BufferedInputStream::bufferData - Stream is closed" );
+        if (isClosed()) {
+            throw IOException(__FILE__, __LINE__, "BufferedInputStream::bufferData - Stream is closed");
         }
 
-        if( this->pos != this->count ) {
+        if (this->pos != this->count) {
             return buffer[this->pos++];;
         }
 
         return -1;
     }
-    DECAF_CATCH_RETHROW( IOException )
-    DECAF_CATCHALL_THROW( IOException )
+    DECAF_CATCH_RETHROW( IOException)
+    DECAF_CATCHALL_THROW( IOException)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int BufferedInputStream::doReadArrayBounded( unsigned char* buffer, int size, int offset, int length ) {
+int BufferedInputStream::doReadArrayBounded(unsigned char* buffer, int size, int offset, int length) {
 
-    try{
+    try {
 
         // Use a local reference in case of unsynchronized close.
         unsigned char* lbuffer = this->proxyBuffer;
 
-        if( lbuffer == NULL ){
-            throw IOException(
-                __FILE__, __LINE__, "Stream is closed" );
+        if (lbuffer == NULL) {
+            throw IOException(__FILE__, __LINE__, "Stream is closed");
         }
 
-        if( buffer == NULL ) {
-            throw NullPointerException(
-                __FILE__, __LINE__, "Buffer passed was NULL." );
+        if (buffer == NULL) {
+            throw NullPointerException(__FILE__, __LINE__, "Buffer passed was NULL.");
         }
 
-        if( offset > size || offset < 0 ) {
-            throw IndexOutOfBoundsException(
-                __FILE__, __LINE__, "offset parameter out of Bounds: %d.", offset );
+        if (offset > size || offset < 0) {
+            throw IndexOutOfBoundsException(__FILE__, __LINE__, "offset parameter out of Bounds: %d.", offset);
         }
 
-        if( length < 0 || length > size - offset ) {
-            throw IndexOutOfBoundsException(
-                __FILE__, __LINE__, "length parameter out of Bounds: %d.", length );
+        if (length < 0 || length > size - offset) {
+            throw IndexOutOfBoundsException(__FILE__, __LINE__, "length parameter out of Bounds: %d.", length);
         }
 
         // For zero, do nothing
-        if( length == 0 ) {
+        if (length == 0) {
             return 0;
         }
 
         // Use a local reference in case of unsynchronized close.
         InputStream* inputStream = this->inputStream;
 
-        if( inputStream == NULL ){
-            throw IOException(
-                __FILE__, __LINE__, "Stream is closed" );
+        if (inputStream == NULL) {
+            throw IOException(__FILE__, __LINE__, "Stream is closed");
         }
 
         int required = 0;
@@ -192,16 +175,16 @@ int BufferedInputStream::doReadArrayBoun
         // There are bytes available in the buffer so use them up first and
         // then we check to see if any are available on the stream, if not
         // then just return what we had.
-        if( this->pos < this->count  ) {
+        if (this->pos < this->count) {
 
             int available = this->count - this->pos;
             int copylength = available >= length ? length : available;
 
-            System::arraycopy( lbuffer, this->pos, buffer, offset, copylength );
+            System::arraycopy(lbuffer, this->pos, buffer, offset, copylength);
             this->pos += copylength;
 
-            if( copylength == length || inputStream->available() == 0 ) {
-                return (int)copylength;
+            if (copylength == length || inputStream->available() == 0) {
+                return (int) copylength;
             }
 
             offset += copylength;
@@ -210,63 +193,61 @@ int BufferedInputStream::doReadArrayBoun
             required = length;
         }
 
-        while( true ) {
+        while (true) {
 
             int read = 0;
 
             // If we're not marked and the required size is greater than the
             // buffer, simply read the bytes directly bypassing the buffer.
-            if( this->markPos == -1 && required >= this->bufferSize ) {
+            if (this->markPos == -1 && required >= this->bufferSize) {
 
-                read = inputStream->read( buffer, size, offset, required );
-                if( read == -1 ) {
-                    return required == length ? -1 : (int)( length - required );
+                read = inputStream->read(buffer, size, offset, required);
+                if (read == -1) {
+                    return required == length ? -1 : (int) (length - required);
                 }
 
             } else {
 
-                if( bufferData( inputStream, lbuffer ) == -1 ) {
-                    return required == length ? -1 : (int)( length - required );
+                if (bufferData(inputStream, lbuffer) == -1) {
+                    return required == length ? -1 : (int) (length - required);
                 }
 
                 // Stream might have closed while we were buffering.
-                if( isClosed() || this->proxyBuffer == NULL ){
-                    throw IOException(
-                        __FILE__, __LINE__,
-                        "BufferedInputStream::bufferData - Stream is closed" );
+                if (isClosed() || this->proxyBuffer == NULL) {
+                    throw IOException(__FILE__, __LINE__, "BufferedInputStream::bufferData - Stream is closed");
                 }
 
                 int available = this->count - this->pos;
                 read = available >= required ? required : available;
-                System::arraycopy( lbuffer, this->pos, buffer, offset, read );
+                System::arraycopy(lbuffer, this->pos, buffer, offset, read);
                 this->pos += read;
             }
 
             required -= read;
 
-            if( required == 0 ) {
+            if (required == 0) {
                 return length;
             }
 
-            if( inputStream->available() == 0 ) {
+            if (inputStream->available() == 0) {
                 return length - required;
             }
 
             offset += read;
         }
     }
-    DECAF_CATCH_RETHROW( IOException )
-    DECAF_CATCH_RETHROW( NullPointerException )
-    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
-    DECAF_CATCHALL_THROW( IOException )
+    DECAF_CATCH_RETHROW( IOException)
+    DECAF_CATCH_RETHROW( NullPointerException)
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException)
+    DECAF_CATCHALL_THROW( IOException)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-long long BufferedInputStream::skip( long long amount ) {
+long long BufferedInputStream::skip(long long amount) {
 
-    try{
+    try {
 
-        if( amount == 0 ) {
+        if (amount == 0) {
             return 0;
         }
 
@@ -274,14 +255,12 @@ long long BufferedInputStream::skip( lon
         InputStream* inputStream = this->inputStream;
         unsigned char* lbuffer = this->proxyBuffer;
 
-        if( isClosed() || lbuffer == NULL ){
-            throw IOException(
-                __FILE__, __LINE__,
-                "BufferedInputStream::skip - Stream is closed" );
+        if (isClosed() || lbuffer == NULL) {
+            throw IOException(__FILE__, __LINE__, "BufferedInputStream::skip - Stream is closed");
         }
 
-        if( ( this->count - this->pos ) >= amount ) {
-            this->pos += (int)amount;
+        if ((this->count - this->pos) >= amount) {
+            this->pos += (int) amount;
             return amount;
         }
 
@@ -289,16 +268,16 @@ long long BufferedInputStream::skip( lon
 
         this->pos = this->count;
 
-        if( this->markPos != -1 ) {
+        if (this->markPos != -1) {
 
-            if( amount <= this->markLimit ) {
+            if (amount <= this->markLimit) {
 
-                if( bufferData( inputStream, lbuffer ) == -1 ) {
+                if (bufferData(inputStream, lbuffer) == -1) {
                     return read;
                 }
 
-                if( ( this->count - this->pos ) >= ( amount - read ) ) {
-                    this->pos += (int)( amount - read );
+                if ((this->count - this->pos) >= (amount - read)) {
+                    this->pos += (int) (amount - read);
                     return amount;
                 }
 
@@ -310,21 +289,21 @@ long long BufferedInputStream::skip( lon
             }
         }
 
-        return read + inputStream->skip( amount - read );
+        return read + inputStream->skip(amount - read);
     }
-    DECAF_CATCH_RETHROW( IOException )
-    DECAF_CATCHALL_THROW( IOException )
+    DECAF_CATCH_RETHROW( IOException)
+    DECAF_CATCHALL_THROW( IOException)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int BufferedInputStream::bufferData( InputStream* inputStream, unsigned char*& buffer ) {
+int BufferedInputStream::bufferData(InputStream* inputStream, unsigned char*& buffer) {
 
-    try{
+    try {
 
-        if( this->markPos == -1 || pos - markPos >= markLimit ) {
+        if (this->markPos == -1 || pos - markPos >= markLimit) {
             // Mark position not set or exceeded readlimit
-            int result = inputStream->read( buffer, this->bufferSize );
-            if( result > 0 ) {
+            int result = inputStream->read(buffer, this->bufferSize);
+            if (result > 0) {
                 this->markLimit = 0;
                 this->markPos = -1;
                 this->pos = this->count = 0;
@@ -334,39 +313,39 @@ int BufferedInputStream::bufferData( Inp
             return result;
         }
 
-        if( this->markPos == 0 && this->markLimit > this->bufferSize ) {
+        if (this->markPos == 0 && this->markLimit > this->bufferSize) {
 
             // Increase buffer size to accommodate the readlimit.
             int newLength = this->bufferSize * 2;
-            if( newLength > markLimit ) {
+            if (newLength > markLimit) {
                 newLength = markLimit;
             }
 
             unsigned char* temp = new unsigned char[newLength];
-            System::arraycopy( temp, 0, buffer, 0, count );
-            std::swap( temp, buffer );
-            delete [] temp;
+            System::arraycopy(temp, 0, buffer, 0, count);
+            std::swap(temp, buffer);
+            delete[] temp;
             this->bufferSize = newLength;
 
-            if( this->proxyBuffer != NULL ) {
+            if (this->proxyBuffer != NULL) {
                 this->buff = buffer;
                 this->proxyBuffer = this->buff;
             }
 
-        } else if( this->markPos > 0 ) {
-            System::arraycopy( buffer, markPos, buffer, 0, this->bufferSize - markPos );
+        } else if (this->markPos > 0) {
+            System::arraycopy(buffer, markPos, buffer, 0, this->bufferSize - markPos);
         }
 
         // Set the new position and mark position
         this->pos -= this->markPos;
         this->count = this->markPos = 0;
 
-        int bytesread = inputStream->read( buffer, this->bufferSize, this->pos, this->bufferSize - this->pos );
+        int bytesread = inputStream->read(buffer, this->bufferSize, this->pos, this->bufferSize - this->pos);
 
         this->count = bytesread <= 0 ? this->pos : this->pos + bytesread;
 
         return bytesread;
     }
-    DECAF_CATCH_RETHROW( IOException )
-    DECAF_CATCHALL_THROW( IOException )
+    DECAF_CATCH_RETHROW( IOException)
+    DECAF_CATCHALL_THROW( IOException)
 }

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=1393764&r1=1393763&r2=1393764&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 Wed Oct  3 21:02:44 2012
@@ -27,46 +27,40 @@ using namespace decaf::lang;
 using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
-BufferedOutputStream::BufferedOutputStream( OutputStream* stream, bool own )
-: FilterOutputStream( stream, own ), buffer(NULL), bufferSize(0), head(0), tail(0) {
+BufferedOutputStream::BufferedOutputStream(OutputStream* stream, bool own) :
+    FilterOutputStream(stream, own), buffer(NULL), bufferSize(0), head(0), tail(0) {
 
     // Default to 1k buffer.
-    init( 8192 );
+    init(8192);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-BufferedOutputStream::BufferedOutputStream( OutputStream* stream, int bufSize, bool own ) :
-    FilterOutputStream( stream, own ), buffer(NULL), bufferSize(0), head(0), tail(0) {
+BufferedOutputStream::BufferedOutputStream(OutputStream* stream, int bufSize, bool own) :
+    FilterOutputStream(stream, own), buffer(NULL), bufferSize(0), head(0), tail(0) {
 
     try {
-        this->init( bufSize );
+        this->init(bufSize);
     }
-    DECAF_CATCH_RETHROW( IllegalArgumentException )
-    DECAF_CATCHALL_THROW( IllegalArgumentException )
+    DECAF_CATCH_RETHROW(IllegalArgumentException)
+    DECAF_CATCHALL_THROW(IllegalArgumentException)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 BufferedOutputStream::~BufferedOutputStream() {
 
-    try{
+    try {
         this->close();
-
-        // Destroy the buffer.
-        if( buffer != NULL ){
-            delete [] buffer;
-            buffer = NULL;
-        }
     }
-    DECAF_CATCH_NOTHROW( IOException )
     DECAF_CATCHALL_NOTHROW()
+
+    delete [] buffer;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void BufferedOutputStream::init( int bufSize ) {
+void BufferedOutputStream::init(int bufSize) {
 
-    if( bufSize < 0 ) {
-        throw IllegalArgumentException(
-            __FILE__, __LINE__, "Size of Buffer cannot be negative." );
+    if (bufSize < 0) {
+        throw IllegalArgumentException(__FILE__, __LINE__, "Size of Buffer cannot be negative.");
     }
 
     this->bufferSize = bufSize;
@@ -78,16 +72,18 @@ void BufferedOutputStream::init( int buf
 ////////////////////////////////////////////////////////////////////////////////
 void BufferedOutputStream::emptyBuffer() {
 
-    if( this->outputStream == NULL ) {
-        throw IOException(
-            __FILE__, __LINE__,
-            "BufferedOutputStream::emptyBuffer - OutputStream is closed" );
+    if (this->outputStream == NULL) {
+        throw IOException(__FILE__, __LINE__, "BufferedOutputStream::emptyBuffer - OutputStream is closed");
     }
 
-    if( this->head != this->tail ){
-        this->outputStream->write( this->buffer + this->head, this->tail -this->head );
+    try {
+        if (this->head != this->tail) {
+            this->outputStream->write(this->buffer + this->head, this->tail - this->head);
+        }
+        this->head = this->tail = 0;
     }
-    this->head = this->tail = 0;
+    DECAF_CATCH_RETHROW(IOException)
+    DECAF_CATCHALL_THROW(IOException)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -95,10 +91,8 @@ void BufferedOutputStream::flush() {
 
     try {
 
-        if( isClosed() ){
-            throw IOException(
-                __FILE__, __LINE__,
-                "BufferedOutputStream::write - Stream is clsoed" );
+        if (isClosed()) {
+            throw IOException(__FILE__, __LINE__, "BufferedOutputStream::write - Stream is clsoed");
         }
 
         // Empty the contents of the buffer to the output stream.
@@ -107,100 +101,88 @@ void BufferedOutputStream::flush() {
         // Flush the output stream.
         outputStream->flush();
     }
-    DECAF_CATCH_RETHROW( IOException )
-    DECAF_CATCHALL_THROW( IOException )
+    DECAF_CATCH_RETHROW(IOException)
+    DECAF_CATCHALL_THROW(IOException)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void BufferedOutputStream::doWriteByte( const unsigned char c ) {
+void BufferedOutputStream::doWriteByte(const unsigned char c) {
 
-    try{
+    try {
 
-        if( isClosed() ){
-            throw IOException(
-                __FILE__, __LINE__,
-                "BufferedOutputStream::write - Stream is clsoed" );
+        if (isClosed()) {
+            throw IOException(__FILE__, __LINE__, "BufferedOutputStream::write - Stream is clsoed");
         }
 
-        if( tail >= bufferSize ){
+        if (tail >= bufferSize) {
             emptyBuffer();
         }
 
         buffer[tail++] = c;
     }
-    DECAF_CATCH_RETHROW( IOException )
-    DECAF_CATCHALL_THROW( IOException )
+    DECAF_CATCH_RETHROW(IOException)
+    DECAF_CATCHALL_THROW(IOException)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void BufferedOutputStream::doWriteArray( const unsigned char* buffer, int size ) {
+void BufferedOutputStream::doWriteArray(const unsigned char* buffer, int size) {
 
-    try{
+    try {
 
-        if( size == 0 ) {
+        if (size == 0) {
             return;
         }
 
-        if( isClosed() ){
-            throw IOException(
-                __FILE__, __LINE__,
-                "BufferedOutputStream::write - Stream is clsoed" );
+        if (isClosed()) {
+            throw IOException(__FILE__, __LINE__, "BufferedOutputStream::write - Stream is clsoed");
         }
 
-        this->doWriteArrayBounded( buffer, size, 0, size );
+        this->doWriteArrayBounded(buffer, size, 0, size);
     }
-    DECAF_CATCH_RETHROW( IOException )
-    DECAF_CATCHALL_THROW( IOException )
+    DECAF_CATCH_RETHROW(IOException)
+    DECAF_CATCHALL_THROW(IOException)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void BufferedOutputStream::doWriteArrayBounded( const unsigned char* buffer, int size,
-                                                int offset, int length ) {
+void BufferedOutputStream::doWriteArrayBounded(const unsigned char* buffer, int size, int offset, int length) {
 
-    try{
+    try {
 
-        if( length == 0 ) {
+        if (length == 0) {
             return;
         }
 
-        if( isClosed() ){
-            throw IOException(
-                __FILE__, __LINE__,
-                "BufferedOutputStream::write - Stream is clsoed" );
+        if (isClosed()) {
+            throw IOException(__FILE__, __LINE__, "BufferedOutputStream::write - Stream is clsoed");
         }
 
-        if( buffer == NULL ) {
-            throw NullPointerException(
-                __FILE__, __LINE__,
-                "BufferedOutputStream::write - Buffer passed is Null.");
+        if (buffer == NULL) {
+            throw NullPointerException(__FILE__, __LINE__, "BufferedOutputStream::write - Buffer passed is Null.");
         }
 
-        if( size < 0 ) {
-            throw IndexOutOfBoundsException(
-                __FILE__, __LINE__, "size parameter out of Bounds: %d.", size );
+        if (size < 0) {
+            throw IndexOutOfBoundsException(__FILE__, __LINE__, "size parameter out of Bounds: %d.", size);
         }
 
-        if( offset > size || offset < 0 ) {
-            throw IndexOutOfBoundsException(
-                __FILE__, __LINE__, "offset parameter out of Bounds: %d.", offset );
+        if (offset > size || offset < 0) {
+            throw IndexOutOfBoundsException(__FILE__, __LINE__, "offset parameter out of Bounds: %d.", offset);
         }
 
-        if( length < 0 || length > size - offset ) {
-            throw IndexOutOfBoundsException(
-                __FILE__, __LINE__, "length parameter out of Bounds: %d.", length );
+        if (length < 0 || length > size - offset) {
+            throw IndexOutOfBoundsException(__FILE__, __LINE__, "length parameter out of Bounds: %d.", length);
         }
 
         // Iterate until all the data is written.
-        for( int pos = 0; pos < length; ){
+        for (int pos = 0; pos < length;) {
 
-            if( tail >= bufferSize ){
+            if (tail >= bufferSize) {
                 emptyBuffer();
             }
 
             // Get the number of bytes left to write.
-            int bytesToWrite = Math::min( bufferSize - tail, length - pos );
+            int bytesToWrite = Math::min(bufferSize - tail, length - pos);
 
-            System::arraycopy( buffer, offset + pos, this->buffer, this->tail, bytesToWrite );
+            System::arraycopy(buffer, offset + pos, this->buffer, this->tail, bytesToWrite);
 
             // Increase the tail position.
             tail += bytesToWrite;
@@ -209,8 +191,8 @@ void BufferedOutputStream::doWriteArrayB
             pos += bytesToWrite;
         }
     }
-    DECAF_CATCH_RETHROW( IOException )
-    DECAF_CATCH_RETHROW( NullPointerException )
-    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
-    DECAF_CATCHALL_THROW( IOException )
+    DECAF_CATCH_RETHROW(IOException)
+    DECAF_CATCH_RETHROW(NullPointerException)
+    DECAF_CATCH_RETHROW(IndexOutOfBoundsException)
+    DECAF_CATCHALL_THROW(IOException)
 }