activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r724718 - in /activemq/activemq-cpp/trunk/src/main: ./ decaf/internal/io/ decaf/io/
Date Tue, 09 Dec 2008 14:42:04 GMT
Author: tabish
Date: Tue Dec  9 06:42:03 2008
New Revision: 724718

URL: http://svn.apache.org/viewvc?rev=724718&view=rev
Log:
Refactoring Decaf's standard input / output streams

Added:
    activemq/activemq-cpp/trunk/src/main/decaf/internal/io/
    activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardErrorOutputStream.cpp 
 (with props)
    activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardErrorOutputStream.h   (with
props)
    activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardInputStream.cpp   (with
props)
    activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardInputStream.h   (with props)
    activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardOutputStream.cpp   (with
props)
    activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardOutputStream.h   (with
props)
Removed:
    activemq/activemq-cpp/trunk/src/main/decaf/io/StandardErrorOutputStream.h
Modified:
    activemq/activemq-cpp/trunk/src/main/Makefile.am

Modified: activemq/activemq-cpp/trunk/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/Makefile.am?rev=724718&r1=724717&r2=724718&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/src/main/Makefile.am Tue Dec  9 06:42:03 2008
@@ -85,6 +85,9 @@
     decaf/internal/AprPool.cpp \
     decaf/internal/util/ByteArrayAdapter.cpp \
     decaf/internal/util/HexStringParser.cpp \
+    decaf/internal/io/StandardErrorOutputStream.cpp \
+    decaf/internal/io/StandardOutputStream.cpp \
+    decaf/internal/io/StandardInputStream.cpp \
     decaf/internal/nio/BufferFactory.cpp \
     decaf/internal/nio/ByteArrayPerspective.cpp \
     decaf/internal/nio/ByteArrayBuffer.cpp \
@@ -365,7 +368,6 @@
     decaf/lang/exceptions/InterruptedException.h \
     decaf/lang/exceptions/NumberFormatException.h \
     decaf/io/BufferedOutputStream.h \
-    decaf/io/StandardErrorOutputStream.h \
     decaf/io/OutputStream.h \
     decaf/io/Writer.h \
     decaf/io/ByteArrayOutputStream.h \
@@ -440,6 +442,9 @@
     decaf/internal/DecafRuntime.h \
     decaf/internal/util/HexStringParser.h \
     decaf/internal/util/ByteArrayAdapter.h \
+    decaf/internal/io/StandardErrorOutputStream.h \
+    decaf/internal/io/StandardOutputStream.h \
+    decaf/internal/io/StandardInputStream.h \
     decaf/internal/nio/BufferFactory.h \
     decaf/internal/nio/ByteArrayPerspective.h \
     decaf/internal/nio/ByteArrayBuffer.h \

Added: activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardErrorOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardErrorOutputStream.cpp?rev=724718&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardErrorOutputStream.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardErrorOutputStream.cpp Tue
Dec  9 06:42:03 2008
@@ -0,0 +1,80 @@
+/*
+ * 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 "StandardErrorOutputStream.h"
+
+#include <apr.h>
+#include <apr_general.h>
+#include <apr_pools.h>
+
+using namespace decaf;
+using namespace decaf::internal;
+using namespace decaf::internal::io;
+
+////////////////////////////////////////////////////////////////////////////////
+StandardErrorOutputStream::StandardErrorOutputStream() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+StandardErrorOutputStream::~StandardErrorOutputStream() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StandardErrorOutputStream::write( unsigned char c )
+    throw ( decaf::io::IOException ) {
+
+    std::cerr << c;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StandardErrorOutputStream::write( const std::vector<unsigned char>& buffer
)
+    throw ( decaf::io::IOException ) {
+
+    if( buffer.empty() ){
+        return;
+    }
+
+    this->write( &buffer[0], 0, buffer.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StandardErrorOutputStream::write( const unsigned char* buffer,
+                                       std::size_t offset,
+                                       std::size_t len )
+    throw ( decaf::io::IOException, lang::exceptions::NullPointerException ) {
+
+    if( buffer == NULL ) {
+        throw lang::exceptions::NullPointerException(
+            __FILE__, __LINE__,
+            "StandardErrorOutputStream::write - Passed buffer is null." );
+    }
+
+    if( offset > len ) {
+        throw decaf::io::IOException(
+            __FILE__, __LINE__,
+            "StandardErrorOutputStream::write - offset passed is greater than length" );
+    }
+
+    for( int i = 0; i < len; ++i ) {
+        std::cerr << buffer[i+offset];
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StandardErrorOutputStream::flush() throw ( decaf::io::IOException ){
+    std::cerr.flush();
+}

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

Added: activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardErrorOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardErrorOutputStream.h?rev=724718&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardErrorOutputStream.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardErrorOutputStream.h Tue
Dec  9 06:42:03 2008
@@ -0,0 +1,159 @@
+/*
+ * 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_INTERNAL_IO_STANDARDERROROUTPUTSTREAM_H_
+#define _DECAF_INTERNAL_IO_STANDARDERROROUTPUTSTREAM_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/io/OutputStream.h>
+#include <decaf/util/concurrent/Mutex.h>
+
+namespace decaf{
+namespace internal{
+namespace io{
+
+    /**
+     * Wrapper Around the Standard error Output facility on the current
+     * platform.  This allows for the use of alternate output methods on
+     * platforms or compilers that do not support <code>std::cerr</code>.
+     */
+    class DECAF_API StandardErrorOutputStream : public decaf::io::OutputStream {
+    private:
+
+        /**
+         * Synchronization object.
+         */
+        util::concurrent::Mutex mutex;
+
+    public:
+
+        /**
+         * Default Constructor
+         */
+        StandardErrorOutputStream();
+
+        virtual ~StandardErrorOutputStream();
+
+        /**
+         * 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 ( decaf::io::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 ( decaf::io::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 decaf::io::IOException thrown if an error occurs.
+         * @throws NullPointerException if buffer is null.
+         */
+        virtual void write( const unsigned char* buffer,
+                            std::size_t offset,
+                            std::size_t len )
+            throw ( decaf::io::IOException, lang::exceptions::NullPointerException );
+
+        /**
+         * Invokes flush on the target output stream.
+         * throws decaf::io::IOException if an error occurs
+         */
+        virtual void flush() throw ( decaf::io::IOException );
+
+        /**
+         * Invokes close on the target output stream.
+         * throws CMSException if an error occurs
+         */
+        virtual void close() throw( decaf::lang::Exception ){
+            this->flush();
+        }
+
+    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( decaf::lang::Exception ){
+            mutex.lock();
+        }
+
+        /**
+         * Unlocks the object.
+         * @throws Exception
+         */
+        virtual void unlock() throw( decaf::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( decaf::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 milliseconds to wait, or WAIT_INIFINITE
+         * @throws Exception
+         */
+        virtual void wait( unsigned long millisecs ) throw( decaf::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( decaf::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( decaf::lang::Exception ){
+            mutex.notifyAll();
+        }
+
+    };
+
+}}}
+
+#endif /*_DECAF_INTERNAL_IO_STANDARDERROROUTPUTSTREAM_H_*/

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

Added: activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardInputStream.cpp?rev=724718&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardInputStream.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardInputStream.cpp Tue Dec
 9 06:42:03 2008
@@ -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 "StandardInputStream.h"
+
+#include <iostream>
+
+#include <apr.h>
+#include <apr_general.h>
+#include <apr_pools.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::internal;
+using namespace decaf::internal::io;
+
+////////////////////////////////////////////////////////////////////////////////
+StandardInputStream::StandardInputStream() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+StandardInputStream::~StandardInputStream() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t StandardInputStream::available() const throw ( decaf::io::IOException ) {
+    return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned char StandardInputStream::read() throw ( decaf::io::IOException ) {
+
+    if( !std::cin.good() ) {
+        throw decaf::io::IOException(
+            __FILE__, __LINE__,
+            "Standard Input Stream in Error State." );
+    }
+
+    return std::cin.get();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int StandardInputStream::read( unsigned char* buffer,
+                               std::size_t offset,
+                               std::size_t bufferSize )
+    throw ( decaf::io::IOException, decaf::lang::exceptions::NullPointerException ) {
+
+    if( buffer == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__,
+            "ByteArrayInputStream::read - Buffer passed is Null" );
+    }
+
+    return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t StandardInputStream::skip( std::size_t num )
+    throw ( decaf::io::IOException,
+            decaf::lang::exceptions::UnsupportedOperationException ) {
+
+    return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StandardInputStream::reset() throw ( decaf::io::IOException ) {
+
+    throw decaf::io::IOException(
+        __FILE__, __LINE__,
+        "Mark and Rest not Supported by this class." );
+}

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

Added: activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardInputStream.h?rev=724718&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardInputStream.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardInputStream.h Tue Dec 
9 06:42:03 2008
@@ -0,0 +1,213 @@
+/*
+ * 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_INTERNAL_IO_STANDARDINPUTSTREAM_H_
+#define _DECAF_INTERNAL_IO_STANDARDINPUTSTREAM_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/io/InputStream.h>
+#include <decaf/util/concurrent/Mutex.h>
+
+namespace decaf {
+namespace internal {
+namespace io {
+
+    class DECAF_API StandardInputStream : public decaf::io::InputStream {
+    private:
+
+        /**
+         * Synchronization object.
+         */
+        util::concurrent::Mutex mutex;
+
+    public:
+
+        StandardInputStream();
+        virtual ~StandardInputStream();
+
+        /**
+         * Indicates the number of bytes available.
+         * @return The number of bytes until the end of the internal buffer.
+         */
+        virtual std::size_t available() const throw ( decaf::io::IOException );
+
+        /**
+         * Reads a single byte from the buffer.
+         * @return The next byte.
+         * @throws IOException thrown if an error occurs.
+         */
+        virtual unsigned char read() throw ( decaf::io::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 decaf::io::IOException thrown if an error occurs.
+         * @throws decaf::lang::exceptions::NullPointerException if buffer is null.
+         */
+        virtual int read( unsigned char* buffer,
+                          std::size_t offset,
+                          std::size_t bufferSize )
+            throw ( decaf::io::IOException, decaf::lang::exceptions::NullPointerException
);
+
+        /**
+         * Closes the target input stream.
+         * @throws decaf::io::IOException thrown 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 bytes skipped
+         *
+         * @throws decaf::io::IOException if an error occurs
+         * @throws decaf::lang::exceptions::UnsupportedOperationException
+         *         If skip is not supported.
+         */
+        virtual std::size_t skip( std::size_t num )
+            throw ( decaf::io::IOException,
+                    decaf::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 ( decaf::io::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 false; }
+
+    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 milliseconds 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_INTERNAL_IO_STANDARDINPUTSTREAM_H_ */

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

Added: activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardOutputStream.cpp?rev=724718&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardOutputStream.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardOutputStream.cpp Tue Dec
 9 06:42:03 2008
@@ -0,0 +1,80 @@
+/*
+ * 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 "StandardOutputStream.h"
+
+#include <apr.h>
+#include <apr_general.h>
+#include <apr_pools.h>
+
+using namespace decaf;
+using namespace decaf::internal;
+using namespace decaf::internal::io;
+
+////////////////////////////////////////////////////////////////////////////////
+StandardOutputStream::StandardOutputStream() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+StandardOutputStream::~StandardOutputStream() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StandardOutputStream::write( unsigned char c )
+    throw ( decaf::io::IOException ) {
+
+    std::cout << c;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StandardOutputStream::write( const std::vector<unsigned char>& buffer )
+    throw ( decaf::io::IOException ) {
+
+    if( buffer.empty() ){
+        return;
+    }
+
+    this->write( &buffer[0], 0, buffer.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StandardOutputStream::write( const unsigned char* buffer,
+                                       std::size_t offset,
+                                       std::size_t len )
+    throw ( decaf::io::IOException, lang::exceptions::NullPointerException ) {
+
+    if( buffer == NULL ) {
+        throw lang::exceptions::NullPointerException(
+            __FILE__, __LINE__,
+            "StandardOutputStream::write - Passed buffer is null." );
+    }
+
+    if( offset > len ) {
+        throw decaf::io::IOException(
+            __FILE__, __LINE__,
+            "StandardOutputStream::write - offset passed is greater than length" );
+    }
+
+    for( int i = 0; i < len; ++i ) {
+        std::cout << buffer[i+offset];
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StandardOutputStream::flush() throw ( decaf::io::IOException ){
+    std::cout.flush();
+}

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

Added: activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardOutputStream.h?rev=724718&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardOutputStream.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/io/StandardOutputStream.h Tue Dec
 9 06:42:03 2008
@@ -0,0 +1,150 @@
+/*
+ * 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_INTERNAL_IO_STANDARDOUTPUTSTREAM_H_
+#define _DECAF_INTERNAL_IO_STANDARDOUTPUTSTREAM_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/io/OutputStream.h>
+#include <decaf/util/concurrent/Mutex.h>
+
+namespace decaf {
+namespace internal {
+namespace io {
+
+    class DECAF_API StandardOutputStream : public decaf::io::OutputStream {
+    private:
+
+        /**
+         * Synchronization object.
+         */
+        util::concurrent::Mutex mutex;
+
+    public:
+
+        StandardOutputStream();
+        virtual ~StandardOutputStream();
+
+        /**
+         * 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 ( decaf::io::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 ( decaf::io::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 decaf::io::IOException thrown if an error occurs.
+         * @throws NullPointerException if buffer is null.
+         */
+        virtual void write( const unsigned char* buffer,
+                            std::size_t offset,
+                            std::size_t len )
+            throw ( decaf::io::IOException, lang::exceptions::NullPointerException );
+
+        /**
+         * Invokes flush on the target output stream.
+         * throws decaf::io::IOException if an error occurs
+         */
+        virtual void flush() throw ( decaf::io::IOException );
+
+        /**
+         * Invokes close on the target output stream.
+         * throws CMSException if an error occurs
+         */
+        virtual void close() throw( decaf::lang::Exception ){
+            this->flush();
+        }
+
+    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( decaf::lang::Exception ){
+            mutex.lock();
+        }
+
+        /**
+         * Unlocks the object.
+         * @throws Exception
+         */
+        virtual void unlock() throw( decaf::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( decaf::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 milliseconds to wait, or WAIT_INIFINITE
+         * @throws Exception
+         */
+        virtual void wait( unsigned long millisecs ) throw( decaf::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( decaf::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( decaf::lang::Exception ){
+            mutex.notifyAll();
+        }
+    };
+
+}}}
+
+#endif /* _DECAF_INTERNAL_IO_STANDARDOUTPUTSTREAM_H_ */

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



Mime
View raw message