activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r652104 [6/29] - in /activemq/activemq-cpp/trunk: ./ m4/ src/examples/ src/examples/consumers/ src/main/ src/main/decaf/ src/main/decaf/internal/ src/main/decaf/internal/net/ src/main/decaf/internal/nio/ src/main/decaf/internal/util/ src/ma...
Date Tue, 29 Apr 2008 20:52:37 GMT
Added: activemq/activemq-cpp/trunk/src/main/decaf/io/BlockingByteArrayInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/io/BlockingByteArrayInputStream.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/io/BlockingByteArrayInputStream.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/io/BlockingByteArrayInputStream.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,262 @@
+/*
+ * 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_BLOCKINGBYTEARRAYINPUTSTREAM_H_
+#define _DECAF_IO_BLOCKINGBYTEARRAYINPUTSTREAM_H_
+
+#include <decaf/io/InputStream.h>
+#include <decaf/util/concurrent/Mutex.h>
+#include <vector>
+
+namespace decaf{
+namespace io{
+
+    /**
+     * This is a blocking version of a byte buffer stream.  Read operations
+     * block until the requested data becomes available in the internal
+     * buffer via a call to setByteArray.
+     */
+    class DECAF_API BlockingByteArrayInputStream : public InputStream {
+    private:
+
+        /**
+         * Default buffer to use, if none provided.
+         */
+        std::vector<unsigned char> buffer;
+
+        /**
+         * iterator to current position in buffer.
+         */
+        std::vector<unsigned char>::const_iterator pos;
+
+        /**
+         * Synchronization object.
+         */
+        util::concurrent::Mutex mutex;
+
+        /**
+         * Indicates that this stream is in the process of shutting
+         * down.
+         */
+        bool closing;
+
+    public:
+
+        /**
+         * Default Constructor - uses a default internal buffer
+         */
+        BlockingByteArrayInputStream();
+
+        /**
+         * Constructor that initializes the internal buffer.
+         * @see setByteArray.
+         */
+        BlockingByteArrayInputStream( const unsigned char* buffer,
+                                      std::size_t bufferSize );
+
+        /**
+         * Destructor
+         */
+        virtual ~BlockingByteArrayInputStream();
+
+        /**
+         * Sets the data that this reader uses.  Replaces any existing
+         * data and resets the read index to the beginning of the buffer.
+         * When this method is called, it notifies any other threads that
+         * data is now available to be read.
+         * @param buffer The new data to be copied to the internal buffer.
+         * @param bufferSize The size of the new buffer.
+         */
+        virtual void setByteArray( const unsigned char* buffer,
+                                   std::size_t bufferSize );
+
+        /**
+         * Indicates the number of bytes available to be read without
+         * blocking.
+         * @return the data available in the internal buffer.
+         * @throws IOException if an error occurs.
+         */
+        virtual std::size_t available() const throw ( IOException ){
+            return std::distance( pos, buffer.end() );
+        }
+
+        /**
+         * Reads a single byte from the buffer.  This operation will
+         * block until data has been added to the buffer via a call
+         * to setByteArray.
+         * @return the next byte.
+         * @throws IOException if an error occurs.
+         */
+        virtual unsigned char read() throw ( IOException );
+
+        /**
+         * Reads an array of bytes from the buffer.  If the desired amount
+         * of data is not currently available, this operation
+         * will block until the appropriate amount of data is available
+         * in the buffer via a call to setByteArray.
+         * @param buffer (out) the target buffer
+         * @param offset the position in the buffer to start from.
+         * @param bufferSize the size of the output buffer.
+         * @return the number of bytes read. or -1 if EOF
+         * @throws IOException f an error occurs.
+         */
+        virtual int read( unsigned char* buffer,
+                          std::size_t offset,
+                          std::size_t bufferSize )
+            throw ( IOException, lang::exceptions::NullPointerException );
+
+        /**
+         * Closes the target input stream.
+         * @throws IOException if an error occurs.
+         */
+        virtual void close() throw ( lang::Exception );
+
+        /**
+         * Skips over and discards n bytes of data from this input stream. The
+         * skip method may, for a variety of reasons, end up skipping over some
+         * smaller number of bytes, possibly 0. This may result from any of a
+         * number of conditions; reaching end of file before n bytes have been
+         * skipped is only one possibility. The actual number of bytes skipped
+         * is returned. If n is negative, no bytes are skipped.
+         * <p>
+         * The skip method of InputStream creates a byte array and then
+         * repeatedly reads into it until n bytes have been read or the end
+         * of the stream has been reached. Subclasses are encouraged to
+         * provide a more efficient implementation of this method.
+         * @param num - the number of bytes to skip
+         * @returns total butes skipped
+         * @throws IOException if an error occurs
+         */
+        virtual std::size_t skip( std::size_t num )
+            throw ( io::IOException, lang::exceptions::UnsupportedOperationException );
+
+        /**
+         * Marks the current position in the stream A subsequent call to the
+         * reset method repositions this stream at the last marked position so
+         * that subsequent reads re-read the same bytes.
+         *
+         * If a stream instance reports that marks are supported then the stream
+         * will ensure that the same bytes can be read again after the reset method
+         * is called so long the readLimit is not reached.
+         * @param readLimit - max bytes read before marked position is invalid.
+         */
+        virtual void mark( int readLimit DECAF_UNUSED ) {}
+
+        /**
+         * Repositions this stream to the position at the time the mark method was
+         * last called on this input stream.
+         *
+         * If the method markSupported returns true, then:
+         *   * If the method mark has not been called since the stream was created,
+         *     or the number of bytes read from the stream since mark was last called
+         * 	   is larger than the argument to mark at that last call, then an
+         *     IOException might be thrown.
+         *   * If such an IOException is not thrown, then the stream is reset to a
+         *     state such that all the bytes read since the most recent call to mark
+         *     (or since the start of the file, if mark has not been called) will be
+         *     resupplied to subsequent callers of the read method, followed by any
+         *     bytes that otherwise would have been the next input data as of the
+         *     time of the call to reset.
+         * If the method markSupported returns false, then:
+         *   * The call to reset may throw an IOException.
+         *   * If an IOException is not thrown, then the stream is reset to a fixed
+         *     state that depends on the particular type of the input stream and how
+         *     it was created. The bytes that will be supplied to subsequent callers
+         *     of the read method depend on the particular type of the input stream.
+         * @throws IOException
+         */
+        virtual void reset() throw ( IOException ) {
+            throw IOException(
+                __FILE__, __LINE__,
+                "BufferedInputStream::reset - mark no yet supported." );
+        }
+
+        /**
+         * Determines if this input stream supports the mark and reset methods.
+         * Whether or not mark and reset are supported is an invariant property of
+         * a particular input stream instance.
+         * @returns true if this stream instance supports marks
+         */
+        virtual bool markSupported() const{ return false; }
+
+    public:
+
+        /**
+         * Waits on a signal from this object, which is generated
+         * by a call to Notify.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void lock() throw( lang::Exception ){
+            mutex.lock();
+        }
+
+        /**
+         * Unlocks the object.
+         * @throws Exception
+         */
+        virtual void unlock() throw( lang::Exception ){
+            mutex.unlock();
+        }
+
+        /**
+         * Waits on a signal from this object, which is generated
+         * by a call to Notify.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void wait() throw( lang::Exception ){
+            mutex.wait();
+        }
+
+        /**
+         * Waits on a signal from this object, which is generated
+         * by a call to Notify.  Must have this object locked before
+         * calling.  This wait will timeout after the specified time
+         * interval.
+         * @param time in millisecsonds to wait, or WAIT_INIFINITE
+         * @throws Exception
+         */
+        virtual void wait( unsigned long millisecs ) throw( lang::Exception ){
+            mutex.wait(millisecs);
+        }
+
+        /**
+         * Signals a waiter on this object that it can now wake
+         * up and continue.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void notify() throw( lang::Exception ){
+            mutex.notify();
+        }
+
+        /**
+         * Signals the waiters on this object that it can now wake
+         * up and continue.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void notifyAll() throw( lang::Exception ){
+            mutex.notifyAll();
+        }
+
+    };
+
+}}
+
+#endif /*_DECAF_IO_BLOCKINGBYTEARRAYINPUTSTREAM_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/io/BufferedInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/io/BufferedInputStream.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/io/BufferedInputStream.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/io/BufferedInputStream.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,279 @@
+/*
+ * 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 "BufferedInputStream.h"
+#include <algorithm>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::io;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+BufferedInputStream::BufferedInputStream( InputStream* stream, bool own )
+: FilterInputStream( stream, own ) {
+    // Default to a 1k buffer.
+    init( 1024 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+BufferedInputStream::BufferedInputStream( InputStream* stream,
+                                          std::size_t bufferSize,
+                                          bool own )
+    throw ( lang::exceptions::IllegalArgumentException )
+
+: FilterInputStream( stream, own ) {
+
+    try {
+        this->init( bufferSize );
+    }
+    DECAF_CATCH_RETHROW( IllegalArgumentException )
+    DECAF_CATCHALL_THROW( IllegalArgumentException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+BufferedInputStream::~BufferedInputStream() {
+    try{
+        this->close();
+    }
+    DECAF_CATCH_NOTHROW( IOException )
+    DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedInputStream::init( std::size_t bufferSize ){
+
+    if( bufferSize <= 0 ) {
+        throw new IllegalArgumentException(
+            __FILE__, __LINE__,
+            "BufferedInputStream::init - Size must be greater than zero");
+    }
+
+    this->bufferSize = bufferSize;
+
+    // Create the buffer and initialize the head and tail positions.
+    this->buffer = new unsigned char[bufferSize];
+    this->head = 0;
+    this->tail = 0;
+    this->markLimit = 0;
+    this->markpos = -1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedInputStream::close() throw( IOException ) {
+
+    // let parent close the inputStream
+    FilterInputStream::close();
+
+    // Destroy the buffer.
+    if( buffer != NULL ){
+        delete [] buffer;
+        buffer = NULL;
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned char BufferedInputStream::read() throw ( IOException ){
+
+    try{
+
+        if( isClosed() ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "BufferedInputStream::bufferData - Stream is clsoed" );
+        }
+
+        // If there's no data left, reset to pointers to the beginning of the
+        // buffer.
+        normalizeBuffer();
+
+        // If we don't have any data buffered yet - read as much as
+        // we can.
+        if( isEmpty() ){
+
+            // If we hit EOF without getting any Data, then throw IOException
+            if( bufferData() == -1 ){
+                throw IOException(
+                    __FILE__, __LINE__,
+                    "BufferedInputStream::read - EOF has been Reached");
+            }
+        }
+
+        // Get the next character.
+        char returnValue = buffer[head++];
+
+        return returnValue;
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int BufferedInputStream::read( unsigned char* targetBuffer,
+                               std::size_t offset,
+                               std::size_t targetBufferSize )
+    throw ( IOException, NullPointerException ){
+
+    try{
+
+        if( isClosed() ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "BufferedInputStream::bufferData - Stream is clsoed" );
+        }
+
+        // For zero, do nothing
+        if( targetBufferSize == 0 ) {
+            return 0;
+        }
+
+        if( targetBuffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "BufferedInputStream::read - Passed NULL for target Buffer");
+        }
+
+        // If there's no data left, reset to pointers to the beginning of the
+        // buffer.
+        normalizeBuffer();
+
+        // If we still haven't filled the output buffer AND there is data
+        // on the input stream to be read, read a buffer's worth from the stream.
+        std::size_t totalRead = 0;
+        while( totalRead < targetBufferSize ){
+
+            // Get the remaining bytes to copy.
+            std::size_t bytesToCopy = min( tail-head, (targetBufferSize-totalRead) );
+
+            // Copy the data to the output buffer.
+            memcpy( targetBuffer+totalRead+offset, this->buffer+head, bytesToCopy );
+
+            // Increment the total bytes read.
+            totalRead += bytesToCopy;
+
+            // Increment the head position.
+            head += bytesToCopy;
+
+            // If the buffer is now empty, reset the positions to the
+            // head of the buffer.
+            normalizeBuffer();
+
+            // If we still haven't satisified the request,
+            // read more data.
+            if( totalRead < targetBufferSize ){
+
+                // Buffer as much data as we can, return EOF if we hit it.
+                if( bufferData() == -1 ) {
+                    return -1;
+                }
+            }
+        }
+
+        // Return the total number of bytes read.
+        return (int)totalRead;
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t BufferedInputStream::skip( std::size_t num )
+    throw ( IOException, lang::exceptions::UnsupportedOperationException ){
+
+    try{
+
+        if( isClosed() ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "BufferedInputStream::skip - Stream is clsoed" );
+        }
+
+        // If there's no data left, reset to pointers to the beginning of the
+        // buffer.
+        normalizeBuffer();
+
+        // loop until we've skipped the desired number of bytes
+        std::size_t totalSkipped = 0;
+        while( totalSkipped < num ){
+
+            // Get the remaining bytes to copy.
+            std::size_t bytesToSkip = min( tail-head, num-totalSkipped );
+
+            // Increment the head position.
+            head += bytesToSkip;
+            totalSkipped += bytesToSkip;
+
+            // If the buffer is now empty, reset the positions to the
+            // head of the buffer.
+            normalizeBuffer();
+
+            // If we still haven't satisified the request,
+            // read more data.
+            if( totalSkipped < num ){
+
+                // Buffer as much data as we can.
+                bufferData();
+            }
+        }
+
+        // Return the total number of bytes read.
+        return totalSkipped;
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int BufferedInputStream::bufferData() throw ( IOException ){
+
+    try{
+        if( getUnusedBytes() == 0 ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "BufferedInputStream::bufferData - buffer full" );
+        }
+
+        // Get the number of bytes currently available on the input stream
+        // that could be read without blocking.
+        std::size_t available = inputStream->available();
+
+        // Calculate the number of bytes that we can read.  Always >= 1 byte!
+        std::size_t bytesToRead = max( (std::size_t)1, min( available, getUnusedBytes() ) );
+
+        // Read the bytes from the input stream.
+        int bytesRead = inputStream->read( getTail(), 0, bytesToRead );
+        if( bytesRead == 0 ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "BufferedInputStream::read() - failed reading bytes from stream");
+        }
+
+        // Dont add -1 to tail if we hit EOF
+        if( bytesRead == -1 ) {
+            return bytesRead;
+        }
+
+        // Increment the tail to the new end position.
+        tail += bytesRead;
+
+        return bytesRead;
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}

Added: activemq/activemq-cpp/trunk/src/main/decaf/io/BufferedInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/io/BufferedInputStream.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/io/BufferedInputStream.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/io/BufferedInputStream.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,266 @@
+/*
+ * 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_BUFFEREDINPUTSTREAM_H_
+#define _DECAF_IO_BUFFEREDINPUTSTREAM_H_
+
+#include <decaf/io/FilterInputStream.h>
+#include <decaf/lang/exceptions/IllegalArgumentException.h>
+
+namespace decaf{
+namespace io{
+
+    /**
+     * A wrapper around another input stream that performs
+     * a buffered read, where it reads more data than it needs
+     * in order to reduce the number of io operations on the
+     * input stream.
+     */
+    class DECAF_API BufferedInputStream : public FilterInputStream {
+    private:
+
+        /**
+         * The internal buffer.
+         */
+        unsigned char* buffer;
+
+        /**
+         * The buffer size.
+         */
+        std::size_t bufferSize;
+
+        /**
+         * The current head of the buffer.
+         */
+        std::size_t head;
+
+        /**
+         * The current tail of the buffer.
+         */
+        std::size_t tail;
+
+        /**
+         * The current limit, which when passed, invalidates the current mark.
+         */
+        int markLimit;
+
+        /**
+         * The currently marked position. -1 indicates no mark has been set or the
+         * mark has been invalidated.
+         */
+        int markpos;
+
+    public:
+
+        /**
+         * Constructor
+         * @param stream The target input stream.
+         * @param own indicates if we own the stream object, defaults to false
+         */
+        BufferedInputStream( InputStream* stream, bool own = false );
+
+        /**
+         * Constructor
+         * @param stream the target input stream
+         * @param bufferSize the size for the internal buffer.
+         * @param own indicates if we own the stream object, defaults to false.
+         * @throws IllegalArgumentException is the size is zero.
+         */
+        BufferedInputStream( InputStream* stream,
+                             std::size_t bufferSize,
+                             bool own = false )
+            throw ( lang::exceptions::IllegalArgumentException );
+
+        virtual ~BufferedInputStream();
+
+        /**
+         * Indcates the number of bytes avaialable.
+         * @return the sum of the amount of data avalable
+         * in the buffer and the data available on the target
+         * input stream.
+         */
+        virtual std::size_t available() const throw ( IOException ) {
+            if( buffer == NULL ) {
+                throw IOException(
+                    __FILE__, __LINE__,
+                    "BufferedInputStream::available - Buffer was closed");
+            }
+            return ( tail - head ) + inputStream->available();
+        }
+
+        /**
+         * Close this BufferedInputStream. This implementation closes the target
+         * stream and releases any resources associated with it.
+         * @throws IOException If an error occurs attempting to close this stream.
+         */
+        virtual void close() throw( IOException );
+
+        /**
+         * Reads a single byte from the buffer.  Blocks until
+         * the data is available.
+         * @return The next byte.
+         * @throws IOException thrown if an error occurs.
+         */
+        virtual unsigned char read() throw ( IOException );
+
+        /**
+         * Reads an array of bytes from the buffer.  Blocks
+         * until the requested number of bytes are available.
+         * @param buffer (out) the target buffer.
+         * @param offset the position in the buffer to start reading from.
+         * @param bufferSize the size of the output buffer.
+         * @return The number of bytes read or -1 if EOF
+         * @throws IOException thrown if an error occurs.
+         * @throws NullPointerException if buffer is NULL
+         */
+        virtual int read( unsigned char* buffer,
+                          std::size_t offset,
+                          std::size_t bufferSize )
+            throw ( IOException,
+                    lang::exceptions::NullPointerException );
+
+        /**
+         * Skips over and discards n bytes of data from this input stream. The
+         * skip method may, for a variety of reasons, end up skipping over some
+         * smaller number of bytes, possibly 0. This may result from any of a
+         * number of conditions; reaching end of file before n bytes have been
+         * skipped is only one possibility. The actual number of bytes skipped
+         * is returned. If n is negative, no bytes are skipped.
+         * <p>
+         * The skip method of InputStream creates a byte array and then
+         * repeatedly reads into it until n bytes have been read or the end
+         * of the stream has been reached. Subclasses are encouraged to
+         * provide a more efficient implementation of this method.
+         * @param num - the number of bytes to skip
+         * @returns total butes skipped
+         * @throws IOException if an error occurs
+         */
+        virtual std::size_t skip( std::size_t num )
+            throw ( io::IOException, lang::exceptions::UnsupportedOperationException );
+
+        /**
+         * Marks the current position in the stream A subsequent call to the
+         * reset method repositions this stream at the last marked position so
+         * that subsequent reads re-read the same bytes.
+         *
+         * If a stream instance reports that marks are supported then the stream
+         * will ensure that the same bytes can be read again after the reset method
+         * is called so long the readLimit is not reached.
+         * @param readLimit - max bytes read before marked position is invalid.
+         */
+        virtual void mark( int readLimit ) {
+            this->markLimit = readLimit;
+            this->markpos = (int)head;
+        }
+
+        /**
+         * Repositions this stream to the position at the time the mark method was
+         * last called on this input stream.
+         *
+         * If the method markSupported returns true, then:
+         *   * If the method mark has not been called since the stream was created,
+         *     or the number of bytes read from the stream since mark was last called
+         * 	   is larger than the argument to mark at that last call, then an
+         *     IOException might be thrown.
+         *   * If such an IOException is not thrown, then the stream is reset to a
+         *     state such that all the bytes read since the most recent call to mark
+         *     (or since the start of the file, if mark has not been called) will be
+         *     resupplied to subsequent callers of the read method, followed by any
+         *     bytes that otherwise would have been the next input data as of the
+         *     time of the call to reset.
+         * If the method markSupported returns false, then:
+         *   * The call to reset may throw an IOException.
+         *   * If an IOException is not thrown, then the stream is reset to a fixed
+         *     state that depends on the particular type of the input stream and how
+         *     it was created. The bytes that will be supplied to subsequent callers
+         *     of the read method depend on the particular type of the input stream.
+         * @throws IOException
+         */
+        virtual void reset() throw ( IOException ) {
+            throw IOException(
+                __FILE__, __LINE__,
+                "BufferedInputStream::reset - mark no yet supported." );
+        }
+
+        /**
+         * Determines if this input stream supports the mark and reset methods.
+         * Whether or not mark and reset are supported is an invariant property of
+         * a particular input stream instance.
+         * @returns true if this stream instance supports marks
+         */
+        virtual bool markSupported() const{ return false; }
+
+    private:
+
+        /**
+         * Initializes the internal structures.
+         * @param size of buffer to allocate
+         */
+        void init( std::size_t bufferSize );
+
+        /**
+         * Populates the buffer with as much data as possible
+         * from the target input stream.
+         * @returns total bytes read, or -1 if EOF.
+         * @throws CMSException
+         */
+        int bufferData() throw ( IOException );
+
+        /**
+         * Returns the number of bytes that are currently unused
+         * in the buffer.
+         */
+        std::size_t getUnusedBytes() const{
+            return bufferSize - tail;
+        }
+
+        /**
+         * Returns the current tail position of the buffer.
+         */
+        unsigned char* getTail(){
+            return buffer + tail;
+        }
+
+        /**
+         * Initializes the head and tail indicies to the beginning
+         * of the buffer.
+         */
+        void clear(){
+            head = tail = 0;
+        }
+
+        /**
+         * Inidicates whether or not the buffer is empty.
+         */
+        bool isEmpty() const{
+            return head == tail;
+        }
+
+        /**
+         * Clears the buffer if there is no data remaining.
+         */
+        void normalizeBuffer(){
+            if( isEmpty() ){
+                clear();
+            }
+        }
+
+    };
+
+}}
+
+#endif /*_DECAF_IO_BUFFEREDINPUTSTREAM_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/io/BufferedOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/io/BufferedOutputStream.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/io/BufferedOutputStream.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/io/BufferedOutputStream.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,212 @@
+/*
+ * 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 "BufferedOutputStream.h"
+#include <algorithm>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::io;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+BufferedOutputStream::BufferedOutputStream( OutputStream* stream, bool own )
+: FilterOutputStream( stream, own ) {
+    // Default to 1k buffer.
+    init( 1024 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+BufferedOutputStream::BufferedOutputStream( OutputStream* stream,
+    std::size_t bufSize,
+    bool own )
+        throw ( lang::exceptions::IllegalArgumentException )
+
+: FilterOutputStream( stream, own ) {
+
+    try {
+        this->init( bufSize );
+    }
+    DECAF_CATCH_RETHROW( IllegalArgumentException )
+    DECAF_CATCHALL_THROW( IllegalArgumentException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+BufferedOutputStream::~BufferedOutputStream() {
+    try{
+        this->close();
+    }
+    DECAF_CATCH_NOTHROW( IOException )
+    DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStream::init( std::size_t bufSize ) {
+
+    if( bufSize <= 0 ) {
+        throw new IllegalArgumentException(
+            __FILE__, __LINE__,
+            "BufferedOutputStream::init - Size must be greater than zero");
+    }
+
+    this->bufferSize = bufSize;
+
+    buffer = new unsigned char[bufSize];
+    head = tail = 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStream::close() throw( lang::Exception ){
+
+    // let parent close the inputStream
+    FilterOutputStream::close();
+
+    // Destroy the buffer.
+    if( buffer != NULL ){
+        delete [] buffer;
+        buffer = NULL;
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStream::emptyBuffer() throw ( IOException ){
+
+    if( outputStream == NULL ) {
+        throw IOException(
+            __FILE__, __LINE__,
+            "BufferedOutputStream::emptyBuffer - OutputStream is closed" );
+    }
+
+    if( head != tail ){
+        outputStream->write( buffer+head, 0, tail-head );
+    }
+    head = tail = 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStream::flush() throw ( IOException ){
+
+    try {
+
+        if( isClosed() ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "BufferedOutputStream::write - Stream is clsoed" );
+        }
+
+        // Empty the contents of the buffer to the output stream.
+        emptyBuffer();
+
+        // Flush the output stream.
+        outputStream->flush();
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStream::write( const unsigned char c ) throw ( IOException ){
+
+    try{
+
+        if( isClosed() ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "BufferedOutputStream::write - Stream is clsoed" );
+        }
+
+        if( tail >= bufferSize ){
+            emptyBuffer();
+        }
+
+        buffer[tail++] = c;
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStream::write( const std::vector<unsigned char>& buffer )
+    throw ( IOException ) {
+
+    try{
+
+        if( buffer.empty() ) {
+            return;
+        }
+
+        if( isClosed() ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "BufferedOutputStream::write - Stream is clsoed" );
+        }
+
+        this->write( &buffer[0], 0, buffer.size() );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStream::write( const unsigned char* buffer,
+                                  std::size_t offset, std::size_t len )
+    throw ( IOException, lang::exceptions::NullPointerException ) {
+
+    try{
+
+        // Fast exit.
+        if( len == 0 ) {
+            return;
+        }
+
+        if( isClosed() ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "BufferedOutputStream::write - Stream is clsoed" );
+        }
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "BufferedOutputStream::write - Buffer passed is Null.");
+        }
+
+        // Iterate until all the data is written.
+        for( std::size_t pos=0; pos < len; ){
+
+            if( tail >= bufferSize ){
+                emptyBuffer();
+            }
+
+            // Get the number of bytes left to write.
+            std::size_t bytesToWrite = min( (int)bufferSize-tail, len-pos );
+
+            // Copy the data.
+            memcpy( this->buffer+tail, buffer+offset+pos, bytesToWrite );
+
+            // Increase the tail position.
+            tail += bytesToWrite;
+
+            // Decrease the number of bytes to write.
+            pos += bytesToWrite;
+        }
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCHALL_THROW( IOException )
+}

Added: activemq/activemq-cpp/trunk/src/main/decaf/io/BufferedOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/io/BufferedOutputStream.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/io/BufferedOutputStream.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/io/BufferedOutputStream.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,131 @@
+/*
+ * 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_BUFFEREDOUTPUTSTREAM_H_
+#define _DECAF_IO_BUFFEREDOUTPUTSTREAM_H_
+
+#include <decaf/io/FilterOutputStream.h>
+#include <decaf/lang/exceptions/IllegalArgumentException.h>
+
+namespace decaf{
+namespace io{
+
+    /**
+     * Wrapper around another output stream that buffers
+     * output before writing to the target output stream.
+     */
+    class DECAF_API BufferedOutputStream : public FilterOutputStream
+    {
+    private:
+
+        /**
+         * The internal buffer.
+         */
+        unsigned char* buffer;
+
+        /**
+         * The size of the internal buffer.
+         */
+        std::size_t bufferSize;
+
+        /**
+         * The current head of the buffer.
+         */
+        std::size_t head;
+
+        /**
+         * The current tail of the buffer.
+         */
+        std::size_t tail;
+
+    public:
+
+        /**
+         * Constructor.
+         * @param stream the target output stream.
+         */
+        BufferedOutputStream( OutputStream* stream, bool own = false );
+
+        /**
+         * Constructor
+         * @param stream the target output stream.
+         * @param bufSize the size for the internal buffer.
+         */
+        BufferedOutputStream( OutputStream* stream,
+                              std::size_t bufSize,
+                              bool own = false )
+            throw ( lang::exceptions::IllegalArgumentException );
+
+        virtual ~BufferedOutputStream();
+
+        /**
+         * Writes a single byte to the output stream.
+         * @param c the byte.
+         * @throws IOException thrown if an error occurs.
+         */
+        virtual void write( unsigned char c ) throw ( IOException );
+
+        /**
+         * Writes an array of bytes to the output stream.
+         * @param buffer The bytes to write.
+         * @throws IOException thrown if an error occurs.
+         */
+        virtual void write( const std::vector<unsigned char>& buffer )
+            throw ( IOException );
+
+        /**
+         * Writes an array of bytes to the output stream.
+         * @param buffer The array of bytes to write.
+         * @param offset, the position to start writing in buffer.
+         * @param len The number of bytes from the buffer to be written.
+         * @throws IOException thrown if an error occurs.
+         * @throws NullPointerException thrown if buffer is Null.
+         */
+        virtual void write( const unsigned char* buffer,
+                            std::size_t offset,
+                            std::size_t len )
+            throw ( IOException, lang::exceptions::NullPointerException );
+
+        /**
+         * Invokes flush on the target output stream.
+         * @throws IOException thrown if an error occurs.
+         */
+        virtual void flush() throw ( IOException );
+
+        /**
+         * Invokes close on the target output stream.
+         * @throws CMSException thrown if an error occurs.
+         */
+        void close() throw( lang::Exception );
+
+   private:
+
+        /**
+         * Initializes the internal structures.
+         */
+        void init( std::size_t bufSize );
+
+        /**
+         * Writes the contents of the buffer to the output stream.
+         */
+        void emptyBuffer() throw ( IOException );
+
+   };
+
+}}
+
+#endif /*_DECAF_IO_BUFFEREDOUTPUTSTREAM_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/io/ByteArrayInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/io/ByteArrayInputStream.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/io/ByteArrayInputStream.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/io/ByteArrayInputStream.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,168 @@
+/*
+ * 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 "ByteArrayInputStream.h"
+#include <algorithm>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::io;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayInputStream::ByteArrayInputStream(){
+    this->activeBuffer = NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayInputStream::ByteArrayInputStream( const vector<unsigned char>& buffer ){
+    setBuffer(buffer);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayInputStream::ByteArrayInputStream( const unsigned char* buffer,
+                                            std::size_t bufferSize ){
+    setByteArray( buffer, bufferSize );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayInputStream::~ByteArrayInputStream(){
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStream::setBuffer( const vector<unsigned char>& buffer ){
+
+    // We're using the default buffer.
+    this->activeBuffer = &buffer;
+
+    // Start the stream off at the beginning marking begin as the reset point.
+    this->markpos = this->activeBuffer->begin();
+    this->pos = this->markpos;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStream::setByteArray( const unsigned char* buffer,
+                                         std::size_t bufferSize ) {
+
+    // We're using the default buffer.
+    this->activeBuffer = &this->defaultBuffer;
+
+    // Remove old data
+    this->defaultBuffer.clear();
+    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 );
+
+    // Start the stream off at the beginning marking begin as the reset point.
+    this->markpos = this->activeBuffer->begin();
+    this->pos = this->markpos;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStream::reset() throw ( IOException){
+    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;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned char ByteArrayInputStream::read() throw ( IOException ){
+
+    if( activeBuffer == NULL ){
+        throw IOException(
+            __FILE__, __LINE__,
+            "ByteArrayInputStream::read - Buffer has not been initialized" );
+    }
+
+    if( pos == activeBuffer->end() ){
+        throw IOException(
+            __FILE__, __LINE__,
+            "ByteArrayInputStream::read - Buffer is empty" );
+    }
+
+    return *(pos++);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int ByteArrayInputStream::read( unsigned char* buffer,
+                                std::size_t offset,
+                                std::size_t bufferSize )
+    throw ( IOException, lang::exceptions::NullPointerException ){
+
+    try{
+
+        if( activeBuffer == NULL ){
+            throw IOException(
+                __FILE__, __LINE__,
+                "ByteArrayInputStream::read - Buffer has not been initialized" );
+        }
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "ByteArrayInputStream::read - Buffer passed is Null" );
+        }
+
+        std::size_t ix = 0;
+
+        if( pos == activeBuffer->end() ) {
+            return -1;
+        }
+
+        // How far are we from end
+        std::size_t remaining = (std::size_t)distance( pos, activeBuffer->end() );
+
+        // We only read as much as is left if the amount remaining is less than
+        // the amount of data asked for.
+        bufferSize = remaining < bufferSize ? remaining : bufferSize;
+
+        for( ; ix < bufferSize; ++ix, ++pos) {
+            buffer[ix + offset] = *(pos);
+        }
+
+        return (int)ix;
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t ByteArrayInputStream::skip( std::size_t num )
+    throw ( IOException, lang::exceptions::UnsupportedOperationException ){
+
+    if( activeBuffer == NULL ){
+        throw IOException(
+            __FILE__, __LINE__,
+            "ByteArrayInputStream::skip - Buffer has not been initialized" );
+    }
+
+    std::size_t ix = 0;
+
+    // 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;
+}

Added: activemq/activemq-cpp/trunk/src/main/decaf/io/ByteArrayInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/io/ByteArrayInputStream.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/io/ByteArrayInputStream.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/io/ByteArrayInputStream.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,265 @@
+/*
+ * 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_BYTEARRAYINPUTSTREAM_H_
+#define _DECAF_IO_BYTEARRAYINPUTSTREAM_H_
+
+#include <decaf/io/InputStream.h>
+#include <decaf/util/concurrent/Mutex.h>
+#include <vector>
+#include <algorithm>
+
+namespace decaf{
+namespace io{
+
+    /**
+     * Simple implementation of InputStream that wraps around an STL Vector
+     * std::vector<unsigned char>.
+     *
+     * Closing a ByteArrayInputStream has no effect. The methods in this class can be
+     * called after the stream has been closed without generating an IOException.
+     */
+    class DECAF_API ByteArrayInputStream : public InputStream {
+    private:
+
+        /**
+         * Default buffer to use, if none provided.
+         */
+        std::vector<unsigned char> defaultBuffer;
+
+        /**
+         * Reference to the buffer being used by this stream.
+         */
+        const std::vector<unsigned char>* activeBuffer;
+
+        /**
+         * iterator to current position in buffer.
+         */
+        std::vector<unsigned char>::const_iterator pos;
+
+        /**
+         * Synchronization object.
+         */
+        util::concurrent::Mutex mutex;
+
+        /**
+         * The currently marked position or begin() of activeBuffer.
+         */
+        std::vector<unsigned char>::const_iterator markpos;
+
+    public:
+
+        /**
+         * Default Constructor
+         */
+        ByteArrayInputStream();
+
+        /**
+         * Creates the input stream and calls setBuffer with the
+         * specified buffer object.
+         * @param buffer The buffer to be used.
+         */
+        ByteArrayInputStream( const std::vector<unsigned char>& buffer );
+
+        /**
+         * Constructor
+         * @param buffer initial byte array to use to read from
+         * @param bufferSize the size of the buffer
+         */
+        ByteArrayInputStream( const unsigned char* buffer,
+                              std::size_t bufferSize );
+
+        virtual ~ByteArrayInputStream();
+
+        /**
+         * Sets the internal buffer.  The input stream will wrap around
+         * this buffer and will perform all read operations on it.  The
+         * position will be reinitialized to the beginning of the specified
+         * buffer.  This class will not own the given buffer - it is the
+         * caller's responsibility to free the memory of the given buffer
+         * as appropriate.
+         * @param buffer The buffer to be used.
+         */
+        virtual void setBuffer( const std::vector<unsigned char>& buffer );
+
+        /**
+         * Sets the data that this reader uses, replaces any existing
+         * data and resets to beginning of the buffer.
+         * @param buffer initial byte array to use to read from
+         * @param bufferSize the size of the buffer
+         */
+        virtual void setByteArray( const unsigned char* buffer,
+                                   std::size_t bufferSize );
+
+        /**
+         * Indcates the number of bytes avaialable.
+         * @return The number of bytes until the end of the internal buffer.
+         */
+        virtual std::size_t available() const throw ( IOException ) {
+            if( activeBuffer == NULL ){
+                throw IOException(
+                    __FILE__, __LINE__,
+                    "buffer has not been initialized");
+            }
+
+            return std::distance( pos, activeBuffer->end() );
+        }
+
+        /**
+         * Reads a single byte from the buffer.
+         * @return The next byte.
+         * @throws IOException thrown if an error occurs.
+         */
+        virtual unsigned char read() throw ( IOException );
+
+        /**
+         * Reads an array of bytes from the buffer.
+         * @param buffer (out) the target buffer.
+         * @param offset the position in the buffer to start reading from.
+         * @param bufferSize the size of the output buffer.
+         * @return The number of bytes read.
+         * @throws IOException thrown if an error occurs.
+         */
+        virtual int read( unsigned char* buffer,
+                          std::size_t offset,
+                          std::size_t bufferSize )
+            throw ( IOException, lang::exceptions::NullPointerException );
+
+        /**
+         * Closes the target input stream.
+         * @throws IOException thrown if an error occurs.
+         */
+        virtual void close() throw( lang::Exception ){ /* do nothing */ }
+
+        /**
+         * Skips over and discards n bytes of data from this input stream. The
+         * skip method may, for a variety of reasons, end up skipping over some
+         * smaller number of bytes, possibly 0. This may result from any of a
+         * number of conditions; reaching end of file before n bytes have been
+         * skipped is only one possibility. The actual number of bytes skipped
+         * is returned. If n is negative, no bytes are skipped.
+         * <p>
+         * The skip method of InputStream creates a byte array and then
+         * repeatedly reads into it until n bytes have been read or the end
+         * of the stream has been reached. Subclasses are encouraged to
+         * provide a more efficient implementation of this method.
+         * @param num - the number of bytes to skip
+         * @returns total butes skipped
+         * @throws IOException if an error occurs
+         */
+        virtual std::size_t skip( std::size_t num )
+            throw ( io::IOException, lang::exceptions::UnsupportedOperationException );
+
+        /**
+         * Marks the current position in the stream A subsequent call to the
+         * reset method repositions this stream at the last marked position so
+         * that subsequent reads re-read the same bytes.
+         *
+         * If a stream instance reports that marks are supported then the stream
+         * will ensure that the same bytes can be read again after the reset method
+         * is called so long the readLimit is not reached.
+         * @param readLimit - max bytes read before marked position is invalid.
+         */
+        virtual void mark( int readLimit DECAF_UNUSED ) {
+            // the reset point is now the marked position until a new byte buffer
+            // is set on this stream.
+            this->markpos = pos;
+        }
+
+        /**
+         * Resets the read index to the beginning of the byte array, unless mark
+         * has been called and the markLimit has not been exceeded, in which case
+         * the stream is reset to the marked position.
+         */
+        virtual void reset() throw ( IOException );
+
+        /**
+         * Determines if this input stream supports the mark and reset methods.
+         * Whether or not mark and reset are supported is an invariant property of
+         * a particular input stream instance.
+         * @returns true if this stream instance supports marks
+         */
+        virtual bool markSupported() const{ return true; }
+
+    protected:
+
+        /**
+         * Waits on a signal from this object, which is generated
+         * by a call to Notify.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void lock() throw( lang::Exception ){
+            mutex.lock();
+        }
+
+        /**
+         * Unlocks the object.
+         * @throws Exception
+         */
+        virtual void unlock() throw( lang::Exception ){
+            mutex.unlock();
+        }
+
+        /**
+         * Waits on a signal from this object, which is generated
+         * by a call to Notify.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void wait() throw( lang::Exception ){
+            mutex.wait();
+        }
+
+        /**
+         * Waits on a signal from this object, which is generated
+         * by a call to Notify.  Must have this object locked before
+         * calling.  This wait will timeout after the specified time
+         * interval.
+         * @param millisecs the time in millisecsonds to wait, or
+         * WAIT_INIFINITE
+         * @throws Exception
+         */
+        virtual void wait( unsigned long millisecs ) throw( lang::Exception ){
+            mutex.wait( millisecs );
+        }
+
+        /**
+         * Signals a waiter on this object that it can now wake
+         * up and continue.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void notify() throw( lang::Exception ){
+            mutex.notify();
+        }
+
+        /**
+         * Signals the waiters on this object that it can now wake
+         * up and continue.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void notifyAll() throw( lang::Exception ){
+            mutex.notifyAll();
+        }
+
+    };
+
+}}
+
+#endif /*_DECAF_IO_BYTEARRAYINPUTSTREAM_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/io/ByteArrayOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/io/ByteArrayOutputStream.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/io/ByteArrayOutputStream.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/io/ByteArrayOutputStream.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,117 @@
+/*
+ * 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 "ByteArrayOutputStream.h"
+#include <algorithm>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::io;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayOutputStream::ByteArrayOutputStream() {
+    activeBuffer = &defaultBuffer;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayOutputStream::ByteArrayOutputStream( vector<unsigned char>& buffer) {
+    setBuffer( buffer );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStream::setBuffer( vector<unsigned char>& buffer) {
+    activeBuffer = &buffer;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStream::reset() throw ( IOException ) {
+    // Empty the contents of the buffer to the output stream.
+    activeBuffer->clear();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStream::write( unsigned char c )
+    throw ( IOException ) {
+    activeBuffer->push_back( c );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStream::write( const std::vector<unsigned char>& buffer )
+    throw ( IOException ) {
+
+    try{
+
+        if( buffer.empty() ) {
+            return;
+        }
+
+        this->write( &buffer[0], 0, buffer.size() );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStream::write( const unsigned char* buffer,
+                                   std::size_t offset,
+                                   std::size_t len )
+    throw ( IOException, lang::exceptions::NullPointerException ) {
+
+    if( buffer == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__,
+            "ByteArrayOutputStream::write - passed buffer is null" );
+    }
+
+    std::back_insert_iterator< std::vector<unsigned char> > iter( *activeBuffer );
+    std::copy( buffer + offset, buffer + offset + len, iter );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string ByteArrayOutputStream::toString() const {
+
+    if( this->activeBuffer->empty() ) {
+        return "";
+    }
+
+    return string( (const char*)this->toByteArray(), this->size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStream::writeTo( OutputStream* out ) const
+    throw ( IOException, lang::exceptions::NullPointerException ) {
+
+    try{
+
+        if( this->size() == 0 ) {
+            return;
+        }
+
+        if( out == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "ByteArrayOutputStream::writeTo - Passed stream pointer is null" );
+        }
+
+        out->write( this->toByteArray(), 0, this->size() );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCHALL_THROW( IOException )
+}

Added: activemq/activemq-cpp/trunk/src/main/decaf/io/ByteArrayOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/io/ByteArrayOutputStream.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/io/ByteArrayOutputStream.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/io/ByteArrayOutputStream.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,219 @@
+/*
+ * 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_BYTEARRAYOUTPUTSTREAM_H_
+#define _DECAF_IO_BYTEARRAYOUTPUTSTREAM_H_
+
+#include <decaf/io/OutputStream.h>
+#include <decaf/util/concurrent/Mutex.h>
+#include <vector>
+
+namespace decaf{
+namespace io{
+
+    class DECAF_API ByteArrayOutputStream : public OutputStream {
+    private:
+
+        /**
+         * Default buffer to use, if none provided.
+         */
+        std::vector<unsigned char> defaultBuffer;
+
+        /**
+         * Reference to the buffer being used by this stream.
+         */
+        std::vector<unsigned char>* activeBuffer;
+
+        /**
+         * Synchronization object.
+         */
+        util::concurrent::Mutex mutex;
+
+    public:
+
+        /**
+         * Default Constructor - uses a default internal buffer
+         */
+        ByteArrayOutputStream();
+
+        /**
+         * Uses the given buffer as the target.  Calls setBuffer.
+         * @param buffer the target buffer.
+         */
+        ByteArrayOutputStream( std::vector<unsigned char>& buffer );
+
+        /**
+         * Destructor
+         */
+        virtual ~ByteArrayOutputStream() {};
+
+        /**
+         * Sets the internal buffer.  This input stream will wrap around
+         * the given buffer and all writes will be performed directly on
+         * the buffer.  This object does not retain control of the buffer's
+         * lifetime however - this is the job of the caller.
+         * @param buffer The target buffer.
+         */
+        virtual void setBuffer( std::vector<unsigned char>& buffer );
+
+        /**
+         * Get a snapshot of the data
+         * @return pointer to the data
+         */
+        virtual const unsigned char* toByteArray() const {
+            if( activeBuffer->size() == 0 ){
+                return NULL;
+            }
+
+            return &(*activeBuffer)[0];
+        }
+
+        /**
+         * Get the Size of the Internal Buffer
+         * @return size of the internal buffer
+         */
+        virtual std::size_t size() const {
+            return activeBuffer->size();
+        }
+
+        /**
+         * Writes a single byte to the output stream.
+         * @param c the byte.
+         * @throws IOException thrown if an error occurs.
+         */
+        virtual void write( unsigned char c )
+           throw ( IOException );
+
+        /**
+         * Writes an array of bytes to the output stream.
+         * @param buffer The bytes to write.
+         * @throws IOException thrown if an error occurs.
+         */
+        virtual void write( const std::vector<unsigned char>& buffer )
+            throw ( IOException );
+
+        /**
+         * Writes an array of bytes to the output stream.
+         * @param buffer The array of bytes to write.
+         * @param offset, the position to start writing in buffer.
+         * @param len The number of bytes from the buffer to be written.
+         * @throws IOException thrown if an error occurs.
+         * @throws NullPointerException thrown if buffer is Null.
+         */
+        virtual void write( const unsigned char* buffer,
+                            std::size_t offset,
+                            std::size_t len )
+            throw ( IOException, lang::exceptions::NullPointerException );
+
+        /**
+         * Invokes flush on the target output stream, has no affect.
+         * @throws IOException
+         */
+        virtual void flush() throw ( IOException ){ /* do nothing */ }
+
+        /**
+         * Clear current Stream contents
+         * @throws IOException
+         */
+        virtual void reset() throw ( IOException );
+
+        /**
+         * Invokes close on the target output stream.
+         * @throws CMSException
+         */
+        void close() throw( lang::Exception ){ /* do nothing */ }
+
+        /**
+         * Converts the bytes in the buffer into a standard C++ string
+         * @returns a string contianing the bytes in the buffer
+         */
+        std::string toString() const;
+
+        /**
+         * Writes the complete contents of this byte array output stream to the
+         * specified output stream argument, as if by calling the output
+         * stream's write method using out.write( buf, 0, count ).
+         */
+        void writeTo( OutputStream* out ) const
+            throw ( IOException, lang::exceptions::NullPointerException );
+
+    public:
+
+        /**
+         * Waits on a signal from this object, which is generated
+         * by a call to Notify.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void lock() throw( lang::Exception ){
+            mutex.lock();
+        }
+
+        /**
+         * Unlocks the object.
+         * @throws Exception
+         */
+        virtual void unlock() throw( lang::Exception ){
+            mutex.unlock();
+        }
+
+        /**
+         * Waits on a signal from this object, which is generated
+         * by a call to Notify.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void wait() throw( lang::Exception ){
+            mutex.wait();
+        }
+
+        /**
+         * Waits on a signal from this object, which is generated
+         * by a call to Notify.  Must have this object locked before
+         * calling.  This wait will timeout after the specified time
+         * interval.
+         * @param time in millisecsonds to wait, or WAIT_INIFINITE
+         * @throws Exception
+         */
+        virtual void wait( unsigned long millisecs ) throw( lang::Exception ){
+            mutex.wait(millisecs);
+        }
+
+        /**
+         * Signals a waiter on this object that it can now wake
+         * up and continue.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void notify() throw( lang::Exception ){
+            mutex.notify();
+        }
+
+        /**
+         * Signals the waiters on this object that it can now wake
+         * up and continue.  Must have this object locked before
+         * calling.
+         * @throws Exception
+         */
+        virtual void notifyAll() throw( lang::Exception ){
+            mutex.notifyAll();
+        }
+    };
+
+}}
+
+#endif /*_DECAF_IO_BYTEARRAYOUTPUTSTREAM_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/io/Closeable.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/io/Closeable.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/io/Closeable.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/io/Closeable.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,46 @@
+/*
+ * 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_CLOSEABLE_H_
+#define _DECAF_IO_CLOSEABLE_H_
+
+#include <decaf/lang/Exception.h>
+
+namespace decaf{
+namespace io{
+
+    /**
+     * Interface for a class that implements the close method.
+     */
+    class DECAF_API Closeable{
+
+    public:
+
+        virtual ~Closeable(){}
+
+        /**
+         * Closes this object and deallocates the appropriate resources.
+         * The object is generally no longer usable after calling close.
+         * @throws CMSException
+         */
+        virtual void close() throw( lang::Exception ) = 0;
+
+    };
+
+}}
+
+#endif /*_DECAF_IO_CLOSEABLE_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/io/DataInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/io/DataInputStream.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/io/DataInputStream.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/io/DataInputStream.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,386 @@
+/*
+ * 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 <decaf/io/DataInputStream.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::io;
+using namespace decaf::util;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+DataInputStream::DataInputStream( InputStream* inputStream, bool own )
+ : FilterInputStream( inputStream, own ) {}
+
+////////////////////////////////////////////////////////////////////////////////
+DataInputStream::~DataInputStream() {}
+
+////////////////////////////////////////////////////////////////////////////////
+int DataInputStream::read( std::vector<unsigned char>& buffer )
+    throw ( io::IOException ) {
+
+    try {
+        return this->read( &buffer[0], 0, buffer.size() );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int DataInputStream::read( unsigned char* buffer,
+                           std::size_t offset,
+                           std::size_t length )
+    throw ( IOException, NullPointerException ) {
+
+    try {
+
+        if( length == 0 ) {
+            return 0;
+        }
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "DataInputStream::read - Buffer is null" );
+        }
+
+        if( inputStream == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "DataInputStream::readFully - Base input stream is null" );
+        }
+
+        return inputStream->read( &buffer[offset], 0, length );
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool DataInputStream::readBoolean()
+    throw( IOException, EOFException ) {
+
+    try {
+        unsigned char value = 0;
+        readAllData( &value, sizeof(value) );
+        return (bool)( value != 0 );
+    }
+    DECAF_CATCH_RETHROW( EOFException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+char DataInputStream::readByte()
+    throw ( IOException, EOFException ) {
+
+    try {
+        unsigned char value = 0;
+        readAllData( &value, sizeof(value) );
+        return (char)( value );
+    }
+    DECAF_CATCH_RETHROW( EOFException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned char DataInputStream::readUnsignedByte()
+    throw ( IOException, EOFException ) {
+
+    try {
+        unsigned char value = 0;
+        readAllData( &value, sizeof(value) );
+        return value;
+    }
+    DECAF_CATCH_RETHROW( EOFException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+char DataInputStream::readChar() throw ( IOException, EOFException ) {
+    try {
+        unsigned char value = 0;
+        readAllData( &value, sizeof(value) );
+        return (char)( value );
+    }
+    DECAF_CATCH_RETHROW( EOFException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+short DataInputStream::readShort() throw ( io::IOException, io::EOFException ) {
+    try {
+        short value = 0;
+        unsigned char buffer[sizeof(value)] = {0};
+        readAllData( buffer, sizeof(value) );
+        value |= (buffer[0] << 8 | buffer[1] << 0);
+        return value;
+    }
+    DECAF_CATCH_RETHROW( EOFException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned short DataInputStream::readUnsignedShort()
+    throw ( io::IOException, io::EOFException ) {
+    try {
+        unsigned short value = 0;
+        unsigned char buffer[sizeof(value)] = {0};
+        readAllData( buffer, sizeof(value) );
+        value |= (buffer[0] << 8 | buffer[1] << 0);
+        return value;
+    }
+    DECAF_CATCH_RETHROW( EOFException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int DataInputStream::readInt() throw ( io::IOException, io::EOFException ) {
+    try {
+        unsigned int value = 0;
+        unsigned char buffer[sizeof(value)] = {0};
+        readAllData( buffer, sizeof(value) );
+        value |= (buffer[0] << 24 | buffer[1] << 16 |
+                  buffer[2] << 8 | buffer[3] << 0);
+        return value;
+    }
+    DECAF_CATCH_RETHROW( EOFException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+double DataInputStream::readDouble() throw ( io::IOException, io::EOFException ) {
+    try {
+        unsigned long long lvalue = this->readLong();
+        double value = 0.0;
+        memcpy( &value, &lvalue, sizeof( unsigned long long ) );
+        return value;
+    }
+    DECAF_CATCH_RETHROW( EOFException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+float DataInputStream::readFloat() throw ( io::IOException, io::EOFException ) {
+    try {
+        unsigned int lvalue = this->readInt();
+        float value = 0.0f;
+        memcpy( &value, &lvalue, sizeof( unsigned int ) );
+        return value;
+    }
+    DECAF_CATCH_RETHROW( EOFException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long DataInputStream::readLong()
+    throw ( io::IOException, io::EOFException ) {
+    try {
+        unsigned long long value = 0;
+        unsigned char buffer[sizeof(value)] = {0};
+        readAllData( buffer, sizeof(value) );
+
+        // Have to do it this way because on Solaris and Cygwin we get all
+        // kinds of warnings when shifting a byte up into a long long.
+        unsigned long long byte1 = buffer[0] & 0x00000000000000FFULL;
+        unsigned long long byte2 = buffer[1] & 0x00000000000000FFULL;
+        unsigned long long byte3 = buffer[2] & 0x00000000000000FFULL;
+        unsigned long long byte4 = buffer[3] & 0x00000000000000FFULL;
+        unsigned long long byte5 = buffer[4] & 0x00000000000000FFULL;
+        unsigned long long byte6 = buffer[5] & 0x00000000000000FFULL;
+        unsigned long long byte7 = buffer[6] & 0x00000000000000FFULL;
+        unsigned long long byte8 = buffer[7] & 0x00000000000000FFULL;
+
+        value = ( byte1 << 56 | byte2 << 48 | byte3 << 40 | byte4 << 32 |
+                  byte5 << 24 | byte6 << 16 | byte7 << 8  | byte8 << 0 );
+
+        return value;
+    }
+    DECAF_CATCH_RETHROW( EOFException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string DataInputStream::readString()
+    throw ( io::IOException, io::EOFException ) {
+    try {
+
+        if( inputStream == NULL ) {
+            throw IOException(
+                __FILE__, __LINE__,
+                "DataInputStream::readFully - Base input stream is null" );
+        }
+
+        size_t size = 1024;
+        std::vector<char> buffer;
+        buffer.resize( size );
+        size_t pos = 0;
+
+        while( true ) {
+
+            if( inputStream->read( (unsigned char*)( &buffer[pos] ), 0, 1 ) == -1 ) {
+                throw EOFException(
+                    __FILE__, __LINE__,
+                    "DataInputStream::readString - Reached EOF" );
+            }
+
+            // if null is found we are done
+            if( buffer[pos] == '\0' ){
+                break;
+            }
+
+            // Resize to hold more if we exceed current size
+            if( ++pos > size ) {
+                buffer.resize( (size *= 2) );
+            }
+        }
+
+        return &buffer[0];
+    }
+    DECAF_CATCH_RETHROW( EOFException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string DataInputStream::readUTF()
+    throw ( io::IOException, io::EOFException ) {
+    try {
+
+        if( inputStream == NULL ) {
+            throw IOException(
+                __FILE__, __LINE__,
+                "DataInputStream::readFully - Base input stream is null" );
+        }
+
+        std::vector<unsigned char> buffer;
+        unsigned short length = readUnsignedShort();
+        buffer.resize(length + 1);  // Add one for a null charactor.
+
+        std::size_t n = 0;
+        while( n < length ) {
+            int count = inputStream->read( &buffer[n], 0, (length - n) );
+            if( count == -1 ) {
+                throw EOFException(
+                    __FILE__, __LINE__,
+                    "DataInputStream::readUTF - Reached EOF" );
+            }
+            n += count;
+        }
+
+        return (char*)&buffer[0];
+    }
+    DECAF_CATCH_RETHROW( EOFException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStream::readFully( std::vector< unsigned char >& buffer )
+    throw ( io::IOException, io::EOFException ) {
+    try {
+        if( buffer.empty() ) {
+            return;
+        }
+        this->readFully( &buffer[0], 0, buffer.size() );
+    }
+    DECAF_CATCH_RETHROW( EOFException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStream::readFully( unsigned char* buffer,
+                                 std::size_t offset,
+                                 std::size_t length )
+    throw ( io::IOException,
+            io::EOFException,
+            lang::exceptions::NullPointerException )
+{
+    try {
+
+        if( length == 0 ) {
+            return;
+        }
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "DataInputStream::readFully - Buffer is null" );
+        }
+
+        if( inputStream == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "DataInputStream::readFully - Base input stream is null" );
+        }
+
+        std::size_t n = 0;
+        while( n < length ) {
+            int count = inputStream->read( &buffer[offset + n], 0, (length - n) );
+            if( count == -1 ) {
+                throw EOFException(
+                    __FILE__, __LINE__,
+                    "DataInputStream::readFully - Reached EOF" );
+            }
+            n += count;
+        }
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( EOFException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t DataInputStream::skip( std::size_t num )
+    throw( io::IOException, lang::exceptions::UnsupportedOperationException ) {
+    try {
+
+        if( inputStream == NULL ) {
+            throw IOException(
+                __FILE__, __LINE__,
+                "DataInputStream::readFully - Base input stream is null" );
+        }
+
+        std::size_t total = 0;
+        std::size_t cur = 0;
+
+        while( ( total < num ) &&
+               ( ( cur = inputStream->skip( num-total ) ) > 0 ) ) {
+            total += cur;
+        }
+
+        return total;
+    }
+    DECAF_CATCH_RETHROW( UnsupportedOperationException )
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCHALL_THROW( IOException )
+}



Mime
View raw message