activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r907849 [1/2] - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/ main/decaf/io/ main/decaf/lang/ main/decaf/util/ main/decaf/util/logging/ test-benchmarks/ test-benchmarks/decaf/io/ test/ test/decaf/io/
Date Mon, 08 Feb 2010 23:53:36 GMT
Author: tabish
Date: Mon Feb  8 23:53:34 2010
New Revision: 907849

URL: http://svn.apache.org/viewvc?rev=907849&view=rev
Log:
1. Improve performance and pointer safety in ByteArrayInputStream.
2. Fix some tests that weren't being safe with NULL pointers.
3. Add performance test for ByteArrayInputStream
4. Update the Reader and Writer interface API and Docs
5. Implement InputStreamReader and OutputStreamWriter
6. Tests for above new classes.
7. Implement more of the Logging API.
8. Forward declare some classes in Properties to reduce recompile times.

Added:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStreamReader.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStreamReader.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStreamWriter.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStreamWriter.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Reader.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Writer.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Readable.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/Handler.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/decaf/io/ByteArrayInputStreamBenchmark.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/decaf/io/ByteArrayInputStreamBenchmark.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/InputStreamReaderTest.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/InputStreamReaderTest.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/OutputStreamWriterTest.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/OutputStreamWriterTest.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ReaderTest.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ReaderTest.h   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/WriterTest.cpp   (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/WriterTest.h   (with props)
Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/ByteArrayInputStream.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Reader.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Writer.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/ConsoleHandler.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/Handler.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/StreamHandler.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/StreamHandler.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/Makefile.am
    activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/testRegistry.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/BufferedOutputStreamTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am?rev=907849&r1=907848&r2=907849&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am Mon Feb  8 23:53:34 2010
@@ -505,6 +505,10 @@
     decaf/io/ByteArrayOutputStream.cpp \
     decaf/io/DataInputStream.cpp \
     decaf/io/DataOutputStream.cpp \
+    decaf/io/InputStreamReader.cpp \
+    decaf/io/OutputStreamWriter.cpp \
+    decaf/io/Reader.cpp \
+    decaf/io/Writer.cpp \
     decaf/lang/Boolean.cpp \
     decaf/lang/Byte.cpp \
     decaf/lang/Character.cpp \
@@ -556,6 +560,7 @@
     decaf/util/concurrent/locks/ReentrantLock.cpp \
     decaf/util/logging/ConsoleHandler.cpp \
     decaf/util/logging/ErrorManager.cpp \
+    decaf/util/logging/Handler.cpp \
     decaf/util/logging/Level.cpp \
     decaf/util/logging/LogManager.cpp \
     decaf/util/logging/LogRecord.cpp \
@@ -1135,8 +1140,10 @@
     decaf/io/Flushable.h \
     decaf/io/IOException.h \
     decaf/io/InputStream.h \
+    decaf/io/InputStreamReader.h \
     decaf/io/InterruptedIOException.h \
     decaf/io/OutputStream.h \
+    decaf/io/OutputStreamWriter.h \
     decaf/io/Reader.h \
     decaf/io/UTFDataFormatException.h \
     decaf/io/UnsupportedEncodingException.h \
@@ -1156,6 +1163,7 @@
     decaf/lang/Math.h \
     decaf/lang/Number.h \
     decaf/lang/Pointer.h \
+    decaf/lang/Readable.h \
     decaf/lang/Runnable.h \
     decaf/lang/Runtime.h \
     decaf/lang/Short.h \

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=907849&r1=907848&r2=907849&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 Mon Feb  8 23:53:34 2010
@@ -56,8 +56,12 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ByteArrayInputStream::setByteArray( const unsigned char* buffer,
-                                         std::size_t bufferSize ) {
+void ByteArrayInputStream::setByteArray( const unsigned char* buffer, std::size_t bufferSize ) {
+
+    if( buffer == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "Input Buffer cannot be NULL." );
+    }
 
     // We're using the default buffer.
     this->activeBuffer = &this->defaultBuffer;
@@ -67,8 +71,7 @@
     this->defaultBuffer.reserve( bufferSize );
 
     // Copy data to internal buffer.
-    std::back_insert_iterator< std::vector<unsigned char> > iter( this->defaultBuffer );
-    std::copy( buffer, buffer + bufferSize, iter );
+    this->defaultBuffer.insert( this->defaultBuffer.begin(), buffer, buffer + bufferSize );
 
     // Start the stream off at the beginning marking begin as the reset point.
     this->markpos = this->activeBuffer->begin();
@@ -76,36 +79,45 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ByteArrayInputStream::reset() throw ( IOException){
-    if( activeBuffer == NULL ){
-        throw IOException( __FILE__, __LINE__, "Buffer has not been initialized" );
-    }
+void ByteArrayInputStream::reset() throw ( IOException ){
+
+    try{
 
-    // Begin at the Beginning if mark hasn't been called otherwise it
-    // starts at the marked pos.
-    pos = this->markpos;
+        if( activeBuffer == NULL ){
+            throw IOException( __FILE__, __LINE__, "Buffer has not been initialized" );
+        }
+
+        // Begin at the Beginning if mark hasn't been called otherwise it
+        // starts at the marked pos.
+        pos = this->markpos;
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 int ByteArrayInputStream::read() throw ( IOException ){
 
-    if( activeBuffer == NULL ){
-        throw IOException(
-            __FILE__, __LINE__,
-            "ByteArrayInputStream::read - Buffer has not been initialized" );
-    }
+    try{
 
-    if( pos == activeBuffer->end() ){
-        return -1;
-    }
+        if( activeBuffer == NULL ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "ByteArrayInputStream::read - Buffer has not been initialized" );
+        }
 
-    return *(pos++);
+        if( pos == activeBuffer->end() ){
+            return -1;
+        }
+
+        return *(pos++);
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-int ByteArrayInputStream::read( unsigned char* buffer,
-                                std::size_t offset,
-                                std::size_t bufferSize )
+int ByteArrayInputStream::read( unsigned char* buffer, std::size_t offset, std::size_t bufferSize )
     throw ( IOException, lang::exceptions::NullPointerException ){
 
     try{
@@ -150,17 +162,22 @@
 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" );
-    }
+    try{
 
-    std::size_t ix = 0;
+        if( activeBuffer == NULL ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "ByteArrayInputStream::skip - Buffer has not been initialized" );
+        }
 
-    // Increment the position until we've skipped the desired number
-    // or we've hit the end of the buffer.
-    for( ; ix < num && pos != activeBuffer->end(); ++ix, ++pos) {}
+        std::size_t ix = 0;
 
-    return ix;
+        // Increment the position until we've skipped the desired number
+        // or we've hit the end of the buffer.
+        for( ; ix < num && pos != activeBuffer->end(); ++ix, ++pos) {}
+
+        return ix;
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
 }

Added: 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=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStreamReader.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStreamReader.cpp Mon Feb  8 23:53:34 2010
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "InputStreamReader.h"
+
+#include <decaf/io/InputStream.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+
+using namespace decaf;
+using namespace decaf::io;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+InputStreamReader::InputStreamReader( InputStream* stream, bool own ) : Reader(), own( own ) {
+
+    if( stream == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "The passed InputStream cannot be NULL." );
+    }
+
+    this->stream = stream;
+    this->closed = false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+InputStreamReader::~InputStreamReader() {
+
+    try{
+
+        this->close();
+
+        if( this->own ) {
+            delete this->stream;
+        }
+
+        this->stream = NULL;
+    }
+    DECAF_CATCH_NOTHROW( Exception )
+    DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void InputStreamReader::close() throw( decaf::io::IOException ) {
+
+    try{
+
+        if( !closed ) {
+            this->stream->close();
+            this->closed = true;
+        }
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool InputStreamReader::ready() const throw( decaf::io::IOException ) {
+
+    try{
+        checkClosed();
+        try{
+            return this->stream->available() != 0;
+        } catch( IOException& ex ) {
+            return false;
+        }
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int InputStreamReader::read( char* buffer, std::size_t offset, std::size_t length )
+    throw( IOException, lang::exceptions::NullPointerException ) {
+
+    try{
+        checkClosed();
+
+        if( length == 0 ) {
+            return 0;
+        }
+
+        return this->stream->read( (unsigned char*)buffer, offset, length );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void InputStreamReader::checkClosed() const throw( decaf::io::IOException ) {
+    if( closed ) {
+        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 )
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStreamReader.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStreamReader.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStreamReader.h Mon Feb  8 23:53:34 2010
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_IO_INPUTSTREAMREADER_H_
+#define _DECAF_IO_INPUTSTREAMREADER_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/io/Reader.h>
+
+namespace decaf {
+namespace io {
+
+    class InputStream;
+
+    /**
+     * An InputStreamReader is a bridge from byte streams to character streams.
+     *
+     * For top efficiency, consider wrapping an InputStreamReader within a BufferedReader.
+     * For example:
+     *
+     *   BufferedReader* in
+     *       = new BufferedReader( new InputStreamReader( System.in, false ), true );
+     *
+     * @see OutputStreamWriter
+     *
+     * @since 1.0
+     */
+    class DECAF_API InputStreamReader : public Reader {
+    private:
+
+        // The target InputStream
+        InputStream* stream;
+
+        // Does this instance own the InputStream
+        bool own;
+
+        // Has the reader been closed.
+        bool closed;
+
+    public:
+
+        /**
+         * Create a new InputStreamReader that wraps the given InputStream.
+         *
+         * @param stream
+         *      The InputStream to read from. (cannot be null).
+         * @param own
+         *      Does this object own the passed InputStream (defaults to false).
+         *
+         * @throw NullPointerException if the passed InputStream is NULL.
+         */
+        InputStreamReader( InputStream* stream, bool own = false );
+
+        virtual ~InputStreamReader();
+
+        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 void checkClosed() const throw( decaf::io::IOException );
+
+    };
+
+}}
+
+#endif /* _DECAF_IO_INPUTSTREAMREADER_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/InputStreamReader.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStreamWriter.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStreamWriter.cpp Mon Feb  8 23:53:34 2010
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "OutputStreamWriter.h"
+
+#include <decaf/io/OutputStream.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+
+using namespace decaf;
+using namespace decaf::io;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+OutputStreamWriter::OutputStreamWriter( OutputStream* stream, bool own ) : own( own ) {
+
+    if( stream == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "OutputStream pointer cannot be NULL" );
+    }
+
+    this->stream = stream;
+    this->closed = false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OutputStreamWriter::~OutputStreamWriter() {
+
+    try{
+
+        this->close();
+
+        if( this->own ) {
+            delete this->stream;
+        }
+
+        this->stream = NULL;
+    }
+    DECAF_CATCH_NOTHROW( Exception )
+    DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OutputStreamWriter::close() throw( decaf::io::IOException ) {
+
+    try{
+
+        if( !closed ) {
+            this->stream->close();
+            this->closed = true;
+        }
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OutputStreamWriter::flush() throw( decaf::io::IOException ) {
+
+    try{
+        checkClosed();
+        this->stream->flush();
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OutputStreamWriter::write( const char* buffer, std::size_t offset, std::size_t count )
+    throw( IOException, NullPointerException ) {
+
+    try{
+        checkClosed();
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__, "Given buffer was NULL." );
+        }
+
+        this->stream->write( (const unsigned char*)buffer, offset, count );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+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" );
+    }
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStreamWriter.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStreamWriter.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStreamWriter.h Mon Feb  8 23:53:34 2010
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_IO_OUTPUTSTREAMWRITER_H_
+#define _DECAF_IO_OUTPUTSTREAMWRITER_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/io/Writer.h>
+
+namespace decaf {
+namespace io {
+
+    class OutputStream;
+
+    /**
+     * A class for turning a character stream into a byte stream.
+     *
+     * @see InputStreamReader
+     *
+     * @since 1.0
+     */
+    class DECAF_API OutputStreamWriter : public Writer {
+    private:
+
+        // Pointer to the Stream this Writer writes its data to.
+        OutputStream* stream;
+
+        // Does this class own the output stream.
+        bool own;
+
+        // Closed flag
+        volatile bool closed;
+
+    public:
+
+        /**
+         * Creates a new OutputStreamWriter.
+         *
+         * @param stream
+         *      The OutputStream to wrap. (cannot be NULL).
+         * @param own
+         *      Indicates whether this instance own the given OutputStream.
+         *      If true then the OutputStream is destroyed when this class is.
+         *
+         * @throws NullPointerException if the stream is NULL.
+         */
+        OutputStreamWriter( OutputStream* stream, bool own = false );
+
+        virtual ~OutputStreamWriter();
+
+        virtual void close() throw( decaf::io::IOException );
+
+        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:
+
+        // Used to check state and throw error when closed.
+        virtual void checkClosed() const throw( decaf::io::IOException );
+
+    };
+
+}}
+
+#endif /* _DECAF_IO_OUTPUTSTREAMWRITER_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/OutputStreamWriter.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Reader.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Reader.cpp Mon Feb  8 23:53:34 2010
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Reader.h"
+
+#include <decaf/lang/Math.h>
+#include <decaf/nio/CharBuffer.h>
+
+#include <vector>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::io;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::nio;
+
+////////////////////////////////////////////////////////////////////////////////
+Reader::Reader() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Reader::~Reader() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Reader::mark( std::size_t readAheadLimit DECAF_UNUSED )
+    throw( decaf::io::IOException ) {
+
+    throw IOException(
+        __FILE__, __LINE__,
+        "Default implementation of Reader, mark not supported." );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Reader::ready() const throw( decaf::io::IOException ) {
+    return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Reader::reset() throw( decaf::io::IOException ) {
+
+    throw IOException(
+        __FILE__, __LINE__,
+        "Default implementation of Reader, reset not supported." );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t Reader::skip( std::size_t count )
+    throw( decaf::io::IOException ) {
+
+    try{
+
+        std::size_t skipped = 0;
+        int toRead = count < 512 ? (int)count : 512;
+
+        std::vector<char> charsSkipped( toRead );
+
+        while( skipped < count ) {
+
+            int read = this->read( &charsSkipped[0], 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 );
+            }
+        }
+
+        return skipped;
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Reader::read( std::vector<char>& buffer ) throw( decaf::io::IOException ) {
+
+    try{
+
+        if( buffer.size() == 0 ) {
+            return -1;
+        }
+
+        return this->read( &buffer[0], 0, buffer.size() );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Reader::read() throw( IOException ) {
+
+    try{
+        char buffer;
+
+        if( this->read( &buffer, 0, 1 ) == -1 ) {
+            return -1;
+        }
+
+        return buffer;
+    }
+    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{
+
+        if( charBuffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__, "Pointer to CharBuffer cannot be NULL." );
+        }
+
+        if( charBuffer->length() == 0 ) {
+            return 0;
+        }
+
+        int length = (int)charBuffer->length();
+
+        std::vector<char> buffer( length );
+
+        length = Math::min( length, this->read( buffer ) );
+
+        if( length > 0 ) {
+            charBuffer->put( &buffer[0], 0, length );
+        }
+
+        return length;
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCHALL_THROW( IOException )
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Reader.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

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=907849&r1=907848&r2=907849&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 Mon Feb  8 23:53:34 2010
@@ -18,6 +18,8 @@
 #define _DECAF_IO_READER_H
 
 #include <string>
+#include <decaf/lang/Readable.h>
+#include <decaf/io/Closeable.h>
 #include <decaf/io/IOException.h>
 #include <decaf/io/InputStream.h>
 #include <decaf/lang/exceptions/NullPointerException.h>
@@ -26,42 +28,134 @@
 namespace io{
 
     /*
-     * Reader interface that wraps around an input stream and provides an interface
-     * for extracting the data from the input stream.
+     * Abstract class for reading character streams. The only methods that a subclass
+     * must implement are read( char*, size_t, size_t ) and close(). Most subclasses,
+     * however, will override some of the methods defined here in order to provide
+     * higher efficiency, additional functionality, or both.
      *
      * @since 1.0
      */
-    class DECAF_API Reader {
+    class DECAF_API Reader : public virtual decaf::io::Closeable,
+                             public virtual decaf::lang::Readable {
+    protected:
+
+        Reader();
+
     public:
 
-        virtual ~Reader(){}
+        virtual ~Reader();
 
         /**
-         * Sets the target input stream.
+         * Marks the present position in the stream. Subsequent calls to reset() will attempt
+         * to reposition the stream to this point. Not all character-input streams support
+         * the mark() operation.
+         *
+         * @param readAheadLimit
+         *      Limit on the number of characters that may be read while still preserving the
+         *      mark. After reading this many characters, attempting to reset the stream may fail.
+         *
+         * @throw IOException if an I/O error occurs, or the stream does not support mark.
          */
-        virtual void setInputStream( InputStream* is ) = 0;
+        virtual void mark( std::size_t readAheadLimit )
+            throw( decaf::io::IOException );
 
         /**
-         * Gets the target input stream.
+         * Tells whether this stream supports the mark() operation. The default implementation
+         * always returns false. Subclasses should override this method.
+         *
+         * @return true if and only if this stream supports the mark operation.
          */
-        virtual InputStream* getInputStream() = 0;
+        virtual bool markSupported() const {
+            return false;
+        }
 
         /**
-         * Attempts to read an array of bytes from the stream.
-         * @param buffer The target byte buffer.
-         * @param count The number of bytes to read.
-         * @return The number of bytes read.
+         * Tells whether this stream is ready to be read.
+         *
+         * @return True if the next read() is guaranteed not to block for input, false otherwise.
+         *         Note that returning false does not guarantee that the next read will block.
+         *
+         * @throw IOException if an I/O error occurs.
+         */
+        virtual bool ready() const throw( decaf::io::IOException );
+
+        /**
+         * Resets the stream. If the stream has been marked, then attempt to reposition it at the
+         * mark. If the stream has not been marked, then attempt to reset it in some way appropriate
+         * to the particular stream, for example by repositioning it to its starting point. Not all
+         * character-input streams support the reset() operation, and some support reset() without
+         * supporting mark().
+         *
+         * @throw IOException if an I/O error occurs.
+         */
+        virtual void reset() throw( decaf::io::IOException );
+
+        /**
+         * Skips characters. This method will block until some characters are available, an I/O error
+         * occurs, or the end of the stream is reached.
+         *
+         * @param count
+         *      The number of character to skip.
+         *
+         * @return the number of Character actually skipped.
+         *
+         * @throw IOException if an I/O error occurs.
+         */
+       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 a portion of 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 target char buffer.
+         * @param offset
+         *      The position in the buffer to start filling.
+         * @param length
+         *      The maximum number of bytes to read.
+         *
+         * @return The number of bytes read or -1 if the end of stream is reached.
+         *
          * @throws IOException thrown if an error occurs.
+         * @throws NullPointerException if buffer is NULL.
          */
-        virtual std::size_t read( unsigned char* buffer, std::size_t count )
-            throw( IOException, lang::exceptions::NullPointerException ) = 0;
+        virtual int read( char* buffer, std::size_t offset, std::size_t length )
+            throw( decaf::io::IOException,
+                   decaf::lang::exceptions::NullPointerException ) = 0;
 
         /**
-         * Attempts to read a byte from the input stream
-         * @return The byte.
+         * Reads a single character. This method will block until a character is available,
+         * an I/O error occurs, or the end of the stream is reached.
+         *
+         * Subclasses that intend to support efficient single-character input should override
+         * this method.
+         *
+         * @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.
          */
-        virtual unsigned char readByte() throw( IOException ) = 0;
+        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 );
 
     };
 

Added: 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=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Writer.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Writer.cpp Mon Feb  8 23:53:34 2010
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Writer.h"
+
+#include <decaf/lang/CharSequence.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::io;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+void Writer::write( char v ) throw( IOException ) {
+
+    try {
+        this->write( (const char*)&v, 0, 1 );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Writer::write( const std::vector<char>& buffer ) throw( IOException ) {
+
+    try {
+        this->write( &buffer[0], 0, buffer.size() );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Writer::write( const std::string& str ) throw( IOException ) {
+
+    try {
+        this->write( str.c_str(), 0, str.length() );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Writer::write( const std::string& str, std::size_t offset, std::size_t length )
+    throw( IOException, IndexOutOfBoundsException ) {
+
+    try {
+
+        if( ( offset + length ) > str.length() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "Given Offset + Length value greater than the String length." );
+        }
+
+        this->write( str.c_str(), offset, length );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Appendable& Writer::append( char value ) throw( decaf::io::IOException ) {
+
+    try {
+        this->write( value );
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Appendable& Writer::append( const decaf::lang::CharSequence* csq )
+    throw ( decaf::io::IOException ) {
+
+    try {
+
+        if( csq == NULL ) {
+            this->write( std::string( "null" ) );
+        } else {
+            this->write( csq->toString() );
+        }
+
+        return *this;
+    }
+    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 {
+
+        if( csq == NULL ) {
+            this->write( string( "null" ).substr( start, end - start ) );
+        } else {
+            CharSequence* result = csq->subSequence( start, end );
+            this->write( result->toString() );
+            delete result;
+        }
+
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/Writer.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

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=907849&r1=907848&r2=907849&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 Mon Feb  8 23:53:34 2010
@@ -18,52 +18,106 @@
 #define _DECAF_IO_WRITER_H
 
 #include <string>
+#include <vector>
 #include <decaf/io/IOException.h>
-#include <decaf/io/OutputStream.h>
+#include <decaf/io/Closeable.h>
+#include <decaf/io/Flushable.h>
+#include <decaf/lang/Appendable.h>
 #include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
 
 namespace decaf{
 namespace io{
 
     /*
-     * Writer interface for an object that wraps around an output stream.
+     * Abstract class for writing to character streams. The only methods that a
+     * subclass must implement are write( char*, size_t, size_t ), flush(), and
+     * close().  Most subclasses, however, will override some of the methods
+     * defined here in order to provide higher efficiency, additional functionality,
+     * or both.
      *
      * @since 1.0
      */
-    class DECAF_API Writer {
+    class DECAF_API Writer : public decaf::io::Closeable,
+                             public decaf::io::Flushable,
+                             public decaf::lang::Appendable {
     public:
 
         virtual ~Writer(){};
 
         /**
-         * Sets the target output stream.
-         * @param os
-         *      The provided Outputstream to use to write to.
+         * Writes an single byte char value.
+         *
+         * @param v
+         *      The value to be written.
+         *
+         * @throws IOException thrown if an error occurs.
          */
-        virtual void setOutputStream( OutputStream* os ) = 0;
+        virtual void write( char v ) throw( decaf::io::IOException );
 
         /**
-         * Gets the target output stream.
-         * @returns the output stream currently being used
+         * Writes an array of Chars
+         *
+         * @param buffer
+         *      The array to be written.
+         *
+         * @throws IOException thrown if an error occurs.
          */
-        virtual OutputStream* getOutputStream() = 0;
+        virtual void write( const std::vector<char>& buffer )
+            throw( decaf::io::IOException );
 
         /**
          * Writes a byte array to the output stream.
-         * @param buffer a byte array
-         * @param count the number of bytes in the array to write.
+         *
+         * @param buffer
+         *      The byte array to write (cannot be NULL).
+         * @param offset
+         *      The position in the array to start writing from.
+         * @param length
+         *      The number of bytes in the array to write.
+         *
+         * @throws IOException if an I/O error occurs.
+         * @throws NullPointerException if buffer is NULL.
+         */
+        virtual void write( const char* buffer, std::size_t offset, std::size_t length )
+            throw( decaf::io::IOException, decaf::lang::exceptions::NullPointerException ) = 0;
+
+        /**
+         * Writes a string
+         *
+         * @param str
+         *      The string to be written.
+         *
+         * @throws IOException thrown if an error occurs.
+         */
+        virtual void write( const std::string& str ) throw( decaf::io::IOException );
+
+        /**
+         * Writes a string
+         *
+         * @param str
+         *      The string to be written.
+         * @param offset
+         *      The position in the array to start writing from.
+         * @param length
+         *      The number of bytes in the array to write.
+         *
          * @throws IOException thrown if an error occurs.
+         * @throws IndexOutOfBoundsException if offset+length is greater than the string length.
          */
-        virtual void write( const unsigned char* buffer,
-                            std::size_t count )
-            throw( IOException, lang::exceptions::NullPointerException ) = 0;
-
-         /**
-          * Writes a byte to the output stream.
-          * @param v The value to be written.
-          * @throws IOException thrown if an error occurs.
-          */
-         virtual void writeByte( unsigned char v ) throw( IOException ) = 0;
+        virtual 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 );
+
+        virtual decaf::lang::Appendable& append( const decaf::lang::CharSequence* csq )
+            throw ( decaf::io::IOException );
+
+        virtual 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 );
 
     };
 

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Readable.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Readable.h?rev=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Readable.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Readable.h Mon Feb  8 23:53:34 2010
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_LANG_READABLE_H_
+#define _DECAF_LANG_READABLE_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/io/IOException.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/nio/ReadOnlyBufferException.h>
+
+namespace decaf {
+namespace nio {
+    class CharBuffer;
+}
+namespace lang {
+
+    /**
+     * A Readable is a source of characters. Characters from a Readable are made available
+     * to callers of the read method via a CharBuffer.
+     *
+     * @since 1.0
+     */
+    class Readable {
+    public:
+
+        virtual ~Readable() {}
+
+        /**
+         * Attempts to read characters into the specified character buffer. The buffer is used
+         * as a repository of characters as-is: the only changes made are the results of a put
+         * operation.  No flipping or rewinding of the buffer is performed.
+         *
+         * @param charBuffer
+         *      The Buffer to read Characters into.
+         *
+         * @return The number of char values added to the buffer, or -1 if this source of
+         *         characters is at its end
+         *
+         * @throw IOException - if an I/O error occurs
+         * @throws NullPointerException - if buffer is NULL.
+         * @throw ReadOnlyBufferException - if charBuffer is a read only buffer
+         */
+        virtual int read( decaf::nio::CharBuffer* charBuffer )
+                 throw( decaf::io::IOException,
+                        decaf::lang::exceptions::NullPointerException,
+                        decaf::nio::ReadOnlyBufferException ) = 0;
+
+    };
+
+}}
+
+#endif /* _DECAF_LANG_READABLE_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Readable.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.h?rev=907849&r1=907848&r2=907849&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Properties.h Mon Feb  8 23:53:34 2010
@@ -24,14 +24,16 @@
 #include <decaf/util/StlMap.h>
 #include <decaf/io/InputStream.h>
 #include <decaf/io/OutputStream.h>
-#include <decaf/io/Reader.h>
-#include <decaf/io/Writer.h>
 #include <decaf/lang/Pointer.h>
 #include <decaf/lang/exceptions/IllegalArgumentException.h>
 #include <decaf/lang/exceptions/NullPointerException.h>
 #include <decaf/io/IOException.h>
 
 namespace decaf{
+namespace io{
+    class Reader;
+    class Writer;
+}
 namespace util{
 
     class PropertiesInternal;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/ConsoleHandler.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/ConsoleHandler.cpp?rev=907849&r1=907848&r2=907849&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/ConsoleHandler.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/ConsoleHandler.cpp Mon Feb  8 23:53:34 2010
@@ -32,9 +32,6 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ConsoleHandler::close() throw ( decaf::io::IOException )
-{
-    if( getOutputStream() ) {
-        getOutputStream()->flush();
-    }
+void ConsoleHandler::close() throw ( decaf::io::IOException ) {
+    StreamHandler::close( true );
 }

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/Handler.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/Handler.cpp?rev=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/Handler.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/Handler.cpp Mon Feb  8 23:53:34 2010
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Handler.h"
+
+#include <decaf/util/logging/Level.h>
+#include <decaf/util/logging/ErrorManager.h>
+#include <decaf/util/logging/Filter.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::util;
+using namespace decaf::util::logging;
+
+////////////////////////////////////////////////////////////////////////////////
+const Level Handler::DEFAULT_LEVEL = Level::ALL;
+
+////////////////////////////////////////////////////////////////////////////////
+Handler::Handler() : level( DEFAULT_LEVEL ) {
+
+    this->errorManager = new ErrorManager();
+    this->formatter = NULL;
+    this->filter = NULL;
+    this->prefix = "Handler";
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Handler::~Handler() {
+    delete errorManager;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Handler::setFormatter( Formatter* formatter ) {
+
+    if( formatter == NULL ) {
+        throw decaf::lang::exceptions::NullPointerException(
+            __FILE__, __LINE__, "The Formatter cannot be set to NULL." );
+    }
+
+    this->formatter = formatter;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Handler::setErrorManager( ErrorManager* errorManager ) {
+
+    if( errorManager == NULL ) {
+        throw decaf::lang::exceptions::NullPointerException(
+            __FILE__, __LINE__, "Error Manager cannot be set to NULL." );
+    }
+
+    this->errorManager = errorManager;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Handler::isLoggable( const LogRecord& record ) const {
+
+    if( this->level.intValue() == Level::OFF.intValue() ) {
+        return false;
+    } else if( record.getLevel().intValue() >= this->level.intValue()) {
+        return NULL == this->filter || this->filter->isLoggable( record );
+    }
+
+    return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Handler::reportError( const std::string& message, decaf::lang::Exception* ex, int code ) {
+
+    if( this->errorManager != NULL ) {
+        this->errorManager->error( message, ex, code );
+    }
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/Handler.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/Handler.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/Handler.h?rev=907849&r1=907848&r2=907849&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/Handler.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/Handler.h Mon Feb  8 23:53:34 2010
@@ -21,6 +21,9 @@
 #include <decaf/lang/Exception.h>
 #include <decaf/util/logging/LogRecord.h>
 #include <decaf/util/logging/Level.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+
+#include <string>
 
 namespace decaf{
 namespace util{
@@ -44,9 +47,31 @@
      * specific documentation for each concrete Handler class.
      */
     class DECAF_API Handler : public io::Closeable {
+    private:
+
+        // Default Logging Level for Handler
+        static const Level DEFAULT_LEVEL;
+
+        // Formats this Handlers output
+        Formatter* formatter;
+
+        // Filter object for Log Filtering
+        Filter* filter;
+
+        // ErrorManager instance for this Handler
+        ErrorManager* errorManager;
+
+        // Level at which that this Handler will start logging.
+        Level level;
+
+        // Name of this class used to read properties
+        std::string prefix;
+
     public:
 
-        virtual ~Handler() {}
+        Handler();
+
+        virtual ~Handler();
 
         /**
          * Flush the Handler's output, clears any buffers.
@@ -68,23 +93,28 @@
          * LogRecord.
          * @param record <code>LogRecord</code> to check
          */
-        virtual bool isLoggable( const LogRecord& record ) const = 0;
+        virtual bool isLoggable( const LogRecord& record ) const;
 
         /**
          * Sets the Filter that this Handler uses to filter Log Records
-         * <p>
+         *
          * For each call of publish the Handler will call this Filter (if it
          * is non-null) to check if the LogRecord should be published or
          * discarded.
+         *
          * @param filter <code>Filter</code> derived instance
          */
-        virtual void setFilter( Filter* filter ) = 0;
+        virtual void setFilter( Filter* filter ) {
+            this->filter = filter;
+        }
 
         /**
          * Gets the Filter that this Handler uses to filter Log Records
          * @returns <code>Filter</code> derived instance
          */
-        virtual const Filter* getFilter() = 0;
+        virtual Filter* getFilter() {
+            return this->filter;
+        }
 
         /**
          * Set the log level specifying which message levels will be logged
@@ -94,14 +124,18 @@
          * but to limit the messages that are sent to certain Handlers.
          * @param value Level enumeration value
          */
-        virtual void setLevel( const Level& value ) = 0;
+        virtual void setLevel( const Level& value ) {
+            this->level = value;
+        }
 
         /**
          * Get the log level specifying which message levels will be logged
          * by this Handler.
          * @returns Level enumeration value
          */
-        virtual Level getLevel() = 0;
+        virtual Level getLevel() {
+            return this->level;
+        }
 
         /**
          * Sets the <code>Formatter</code> used by this Handler
@@ -110,13 +144,15 @@
          * Formatter will be remembered, but not used.
          * @param formatter <code>Filter</code> derived instance
          */
-        virtual void setFormatter( Formatter* formatter ) = 0;
+        virtual void setFormatter( Formatter* formatter );
 
         /**
          * Gets the <code>Formatter</code> used by this Handler
          * @returns <code>Filter</code> derived instance
          */
-        virtual const Formatter* getFormatter() = 0;
+        virtual Formatter* getFormatter() {
+            return this->formatter;
+        }
 
         /**
          * Sets the <code>Formatter</code> used by this Handler
@@ -126,15 +162,28 @@
          *
          * @param errorManager <code>ErrorManager</code> derived instance
          */
-        virtual void setErrorManager( ErrorManager* errorManager ) = 0;
+        virtual void setErrorManager( ErrorManager* errorManager );
 
         /**
          * Gets the <code>ErrorManager</code> used by this Handler.
          * @returns <code>ErrorManager</code> derived pointer or NULL.
          */
-        virtual const ErrorManager* getErrorManager() = 0;
+        virtual ErrorManager* getErrorManager() {
+            return this->errorManager;
+        }
+
+    protected:
+
+        /**
+         * Protected convenience method to report an error to this Handler's ErrorManager.
+         *
+         * @param message - a descriptive string (may be empty)
+         * @param ex - an exception (may be NULL)
+         * @param code - an error code defined in ErrorManager
+         */
+        void reportError( const std::string& message, decaf::lang::Exception* ex, int code );
 
-   };
+    };
 
 }}}
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/StreamHandler.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/StreamHandler.cpp?rev=907849&r1=907848&r2=907849&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/StreamHandler.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/StreamHandler.cpp Mon Feb  8 23:53:34 2010
@@ -18,35 +18,49 @@
 #include "StreamHandler.h"
 
 #include <decaf/util/logging/Level.h>
+#include <decaf/util/logging/Formatter.h>
+#include <decaf/util/logging/ErrorManager.h>
+#include <decaf/util/logging/Filter.h>
 #include <decaf/io/OutputStream.h>
+#include <decaf/io/Writer.h>
 
 using namespace decaf;
 using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
 using namespace decaf::io;
 using namespace decaf::util;
 using namespace decaf::util::logging;
 
 ////////////////////////////////////////////////////////////////////////////////
-StreamHandler::StreamHandler() : level( Level::SEVERE ) {
-
+StreamHandler::StreamHandler() : Handler() {
     this->stream = NULL;
-    this->formatter = NULL;
-    this->filter = NULL;
+    this->writerNotInitialized = true;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-StreamHandler::StreamHandler( OutputStream* stream, Formatter* formatter ) : level( Level::SEVERE ) {
+StreamHandler::StreamHandler( OutputStream* stream, Formatter* formatter ) : Handler() {
+
+    if( stream == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "OutputStream cannot be NULL." );
+    }
+
+    if( formatter == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "Formatter cannot be NULL." );
+    }
 
     this->stream = stream;
-    this->formatter = formatter;
-    this->filter = NULL;
+    this->writerNotInitialized = true;
+
+    setFormatter( formatter );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 StreamHandler::~StreamHandler() {
 
     try {
-        this->close();
+        this->close(true);
     }
     DECAF_CATCH_NOTHROW( lang::Exception)
     DECAF_CATCHALL_NOTHROW()
@@ -54,16 +68,23 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 void StreamHandler::close() throw ( decaf::io::IOException ) {
-    if( stream ) {
-        stream->flush();
-        stream->close();
-    }
+    this->close( true );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void StreamHandler::flush() {
-    if( stream ) {
-        stream->flush();
+
+    if( this->stream != NULL ) {
+        try {
+            if( this->writer != NULL ) {
+                this->writer->flush();
+            } else {
+                this->stream->flush();
+            }
+        } catch( Exception& e ) {
+            this->getErrorManager()->error(
+                "Failed to flush the output stream", &e, ErrorManager::FLUSH_FAILURE );
+        }
     }
 }
 
@@ -72,36 +93,97 @@
 
     try {
 
-        if( !stream ) {
-            throw lang::exceptions::NullPointerException(
-                __FILE__, __LINE__,
-                "StreamHandler::publish - Stream not set.");
+        if( this->isLoggable( record ) ) {
+
+            if( this->writerNotInitialized ) {
+                initializeWritter();
+            }
+
+            std::string msg = "";
+            try {
+                msg = getFormatter()->format( record );
+            } catch( Exception& e ) {
+                this->getErrorManager()->error(
+                    "Failed to format the LogRecord", &e, ErrorManager::FORMAT_FAILURE );
+            }
+
+            this->write( msg );
         }
+    } catch( Exception& e ) {
+        this->getErrorManager()->error(
+            "Failed to publish the LogRecord", &e, ErrorManager::GENERIC_FAILURE );
+    }
+}
 
-        // Check if we should log this record
-        if( isLoggable( record ) ) {
+////////////////////////////////////////////////////////////////////////////////
+bool StreamHandler::isLoggable( const LogRecord& record ) const {
 
-            std::string log = formatter->format( record );
+    if( this->stream != NULL && Handler::isLoggable( record ) ) {
+        return true;
+    }
+
+    return false;
+}
 
-            synchronized( stream ) {
-                // Write the data to the stream
-                stream->write( (const unsigned char*)log.c_str(), 0, log.length() );
+////////////////////////////////////////////////////////////////////////////////
+void StreamHandler::setOuputStream( decaf::io::OutputStream* stream )
+    throw( decaf::lang::exceptions::NullPointerException ) {
+
+    if( stream == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "OutputStream cannot be set to NULL." );
+    }
+
+    this->close( true );
+    this->stream = stream;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StreamHandler::close( bool closeStream ) {
+
+    if( this->stream != NULL ) {
+
+        if( this->writerNotInitialized ) {
+            initializeWritter();
+        }
+
+        this->write( getFormatter()->getTail( this ) );
+
+        try {
+
+            this->writer->flush();
+
+            if( closeStream ) {
+                this->writer->close();
+                this->writer = NULL;
+                this->stream = NULL;
             }
+
+        } catch( Exception& e ) {
+            this->getErrorManager()->error(
+                "Failed to close the OutputStream", &e, ErrorManager::CLOSE_FAILURE );
         }
     }
-    DECAF_CATCH_RETHROW( lang::Exception )
-    DECAF_CATCHALL_THROW( lang::Exception )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-bool StreamHandler::isLoggable( const LogRecord& record ) const {
+void StreamHandler::write( const std::string& value ) {
 
-    if( filter ) {
-        // Allow for some filtering to occur
-        return filter->isLoggable( record );
+    try{
+        this->stream->write( (const unsigned char*)value.c_str(), 0, value.length() );
+    } catch( Exception& e ) {
+        this->getErrorManager()->error(
+            "Failed to write to the OutputStream", &e, ErrorManager::WRITE_FAILURE );
     }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StreamHandler::initializeWritter() {
+
+    this->writerNotInitialized = false;
+    // TODO
+    //this->writer = new OutputStreamWriter(this.os);
 
-    // By default we want everything that is greater than our
-    // equal to the set level of this Handler.
-    return record.getLevel().compareTo( this->level ) >= 0;
+    // Start the Document by writing out the Head element.
+    this->write( getFormatter()->getHead( this ) );
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/StreamHandler.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/StreamHandler.h?rev=907849&r1=907848&r2=907849&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/StreamHandler.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/StreamHandler.h Mon Feb  8 23:53:34 2010
@@ -19,9 +19,6 @@
 
 #include <decaf/util/logging/LoggerCommon.h>
 #include <decaf/util/logging/Handler.h>
-#include <decaf/util/logging/Formatter.h>
-#include <decaf/util/logging/Filter.h>
-#include <decaf/util/logging/ErrorManager.h>
 #include <decaf/lang/exceptions/NullPointerException.h>
 #include <decaf/lang/exceptions/InvalidStateException.h>
 #include <decaf/util/concurrent/Concurrent.h>
@@ -30,27 +27,43 @@
 namespace decaf{
 namespace io{
     class OutputStream;
+    class Writer;
 }
 namespace util{
 namespace logging{
 
+    /**
+     * Stream based logging Handler.
+     *
+     * This is primarily intended as a base class or support class to be used in implementing
+     * other logging Handlers.
+     *
+     * LogRecords are published to a given <code>decaf.io.OutputStream</code>.
+     *
+     * Configuration: By default each StreamHandler is initialized using the following LogManager
+     * configuration properties. If properties are not defined (or have invalid values) then the
+     * specified default values are used.
+     *
+     *   * decaf.util.logging.StreamHandler.level specifies the default level for the Handler
+     *     (defaults to Level.INFO).
+     *   * decaf.util.logging.StreamHandler.filter specifies the name of a Filter class to use
+     *     (defaults to no Filter).
+     *   * decaf.util.logging.StreamHandler.formatter specifies the name of a Formatter class
+     *     to use (defaults to decaf.util.logging.SimpleFormatter).
+     *
+     * @since 1.0
+     */
     class DECAF_API StreamHandler : public Handler {
     private:
 
         // OutputStream to write to
         decaf::io::OutputStream* stream;
 
-        // Formats this Handlers output
-        Formatter* formatter;
+        // A Writer to wrap the OutputStream
+        decaf::io::Writer* writer;
 
-        // Filter object for Log Filtering
-        Filter* filter;
-
-        // ErrorManager instance for this Handler
-        ErrorManager* errorManager;
-
-        // Level at which that this Handler will start logging.
-        Level level;
+        // Indicates if the writer has been initialized already
+        bool writerNotInitialized;
 
     public:
 
@@ -101,90 +114,39 @@
          */
         virtual bool isLoggable( const LogRecord& record ) const;
 
-        /**
-         * Sets the Filter that this Handler uses to filter Log Records
-         * @param filter
-         *      <code>Filter</code> derived instance
-         */
-        virtual void setFilter( Filter* filter ) {
-            this->filter = filter;
-        }
-
-        /**
-         * Gets the Filter that this Handler uses to filter Log Records
-         * @return <code>Filter</code> derived instance
-         */
-        virtual const Filter* getFilter() {
-            return filter;
-        }
+    protected:
 
         /**
-         * Set the log level specifying which message levels will be logged
-         * by this Handler.
-         * <p>
-         * The intention is to allow developers to turn on verbose logging,
-         * but to limit the messages that are sent to certain Handlers.
+         * Change the output stream.
          *
-         * @param level
-         *      Level enumeration value
-         */
-        virtual void setLevel( Level level ) {
-            this->level = level;
-        }
-
-        /**
-         * Get the log level specifying which message levels will be logged
-         * by this Handler.
-         * @return Currently set Level enumeration value
-         */
-        virtual Level getLevel() {
-            return level;
-        }
-
-        /**
-         * Sets the <code>Formatter</code> used by this Handler
-         * @param formatter
-         *      <code>Formatter</code> derived instance
+         * If there is a current output stream then the Formatter's tail string is written and
+         * the stream is flushed and closed. Then the output stream is replaced with the new
+         * output stream.
+         *
+         * @param stream - New output stream. May not be NULL.
+         *
+         * @throws NullPointerException if the passed stream is NULL.
          */
-        virtual void setFormatter( Formatter* formatter ){
-            this->formatter = formatter;
-        }
+        virtual void setOuputStream( decaf::io::OutputStream* stream )
+            throw( decaf::lang::exceptions::NullPointerException );
 
         /**
-         * Gets the <code>Formatter</code> used by this Handler
-         * @return currently configured <code>Formatter</code> derived instance
+         * Closes this handler, but the underlying output stream is only closed if
+         * {@code closeStream} is {@code true}.
+         *
+         * @param closeStream
+         *            whether to close the underlying output stream.
          */
-        virtual const Formatter* getFormatter(){
-            return formatter;
-        }
+        void close( bool closeStream );
 
-        /**
-         * Gets the output Stream that this Handler is using
-         * @return OuputStream pointer used by this handler.
-         */
-        virtual io::OutputStream* getOutputStream() const{
-            return stream;
-        }
+    private:
 
-        /**
-         * Sets the <code>Formatter</code> used by this Handler
-         * <p>
-         * The ErrorManager's "error" method will be invoked if any errors occur while
-         * using this Handler.
-         *
-         * @param errorManager <code>ErrorManager</code> derived instance
-         */
-        virtual void setErrorManager( ErrorManager* errorManager ) {
-            this->errorManager = errorManager;
-        }
+        // Safely writes the string to the output stream, calling the ErrorManager
+        // if any exceptions are thrown while writing.
+        void write( const std::string& value );
 
-        /**
-         * Gets the <code>ErrorManager</code> used by this Handler.
-         * @returns <code>ErrorManager</code> derived pointer or NULL.
-         */
-        virtual const ErrorManager* getErrorManager() {
-            return this->errorManager;
-        }
+        // Initialize the Writer if its not already been initialized.
+        void initializeWritter();
 
     };
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/Makefile.am?rev=907849&r1=907848&r2=907849&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/Makefile.am Mon Feb  8 23:53:34 2010
@@ -19,6 +19,7 @@
     activemq/util/PrimitiveMapBenchmark.cpp \
     activemq/wireformat/openwire/utils/OpenWireStringSupportBenchmark.cpp \
     benchmark/PerformanceTimer.cpp \
+    decaf/io/ByteArrayInputStreamBenchmark.cpp \
     decaf/io/ByteArrayOutputStreamBenchmark.cpp \
     decaf/io/DataInputStreamBenchmark.cpp \
     decaf/io/DataOutputStreamBenchmark.cpp \
@@ -37,6 +38,7 @@
     activemq/wireformat/openwire/utils/OpenWireStringSupportBenchmark.h \
     benchmark/BenchmarkBase.h \
     benchmark/PerformanceTimer.h \
+    decaf/io/ByteArrayInputStreamBenchmark.h \
     decaf/io/ByteArrayOutputStreamBenchmark.h \
     decaf/io/DataInputStreamBenchmark.h \
     decaf/io/DataOutputStreamBenchmark.h \

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/decaf/io/ByteArrayInputStreamBenchmark.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/decaf/io/ByteArrayInputStreamBenchmark.cpp?rev=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/decaf/io/ByteArrayInputStreamBenchmark.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/decaf/io/ByteArrayInputStreamBenchmark.cpp Mon Feb  8 23:53:34 2010
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ByteArrayInputStreamBenchmark.h"
+
+using namespace decaf;
+using namespace decaf::io;
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayInputStreamBenchmark::ByteArrayInputStreamBenchmark() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayInputStreamBenchmark::~ByteArrayInputStreamBenchmark() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamBenchmark::setUp() {
+
+    buffer = new unsigned char[bufferSize];
+
+    // init to full String Buffer
+    stlBuffer.reserve( bufferSize );
+    for( int ix = 0; ix < bufferSize - 1; ++ix ) {
+        buffer[ix] = 65;
+        stlBuffer.push_back( 65 );
+    }
+    buffer[bufferSize-1] = 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamBenchmark::tearDown(){
+
+    delete [] buffer;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamBenchmark::run(){
+
+    int numRuns = 25;
+
+    std::vector<unsigned char> bucket( bufferSize );
+    ByteArrayInputStream bis( buffer, bufferSize );
+
+    for( int iy = 0; iy < numRuns; ++iy ){
+        ByteArrayInputStream local( buffer, bufferSize );
+    }
+
+    for( int iy = 0; iy < numRuns; ++iy ){
+
+        for( int iz = 0; iz < bufferSize; ++iz ) {
+            bucket[iy] = bis.read();
+        }
+        bis.reset();
+    }
+
+    for( int iy = 0; iy < numRuns; ++iy ){
+        bis.read( &bucket[0], 0, bufferSize );
+        bis.reset();
+    }
+
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/decaf/io/ByteArrayInputStreamBenchmark.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/decaf/io/ByteArrayInputStreamBenchmark.cpp
------------------------------------------------------------------------------
    svn:executable = *

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/decaf/io/ByteArrayInputStreamBenchmark.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/decaf/io/ByteArrayInputStreamBenchmark.h?rev=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/decaf/io/ByteArrayInputStreamBenchmark.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/decaf/io/ByteArrayInputStreamBenchmark.h Mon Feb  8 23:53:34 2010
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_IO_BYTEARRAYINPUTSTREAMBENCHMARK_H_
+#define _DECAF_IO_BYTEARRAYINPUTSTREAMBENCHMARK_H_
+
+#include <benchmark/BenchmarkBase.h>
+#include <decaf/io/ByteArrayInputStream.h>
+
+namespace decaf {
+namespace io {
+
+    class ByteArrayInputStreamBenchmark :
+    public benchmark::BenchmarkBase<
+        decaf::io::ByteArrayInputStreamBenchmark, ByteArrayInputStream >
+    {
+    private:
+
+        unsigned char* buffer;
+        std::vector<unsigned char> stlBuffer;
+        static const int bufferSize = 200000;
+
+    public:
+
+        ByteArrayInputStreamBenchmark();
+        virtual ~ByteArrayInputStreamBenchmark();
+
+        virtual void setUp();
+        virtual void tearDown();
+        virtual void run();
+
+    };
+
+}}
+
+#endif /* _DECAF_IO_BYTEARRAYINPUTSTREAMBENCHMARK_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/decaf/io/ByteArrayInputStreamBenchmark.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/decaf/io/ByteArrayInputStreamBenchmark.h
------------------------------------------------------------------------------
    svn:executable = *

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/testRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/testRegistry.cpp?rev=907849&r1=907848&r2=907849&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/testRegistry.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test-benchmarks/testRegistry.cpp Mon Feb  8 23:53:34 2010
@@ -37,6 +37,8 @@
 
 #include <decaf/io/ByteArrayOutputStreamBenchmark.h>
 CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::ByteArrayOutputStreamBenchmark );
+#include <decaf/io/ByteArrayInputStreamBenchmark.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::ByteArrayInputStreamBenchmark );
 #include <decaf/io/DataInputStreamBenchmark.h>
 CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::DataInputStreamBenchmark );
 #include <decaf/io/DataOutputStreamBenchmark.h>

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am?rev=907849&r1=907848&r2=907849&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am Mon Feb  8 23:53:34 2010
@@ -90,6 +90,10 @@
     decaf/io/DataOutputStreamTest.cpp \
     decaf/io/FilterInputStreamTest.cpp \
     decaf/io/FilterOutputStreamTest.cpp \
+    decaf/io/InputStreamReaderTest.cpp \
+    decaf/io/OutputStreamWriterTest.cpp \
+    decaf/io/ReaderTest.cpp \
+    decaf/io/WriterTest.cpp \
     decaf/lang/BooleanTest.cpp \
     decaf/lang/ByteTest.cpp \
     decaf/lang/CharacterTest.cpp \
@@ -220,6 +224,10 @@
     decaf/io/DataOutputStreamTest.h \
     decaf/io/FilterInputStreamTest.h \
     decaf/io/FilterOutputStreamTest.h \
+    decaf/io/InputStreamReaderTest.h \
+    decaf/io/OutputStreamWriterTest.h \
+    decaf/io/ReaderTest.h \
+    decaf/io/WriterTest.h \
     decaf/lang/BooleanTest.h \
     decaf/lang/ByteTest.h \
     decaf/lang/CharacterTest.h \



Mime
View raw message