You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2007/05/31 13:56:03 UTC
svn commit: r543121 [2/6] - in /activemq/activemq-cpp/trunk/src/decaf: io/
lang/ lang/exceptions/ net/ util/ util/concurrent/ util/logging/
Added: activemq/activemq-cpp/trunk/src/decaf/io/DataInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/io/DataInputStream.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/io/DataInputStream.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/io/DataInputStream.h Thu May 31 04:55:59 2007
@@ -0,0 +1,354 @@
+/*
+ * 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_DATAINPUTSTREAM_H_
+#define _DECAF_IO_DATAINPUTSTREAM_H_
+
+#include <decaf/io/FilterInputStream.h>
+#include <decaf/io/IOException.h>
+#include <decaf/io/EOFException.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
+
+namespace decaf{
+namespace io{
+
+ /**
+ * A data input stream lets an application read primitive Java data
+ * types from an underlying input stream in a machine-independent way.
+ * An application uses a data output stream to write data that can
+ * later be read by a data input stream.
+ *
+ * Due to the lack of garbage collection in C++ a design decision was
+ * made to add a boolean parameter to the constructor indicating if the
+ * wrapped <code>InputStream</code> is owned by this object. That way
+ * creation of the underlying stream can occur in a Java like way. Ex:
+ *
+ * DataInputStream os = new DataInputStream( new InputStream(), true )
+ */
+ class DataInputStream : public FilterInputStream
+ {
+ public:
+
+ /**
+ * Creates a DataInputStream that uses the specified underlying
+ * InputStream.
+ * @param inputStream the InputStream instance to wrap.
+ * @param own, indicates if this class owns the wrapped string
+ * defaults to false.
+ */
+ DataInputStream( InputStream* inputStream, bool own = false );
+
+ virtual ~DataInputStream();
+
+ /**
+ * Reads some number of bytes from the contained input stream and
+ * stores them into the buffer array b. The number of bytes actually
+ * read is returned as an integer. This method blocks until input
+ * data is available, end of file is detected, or an exception is
+ * thrown.
+ * <p>
+ * If the length of buffer is zero, then no bytes are read and 0 is
+ * returned; otherwise, there is an attempt to read at least one
+ * byte. If no byte is available because the stream is at end of
+ * file, the value -1 is returned; otherwise, at least one byte is
+ * read and stored into buffer.
+ * <p>
+ * The first byte read is stored into element buffer[0], the next one
+ * into buffer[1], and so on. The number of bytes read is, at most,
+ * equal to the length of buffer. Let k be the number of bytes actually
+ * read; these bytes will be stored in elements b[0] through b[k-1],
+ * leaving elements buffer[k] through buffer[buffer.length-1]
+ * unaffected.
+ * <p>
+ * If the first byte cannot be read for any reason other than end
+ * of file, then an IOException is thrown. In particular, an
+ * IOException is thrown if the input stream has been closed.
+ * <p>
+ * The read( buffer ) method has the same effect as:
+ * read( buffer, 0, b.length )
+ * @param buffer - byte array to insert read data into
+ * @returns the total number of bytes read, or -1 if there is no
+ * more data because the stream is EOF.
+ * @throws IOException
+ */
+ virtual std::size_t read( std::vector< unsigned char >& buffer )
+ throw ( io::IOException );
+
+ /**
+ * Reads up to len bytes of data from the contained input stream
+ * into an array of bytes. An attempt is made to read as many as
+ * len bytes, but a smaller number may be read, possibly zero. The
+ * number of bytes actually read is returned as an integer.
+ * <p>
+ * This method blocks until input data is available, end of file is
+ * detected, or an exception is thrown.
+ * <p>
+ * If buffer is null, a NullPointerException is thrown.
+ * <p>
+ * If off is negative, or len is negative then an
+ * IndexOutOfBoundsException is thrown, if off + len is greater that
+ * the allocated length of the array, an IOException will result
+ * depending on the platform and compiler settings.
+ * <p>
+ * If len is zero, then no bytes are read and 0 is returned;
+ * otherwise, there is an attempt to read at least one byte. If no
+ * byte is available because the stream is at end of file, the
+ * value -1 is returned; otherwise, at least one byte is read and
+ * stored into buffer.
+ * <p>
+ * The first byte read is stored into element b[off], the next one
+ * into buffer[off+1], and so on. The number of bytes read is, at most,
+ * equal to len. Let k be the number of bytes actually read; these
+ * bytes will be stored in elements buffer[off] through buffer[off+k-1],
+ * leaving elements buffer[off+k] through buffer[off+len-1] unaffected.
+ * <p>
+ * In every case, elements buffer[0] through buffer[off] and elements
+ * buffer[off+len] through buffer[buffer.length-1] are unaffected.
+ * <p>
+ * If the first byte cannot be read for any reason other than end of
+ * file, then an IOException is thrown. In particular, an IOException
+ * is thrown if the input stream has been closed.
+ * @param buffer - byte array to insert read data into
+ * @param offset - location in buffer to start writing
+ * @param length - number of bytes to read
+ * @returns the total number of bytes read, or -1 if there is no
+ * more data because the stream is EOF.
+ * @throws IOException
+ */
+ virtual std::size_t read( unsigned char* buffer,
+ std::size_t offset,
+ std::size_t length )
+ throw ( io::IOException,
+ lang::exceptions::IndexOutOfBoundsException,
+ lang::exceptions::NullPointerException );
+
+ /**
+ * Reads one input byte and returns true if that byte is nonzero,
+ * false if that byte is zero.
+ * @returns the boolean value read.
+ * @throws IOException
+ * @throws EOFException
+ */
+ virtual bool readBoolean()
+ throw( io::IOException, io::EOFException );
+
+ /**
+ * Reads and returns one input byte. The byte is treated as a
+ * signed value in the range -128 through 127, inclusive.
+ * @returns the 8-bit value read.
+ * @throws IOException
+ * @throws EOFException
+ */
+ virtual char readByte()
+ throw ( io::IOException, io::EOFException );
+
+ /**
+ * Reads one input byte, zero-extends it to type int, and returns
+ * the result, which is therefore in the range 0 through 255.
+ * @returns the 8 bit unsigned value read
+ * @throws IOException
+ * @throws EOFException
+ */
+ virtual unsigned char readUnsignedByte()
+ throw ( io::IOException, io::EOFException );
+
+ /**
+ * Reads an input char and returns the char value. A ascii char
+ * is made up of one bytes. This returns the same result as
+ * <code>readByte</code>
+ * @returns the 8 bit char read
+ * @throws IOException
+ * @throws EOFException
+ */
+ virtual char readChar() throw ( io::IOException, io::EOFException );
+
+ /**
+ * Reads eight input bytes and returns a double value. It does this
+ * by first constructing a long long value in exactly the manner of
+ * the readlong method, then converting this long value to a double
+ * in exactly the manner of the method Double.longBitsToDouble.
+ * @returns the double value read
+ * @throws IOException
+ * @throws EOFException
+ */
+ virtual double readDouble()
+ throw ( io::IOException, io::EOFException );
+
+ /**
+ * Reads four input bytes and returns a float value. It does this
+ * by first constructing an int value in exactly the manner of the
+ * readInt method, then converting this int value to a float in
+ * exactly the manner of the method Float.intBitsToFloat.
+ * @returns the float value read
+ * @throws IOException
+ * @throws EOFException
+ */
+ virtual float readFloat() throw ( io::IOException, io::EOFException );
+
+ /**
+ * Reads four input bytes and returns an int value. Let a be the
+ * first byte read, b be the second byte, c be the third byte, and
+ * d be the fourth byte. The value returned is: <p>
+ * (((a & 0xff) << 24) | ((b & 0xff) << 16) |
+ * ((c & 0xff) << 8) | (d & 0xff))
+ * @returns the int value read
+ * @throws IOException
+ * @throws EOFException
+ */
+ virtual int readInt() throw ( io::IOException, io::EOFException );
+
+ /**
+ * Reads eight input bytes and returns a long value. Let a be the
+ * first byte read, b be the second byte, c be the third byte, d
+ * be the fourth byte, e be the fifth byte, f be the sixth byte,
+ * g be the seventh byte, and h be the eighth byte. The value
+ * returned is:
+ * (((long)(a & 0xff) << 56) |
+ * ((long)(b & 0xff) << 48) |
+ * ((long)(c & 0xff) << 40) |
+ * ((long)(d & 0xff) << 32) |
+ * ((long)(e & 0xff) << 24) |
+ * ((long)(f & 0xff) << 16) |
+ * ((long)(g & 0xff) << 8) |
+ * ((long)(h & 0xff)))
+ * @returns the 64 bit long long read
+ * @throws IOException
+ * @throws EOFException
+ */
+ virtual long long readLong()
+ throw ( io::IOException, io::EOFException );
+
+ /**
+ * Reads two input bytes and returns a short value. Let a be the
+ * first byte read and b be the second byte. The value returned is:
+ * (short)((a << 8) | (b & 0xff))
+ * @returns the 16 bit short value read
+ * @throws IOException
+ * @throws EOFException
+ */
+ virtual short readShort() throw ( io::IOException, io::EOFException );
+
+ /**
+ * Reads two input bytes and returns an int value in the range 0
+ * through 65535. Let a be the first byte read and b be the
+ * second byte. The value returned is:
+ * (((a & 0xff) << 8) | (b & 0xff))
+ * @returns the 16 bit unsigned short read
+ * @throws IOException
+ * @throws EOFException
+ */
+ virtual unsigned short readUnsignedShort()
+ throw ( io::IOException, io::EOFException );
+
+ /**
+ * Reads an null terminated ASCII string to the stream and returns the
+ * string to the caller.
+ * @returns string object containing the string read.
+ * @throws IOException
+ * @throws EOFException
+ */
+ virtual std::string readString()
+ throw ( io::IOException, io::EOFException );
+
+ /**
+ * Reads a UTF8 encoded string in ASCII format and returns it, this is
+ * only useful if you know for sure that the string that is to be read
+ * was a string that contained all ascii values, and not uncide chars.
+ * @returns string read from stream.
+ * @throws IOException
+ * @throws EOFException
+ */
+ virtual std::string readUTF()
+ throw ( io::IOException, io::EOFException );
+
+ /**
+ * Reads some bytes from an input stream and stores them into the
+ * buffer array buffer. The number of bytes read is equal to the length
+ * of buffer.<p>
+ * This method blocks until one of the following conditions occurs:
+ * * buffer.size() bytes of input data are available, in which case
+ * a normal return is made.
+ * * End of file is detected, in which case an EOFException is
+ * thrown.
+ * * An I/O error occurs, in which case an IOException other than
+ * EOFException is thrown.
+ * <p>
+ * If buffer.size() is zero, then no bytes are read. Otherwise, the
+ * first byte read is stored into element b[0], the next one into
+ * buffer[1], and so on. If an exception is thrown from this method,
+ * then it may be that some but not all bytes of buffer have been
+ * updated with data from the input stream.
+ * @param buffer - vector of char that is read to its size()
+ * @throws IOException
+ * @throws EOFException
+ */
+ virtual void readFully( std::vector< unsigned char >& buffer )
+ throw ( io::IOException, io::EOFException );
+
+ /**
+ * Reads length bytes from an input stream.
+ * <p>
+ * This method blocks until one of the following conditions occurs:
+ * * length bytes of input data are available, in which case a
+ * normal return is made.
+ * * End of file is detected, in which case an EOFException is
+ * thrown.
+ * * An I/O error occurs, in which case an IOException other
+ * than EOFException is thrown.
+ * <p>
+ * If buffer is null, a NullPointerException is thrown. If offset is
+ * negative, or len is negative, or offset+length is greater than the
+ * length of the array buffer, then an IndexOutOfBoundsException is
+ * thrown. If len is zero, then no bytes are read. Otherwise, the
+ * first byte read is stored into element buffer[off], the next one into
+ * buffer[offset+1], and so on. The number of bytes read is, at most,
+ * equal to len.
+ * @param buffer - byte array to insert read data into
+ * @param offset - location in buffer to start writing
+ * @param length - number of bytes to read
+ * @throws IOException
+ * @throws EOFException
+ */
+ virtual void readFully( unsigned char* buffer,
+ std::size_t offset,
+ std::size_t length )
+ throw ( io::IOException,
+ io::EOFException,
+ lang::exceptions::IndexOutOfBoundsException,
+ lang::exceptions::NullPointerException );
+
+ /**
+ * Makes an attempt to skip over n bytes of data from the input
+ * stream, discarding the skipped bytes. However, it may skip over
+ * some smaller number of bytes, possibly zero. This may result from
+ * any of a number of conditions; reaching end of file before n
+ * bytes have been skipped is only one possibility. This method
+ * never throws an EOFException. The actual number of bytes skipped
+ * is returned.
+ * @param num - number of bytes to skip
+ * @return the total number of bytes skipped
+ */
+ virtual std::size_t skip( std::size_t num )
+ throw( io::IOException,
+ lang::exceptions::UnsupportedOperationException );
+
+ };
+
+}}
+
+#endif /*_DECAF_IO_DATAINPUTSTREAM_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/io/DataOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/io/DataOutputStream.cpp?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/io/DataOutputStream.cpp (added)
+++ activemq/activemq-cpp/trunk/src/decaf/io/DataOutputStream.cpp Thu May 31 04:55:59 2007
@@ -0,0 +1,220 @@
+/*
+ * 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/DataOutputStream.h>
+#include <decaf/util/Config.h>
+
+using namespace decaf;
+using namespace decaf::io;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+DataOutputStream::DataOutputStream( OutputStream* outputStream, bool own )
+ : FilterOutputStream( outputStream, own )
+{
+ // Init the written count
+ written = 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+DataOutputStream::~DataOutputStream()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::write( const unsigned char c ) throw ( IOException ) {
+ try {
+ outputStream->write( c );
+ written++;
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::write( const std::vector<unsigned char>& buffer )
+ throw ( IOException ) {
+
+ try {
+
+ if( buffer.size() == 0 ){
+ // nothing to write.
+ return;
+ }
+
+ outputStream->write( &buffer[0], buffer.size() );
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::write( const unsigned char* buffer, std::size_t len )
+ throw ( IOException ) {
+
+ try {
+ outputStream->write( buffer, len );
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::write( const unsigned char* buffer,
+ std::size_t offset,
+ std::size_t len ) throw ( IOException )
+{
+
+ try {
+ outputStream->write( buffer+offset, len );
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::writeBoolean( bool value ) throw ( IOException ) {
+ try {
+ unsigned char ivalue = 0;
+ value == true ? ivalue = 1 : ivalue = 0;
+
+ this->write( ivalue );
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::writeByte( unsigned char value ) throw ( IOException ) {
+ try {
+ this->write( value );
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::writeShort( short value ) throw ( IOException ) {
+ try {
+ this->writeUnsignedShort( (unsigned short)value );
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::writeUnsignedShort( unsigned short value )
+ throw ( IOException )
+{
+ try {
+ write( (unsigned char)( (value & 0xFF00) >> 8 ) );
+ write( (unsigned char)( (value & 0x00FF) >> 0 ) );
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::writeChar( char value ) throw ( IOException ) {
+ try {
+ write( value );
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::writeInt( int value ) throw ( IOException ) {
+ try {
+ this->write( (unsigned char)( (value & 0xFF000000) >> 24 ) );
+ this->write( (unsigned char)( (value & 0x00FF0000) >> 16 ) );
+ this->write( (unsigned char)( (value & 0x0000FF00) >> 8 ) );
+ this->write( (unsigned char)( (value & 0x000000FF) >> 0 ) );
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::writeLong( long long value ) throw ( IOException ) {
+ try {
+ this->write( (unsigned char)( (value & 0xFF00000000000000ULL) >> 56 ) );
+ this->write( (unsigned char)( (value & 0x00FF000000000000ULL) >> 48 ) );
+ this->write( (unsigned char)( (value & 0x0000FF0000000000ULL) >> 40 ) );
+ this->write( (unsigned char)( (value & 0x000000FF00000000ULL) >> 32 ) );
+ this->write( (unsigned char)( (value & 0x00000000FF000000ULL) >> 24 ) );
+ this->write( (unsigned char)( (value & 0x0000000000FF0000ULL) >> 16 ) );
+ this->write( (unsigned char)( (value & 0x000000000000FF00ULL) >> 8 ) );
+ this->write( (unsigned char)( (value & 0x00000000000000FFULL) >> 0 ) );
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::writeFloat( float value ) throw ( IOException ) {
+ try {
+ unsigned int lvalue = 0;
+ memcpy( &lvalue, &value, sizeof( float ) );
+ this->writeInt( lvalue );
+ memcpy( &value, &lvalue, sizeof( unsigned int ) );
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::writeDouble( double value ) throw ( IOException ) {
+ try {
+ unsigned long long lvalue = 0;
+ memcpy( &lvalue, &value, sizeof( double ) );
+ this->writeLong( lvalue );
+ memcpy( &value, &lvalue, sizeof( unsigned long long ) );
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::writeBytes( const std::string& value ) throw ( IOException ) {
+ try {
+ // do not add one so that we don't write the NULL
+ this->write( (const unsigned char*)value.c_str(), value.length() );
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::writeChars( const std::string& value ) throw ( IOException ) {
+ try {
+ // add one so that we write the NULL
+ this->write( (const unsigned char*)value.c_str(), value.length() + 1 );
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::writeUTF( const std::string& value ) throw ( IOException ) {
+ try {
+ this->writeUnsignedShort( (unsigned short)value.length() );
+ this->write( (const unsigned char*)value.c_str(), value.length() );
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+}
Added: activemq/activemq-cpp/trunk/src/decaf/io/DataOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/io/DataOutputStream.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/io/DataOutputStream.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/io/DataOutputStream.h Thu May 31 04:55:59 2007
@@ -0,0 +1,218 @@
+/*
+ * 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_DATAOUTPUTSTREAM_H_
+#define _DECAF_IO_DATAOUTPUTSTREAM_H_
+
+#include <decaf/io/FilterOutputStream.h>
+
+namespace decaf{
+namespace io{
+
+ /**
+ * A data output stream lets an application write primitive Java data
+ * types to an output stream in a portable way. An application can then
+ * use a data input stream to read the data back in.
+ */
+ class DataOutputStream : public FilterOutputStream
+ {
+ protected:
+
+ // The number of bytes written to the data output stream so far.
+ std::size_t written;
+
+ public:
+
+ /**
+ * Creates a new data output stream to write data to the specified
+ * underlying output stream.
+ * @param outputStream a stream to wrap with this one.
+ * @param own true if this objects owns the stream that it wraps.
+ */
+ DataOutputStream( OutputStream* outputStream, bool own = false );
+
+ virtual ~DataOutputStream();
+
+ /**
+ * Returns the current value of the counter written, the number of
+ * bytes written to this data output stream so far. If the counter
+ * overflows, it will be wrapped to Integer.MAX_VALUE.
+ * @return the value of the written field.
+ */
+ virtual std::size_t size() const {
+ return written;
+ }
+
+ /**
+ * Writes a single byte to the output stream. If no exception is
+ * thrown, the counter written is incremented by 1.
+ * @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. the counter
+ * written is incremented by len.
+ * @param buffer The array of bytes to write.
+ * @param len The number of bytes from the buffer to be written.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( const unsigned char* buffer, std::size_t len )
+ throw ( IOException );
+
+ /**
+ * Writes an array of bytes to the output stream. the counter
+ * written is incremented by len.
+ * @param buffer The array of bytes to write.
+ * @param len The number of bytes from the buffer to be written.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( const unsigned char* buffer,
+ std::size_t offset,
+ std::size_t len ) 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 a boolean to the underlying output stream as a 1-byte value. The
+ * value true is written out as the value (byte)1; the value false
+ * is written out as the value (byte)0. If no exception is thrown,
+ * the counter written is incremented by 1.
+ * @param value the boolean to write.
+ * @throws IOException
+ *
+ */
+ virtual void writeBoolean( bool value ) throw ( IOException );
+
+ /**
+ * Writes out a byte to the underlying output stream as a 1-byte
+ * value. If no exception is thrown, the counter written is
+ * incremented by 1.
+ * @param value the unsigned char value to write.
+ * @throws IOException
+ */
+ virtual void writeByte( unsigned char value ) throw ( IOException );
+
+ /**
+ * Writes a short to the underlying output stream as two bytes, high
+ * byte first. If no exception is thrown, the counter written is
+ * incremented by 2.
+ * @param value the value to write.
+ * @throws IOException
+ */
+ virtual void writeShort( short value ) throw ( IOException );
+
+ /**
+ * Writes a unsigned short to the bytes message stream as a 2 byte value
+ * @param value - unsigned short to write to the stream
+ * @throws IOException
+ */
+ virtual void writeUnsignedShort( unsigned short value ) throw ( IOException );
+
+ /**
+ * Writes out a char to the underlying output stream as a one byte
+ * value If no exception is thrown, the counter written is
+ * incremented by 1.
+ * @param value the value to write.
+ * @throws IOException
+ */
+ virtual void writeChar( char value ) throw ( IOException );
+
+ /**
+ * Writes an int to the underlying output stream as four bytes, high
+ * byte first. If no exception is thrown, the counter written is
+ * incremented by 4.
+ * @param value the value to write.
+ * @throws IOException
+ */
+ virtual void writeInt( int value ) throw ( IOException );
+
+ /**
+ * Writes an 64 bit long to the underlying output stream as eight
+ * bytes, high byte first. If no exception is thrown, the counter
+ * written is incremented by 8.
+ * @param value the value to write.
+ * @throws IOException
+ */
+ virtual void writeLong( long long value ) throw ( IOException );
+
+ /**
+ * Converts the float argument to an int using the floatToIntBits
+ * method in class Float, and then writes that int value to the
+ * underlying output stream as a 4-byte quantity, high byte first.
+ * If no exception is thrown, the counter written is incremented
+ * by 4.
+ * @param value the value to write.
+ * @throws IOException
+ */
+ virtual void writeFloat( float value ) throw ( IOException );
+
+ /**
+ * Converts the double argument to a long using the doubleToLongBits
+ * method in class Double, and then writes that long value to the
+ * underlying output stream as an 8-byte quantity, high byte first.
+ * If no exception is thrown, the counter written is incremented
+ * by 8.
+ * @param value the value to write.
+ * @throws IOException
+ */
+ virtual void writeDouble( double value ) throw ( IOException );
+
+ /**
+ * Writes out the string to the underlying output stream as a
+ * sequence of bytes. Each character in the string is written out,
+ * in sequence, by discarding its high eight bits. If no exception
+ * is thrown, the counter written is incremented by the length of
+ * value. The value written does not include a trailing null as that
+ * is not part of the sequence of bytes, if the null is needed, then use
+ * the writeChars method.
+ * @param value the value to write.
+ * @throws IOException
+ */
+ virtual void writeBytes( const std::string& value ) throw ( IOException );
+
+ /**
+ * Writes a string to the underlying output stream as a sequence of
+ * characters. Each character is written to the data output stream
+ * as if by the writeChar method. If no exception is thrown, the
+ * counter written is incremented by the length of value. The trailing
+ * NULL charactor is written by this method.
+ * @param value the value to write.
+ * @throws IOException
+ */
+ virtual void writeChars( const std::string& value ) throw ( IOException );
+
+ /**
+ * Writes out the string to the underlying output stream as a
+ * unsigned short indicating its length followed by the rest of
+ * the string.
+ * @param value the value to write.
+ * @throws IOException
+ */
+ virtual void writeUTF( const std::string& value ) throw ( IOException );
+ };
+
+}}
+
+#endif /*_DECAF_IO_DATAOUTPUTSTREAM_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/io/EOFException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/io/EOFException.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/io/EOFException.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/io/EOFException.h Thu May 31 04:55:59 2007
@@ -0,0 +1,91 @@
+/*
+ * 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_EOFEXCEPTION_H
+#define _DECAF_IO_EOFEXCEPTION_H
+
+#include <decaf/io/IOException.h>
+
+namespace decaf{
+namespace io{
+
+ /*
+ * Signals that an End of File exception has occurred.
+ */
+ class EOFException : public io::IOException
+ {
+ public:
+
+ /**
+ * Default Constructor
+ */
+ EOFException() throw(){}
+
+ /**
+ * Copy Constructor
+ * @param ex the exception to copy
+ */
+ EOFException( const lang::Exception& ex ) throw()
+ : IOException()
+ {
+ *(lang::Exception*)this = ex;
+ }
+
+ /**
+ * Copy Constructor
+ * @param ex the exception to copy, which is an instance of this type
+ */
+ EOFException( const EOFException& ex ) throw()
+ : IOException()
+ {
+ *(lang::Exception*)this = ex;
+ }
+
+ /**
+ * Consturctor
+ * @param file name of the file were the exception occured.
+ * @param lineNumber line where the exception occured
+ * @param msg the message that was generated
+ */
+ EOFException( const char* file, const int lineNumber,
+ const char* msg, ... ) throw()
+ : IOException()
+ {
+ va_list vargs;
+ va_start( vargs, msg );
+ buildMessage( msg, vargs );
+
+ // Set the first mark for this exception.
+ setMark( file, lineNumber );
+ }
+
+ /**
+ * Clones this exception. This is useful for cases where you need
+ * to preserve the type of the original exception as well as the message.
+ * All subclasses should override.
+ */
+ virtual EOFException* clone() const{
+ return new EOFException( *this );
+ }
+
+ virtual ~EOFException() throw(){}
+
+ };
+
+}}
+
+#endif /*_DECAF*/
Added: activemq/activemq-cpp/trunk/src/decaf/io/FilterInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/io/FilterInputStream.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/io/FilterInputStream.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/io/FilterInputStream.h Thu May 31 04:55:59 2007
@@ -0,0 +1,225 @@
+/*
+ * 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_FILTERINPUTSTREAM_H_
+#define _DECAF_IO_FILTERINPUTSTREAM_H_
+
+#include <decaf/io/InputStream.h>
+#include <decaf/io/IOException.h>
+#include <decaf/util/concurrent/Mutex.h>
+
+namespace decaf{
+namespace io{
+
+ /**
+ * A FilterInputStream contains some other input stream, which it uses
+ * as its basic source of data, possibly transforming the data along the
+ * way or providing additional functionality. The class FilterInputStream
+ * itself simply overrides all methods of InputStream with versions
+ * that pass all requests to the contained input stream. Subclasses of
+ * FilterInputStream may further override some of these methods and may
+ * also provide additional methods and fields.
+ */
+ class FilterInputStream : public InputStream
+ {
+ protected:
+
+ // The input stream to wrap
+ InputStream* inputStream;
+
+ // Synchronization object.
+ util::concurrent::Mutex mutex;
+
+ // Indicates if we own the wrapped stream
+ bool own;
+
+ public:
+
+ /**
+ * Constructor to create a wrapped InputStream
+ * @param inputStream the stream to wrap and filter
+ * @param own indicates if we own the stream object, defaults to false
+ */
+ FilterInputStream( InputStream* inputStream, bool own = false ) {
+ this->inputStream = inputStream;
+ this->own = own;
+ }
+
+ virtual ~FilterInputStream() {
+ try {
+ if( own == true ) delete inputStream;
+ }
+ DECAF_CATCH_NOTHROW( IOException )
+ DECAF_CATCHALL_NOTHROW( )
+ }
+
+ /**
+ * Returns the number of bytes that can be read from this input stream
+ * without blocking. This method simply performs in.available() and
+ * returns the result.
+ * @return the number of bytes available without blocking.
+ */
+ virtual std::size_t available() const throw ( IOException ) {
+ try {
+ return inputStream->available();
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+ }
+
+ /**
+ * Reads the next byte of data from this input stream. The value byte
+ * is returned as an unsigned char in the range 0 to 255. If no byte is
+ * available because the end of the stream has been reached, the value
+ * -1 is returned. This method blocks until input data is available,
+ * the end of the stream is detected, or an exception is thrown.
+ * This method simply performs in.read() and returns the result.
+ * @return The next byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual unsigned char read() throw ( IOException ) {
+ try {
+ return inputStream->read();
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+ }
+
+ /**
+ * Reads up to len bytes of data from this input stream into an array
+ * of bytes. This method blocks until some input is available.
+ * This method simply performs in.read(b, len) and returns the result.
+ * @param buffer (out) the target buffer.
+ * @param bufferSize the size of the output buffer.
+ * @return The number of bytes read or -1 if EOS is detected
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual std::size_t read( unsigned char* buffer, std::size_t bufferSize )
+ throw ( IOException )
+ {
+ try {
+ return inputStream->read( buffer, bufferSize );
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+ }
+
+ /**
+ * Close the Stream, the FilterOutputStream simply calls the close
+ * method of the underlying stream
+ * @throws Exception
+ */
+ virtual void close() throw ( lang::Exception ) {
+ try {
+ inputStream->close();
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+ }
+
+ /**
+ * 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 ) {
+ try {
+ return inputStream->skip(num);
+ }
+ DECAF_CATCH_RETHROW( lang::exceptions::UnsupportedOperationException )
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+ }
+
+ public: // Synchronizable
+
+ /**
+ * 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_FILTERINPUTSTREAM_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/io/FilterOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/io/FilterOutputStream.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/io/FilterOutputStream.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/io/FilterOutputStream.h Thu May 31 04:55:59 2007
@@ -0,0 +1,209 @@
+/*
+ * 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_FILTEROUTPUTSTREAM_H_
+#define _DECAF_IO_FILTEROUTPUTSTREAM_H_
+
+#include <decaf/io/OutputStream.h>
+#include <decaf/io/IOException.h>
+#include <decaf/util/concurrent/Mutex.h>
+
+namespace decaf{
+namespace io{
+
+ /**
+ * This class is the superclass of all classes that filter output
+ * streams. These streams sit on top of an already existing output
+ * stream (the underlying output stream) which it uses as its basic
+ * sink of data, but possibly transforming the data along the way or
+ * providing additional functionality.
+ *
+ * The class FilterOutputStream itself simply overrides all methods of
+ * OutputStream with versions that pass all requests to the underlying
+ * output stream. Subclasses of FilterOutputStream may further override
+ * some of these methods as well as provide additional methods and
+ * fields.
+ *
+ * Due to the lack of garbage collection in C++ a design decision was
+ * made to add a boolean parameter to the constructor indicating if the
+ * wrapped <code>InputStream</code> is owned by this object. That way
+ * creation of the underlying stream can occur in a Java like way. Ex:
+ *
+ * DataOutputStream os = new DataOutputStream( new OutputStream(), true )
+ */
+ class FilterOutputStream : public OutputStream
+ {
+ protected:
+
+ // The output Stream to wrap
+ OutputStream* outputStream;
+
+ // Synchronization object.
+ util::concurrent::Mutex mutex;
+
+ // Indicates if we own the wrapped stream
+ bool own;
+
+ public:
+
+ /**
+ * Constructor, creates a wrapped output stream
+ * @param outputStream the OutputStream to wrap
+ * @param own If true, this object will control the lifetime of the
+ * output stream that it encapsulates.
+ */
+ FilterOutputStream( OutputStream* outputStream, bool own = false ){
+ this->outputStream = outputStream;
+ this->own = own;
+ }
+
+ virtual ~FilterOutputStream() {
+ try {
+ if( own == true ) delete outputStream;
+ }
+ DECAF_CATCH_NOTHROW( IOException )
+ DECAF_CATCHALL_NOTHROW( )
+ }
+
+ /**
+ * Writes a single byte to the output stream. The write method of
+ * FilterOutputStream calls the write method of its underlying output
+ * stream, that is, it performs out.write(b).
+ * @param c the byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( unsigned char c ) throw ( IOException ) {
+ try {
+ outputStream->write( c );
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+ }
+
+ /**
+ * Writes an array of bytes to the output stream. The write method of
+ * FilterOutputStream calls the write method of one argument on each
+ * byte to output.
+ * @param buffer The array of bytes to write.
+ * @param len The number of bytes from the buffer to be written.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( const unsigned char* buffer, std::size_t len ) throw ( IOException ) {
+ try {
+ for( std::size_t ix = 0; ix < len; ++ix )
+ {
+ outputStream->write( buffer[ix] );
+ }
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+ }
+
+ /**
+ * Flushes any pending writes in this output stream.
+ * The flush method of FilterOutputStream calls the flush method
+ * of its underlying output stream
+ * @throws IOException
+ */
+ virtual void flush() throw ( IOException ) {
+ try {
+ outputStream->flush();
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+ }
+
+ /**
+ * Close the Stream, the FilterOutputStream simply calls the close
+ * method of the underlying stream
+ * @throws CMSException
+ */
+ virtual void close() throw ( lang::Exception ) {
+ try {
+ outputStream->close();
+ }
+ DECAF_CATCH_RETHROW( IOException )
+ DECAF_CATCHALL_THROW( IOException )
+ }
+
+ public: // Synchronizable
+
+ /**
+ * 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_FILTEROUTPUTSTREAM_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/io/IOException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/io/IOException.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/io/IOException.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/io/IOException.h Thu May 31 04:55:59 2007
@@ -0,0 +1,90 @@
+/*
+ * 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_IOEXCEPTION_H
+#define _DECAF_IO_IOEXCEPTION_H
+
+#include <decaf/lang/Exception.h>
+
+namespace decaf{
+namespace io{
+
+ /*
+ * Signals that an I/O exception of some sort has occurred.
+ */
+ class IOException : public lang::Exception
+ {
+ public:
+
+ /**
+ * Default Constructor
+ */
+ IOException() throw() {}
+
+ /**
+ * Copy Constructor
+ * @param ex the exception to copy
+ */
+ IOException( const lang::Exception& ex ) throw()
+ : lang::Exception()
+ {
+ *(lang::Exception*)this = ex;
+ }
+
+ /**
+ * Copy Constructor
+ * @param ex the exception to copy, which is an instance of this type
+ */
+ IOException( const IOException& ex ) throw()
+ : lang::Exception()
+ {
+ *(lang::Exception*)this = ex;
+ }
+
+ /**
+ * Consturctor
+ * @param file name of the file were the exception occured.
+ * @param lineNumber line where the exception occured
+ * @param msg the message that was generated
+ */
+ IOException( const char* file, const int lineNumber,
+ const char* msg, ... ) throw()
+ : lang::Exception()
+ {
+ va_list vargs;
+ va_start( vargs, msg );
+ buildMessage( msg, vargs );
+
+ // Set the first mark for this exception.
+ setMark( file, lineNumber );
+ }
+
+ /**
+ * Clones this exception. This is useful for cases where you need
+ * to preserve the type of the original exception as well as the message.
+ * All subclasses should override.
+ */
+ virtual IOException* clone() const{
+ return new IOException( *this );
+ }
+
+ virtual ~IOException() throw() {}
+
+ };
+
+}}
+
+#endif /*_DECAF_IO_IOEXCEPTION_H*/
Added: activemq/activemq-cpp/trunk/src/decaf/io/InputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/io/InputStream.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/io/InputStream.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/io/InputStream.h Thu May 31 04:55:59 2007
@@ -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.
+ */
+
+#ifndef _DECAF_IO_INPUTSTREAM_H_
+#define _DECAF_IO_INPUTSTREAM_H_
+
+#include <decaf/io/IOException.h>
+#include <decaf/io/Closeable.h>
+#include <decaf/util/concurrent/Synchronizable.h>
+#include <decaf/lang/exceptions/UnsupportedOperationException.h>
+
+namespace decaf{
+namespace io{
+
+ /**
+ * Base interface for an input stream.
+ */
+ class InputStream : public Closeable,
+ public util::concurrent::Synchronizable
+ {
+ public:
+
+ virtual ~InputStream(){}
+
+ /**
+ * Indcates the number of bytes avaialable.
+ * @return the number of bytes available on this input stream.
+ * @throws IOException if an error occurs.
+ */
+ virtual std::size_t available() const throw ( IOException ) = 0;
+
+ /**
+ * Reads a single byte from the buffer. Blocks until
+ * data is available.
+ * @return The next byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual unsigned char read() throw ( IOException ) = 0;
+
+ /**
+ * Reads an array of bytes from the buffer. Blocks until
+ * the requested number of bytes are available.
+ * @param buffer (out) the target buffer.
+ * @param bufferSize the size of the output buffer.
+ * @return The number of bytes read or -1 if EOF is detected
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual std::size_t read( unsigned char* buffer, std::size_t bufferSize )
+ throw ( IOException ) = 0;
+
+ /**
+ * 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 ) = 0;
+
+ };
+
+}}
+
+#endif /*_DECAF_IO_INPUTSTREAM_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/io/OutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/io/OutputStream.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/io/OutputStream.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/io/OutputStream.h Thu May 31 04:55:59 2007
@@ -0,0 +1,63 @@
+/*
+ * 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_OUTPUTSTREAM_H
+#define _DECAF_IO_OUTPUTSTREAM_H
+
+#include <decaf/io/Closeable.h>
+#include <decaf/io/IOException.h>
+#include <decaf/util/concurrent/Synchronizable.h>
+
+namespace decaf{
+namespace io{
+
+ /**
+ * Base interface for an output stream.
+ */
+ class OutputStream : public Closeable,
+ public util::concurrent::Synchronizable
+ {
+ public:
+
+ virtual ~OutputStream(){}
+
+ /**
+ * 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 ) = 0;
+
+ /**
+ * Writes an array of bytes to the output stream.
+ * @param buffer The array of bytes to write.
+ * @param len The number of bytes from the buffer to be written.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( const unsigned char* buffer, std::size_t len )
+ throw ( IOException ) = 0;
+
+ /**
+ * Flushes any pending writes in this output stream.
+ * @throws IOException
+ */
+ virtual void flush() throw ( IOException ) = 0;
+ };
+
+}}
+
+#endif /*_DECAF_IO_OUTPUTSTREAM_H*/
Added: activemq/activemq-cpp/trunk/src/decaf/io/Reader.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/io/Reader.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/io/Reader.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/io/Reader.h Thu May 31 04:55:59 2007
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_IO_READER_H
+#define _DECAF_IO_READER_H
+
+#include <string>
+#include <decaf/io/IOException.h>
+#include <decaf/io/InputStream.h>
+
+namespace decaf{
+namespace io{
+
+ /*
+ * Reader interface that wraps around an input stream and provides
+ * an interface for extracting the data from the input stream.
+ */
+ class Reader
+ {
+ public:
+
+ virtual ~Reader(){};
+
+ /**
+ * Sets the target input stream.
+ */
+ virtual void setInputStream( InputStream* is ) = 0;
+
+ /**
+ * Gets the target input stream.
+ */
+ virtual InputStream* getInputStream() = 0;
+
+ /**
+ * Attempts to read an array of bytes from the stream.
+ * @param buffer The target byte buffer.
+ * @param count The number of bytes to read.
+ * @return The number of bytes read.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual std::size_t read( unsigned char* buffer, std::size_t count )
+ throw( IOException ) = 0;
+
+ /**
+ * Attempts to read a byte from the input stream
+ * @return The byte.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual unsigned char readByte() throw( IOException ) = 0;
+
+ };
+
+}}
+
+#endif /*_DECAF_IO_READER_H*/
Added: activemq/activemq-cpp/trunk/src/decaf/io/StandardErrorOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/io/StandardErrorOutputStream.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/io/StandardErrorOutputStream.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/io/StandardErrorOutputStream.h Thu May 31 04:55:59 2007
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_IO_STANDARDERROROUTPUTSTREAM_H_
+#define _DECAF_IO_STANDARDERROROUTPUTSTREAM_H_
+
+#include <decaf/io/OutputStream.h>
+#include <decaf/util/concurrent/Mutex.h>
+
+#include <iostream>
+
+namespace decaf{
+namespace io{
+
+ class StandardErrorOutputStream : public OutputStream
+ {
+ private:
+
+ /**
+ * Synchronization object.
+ */
+ util::concurrent::Mutex mutex;
+
+ public:
+
+ /**
+ * Default Constructor
+ */
+ StandardErrorOutputStream(void) {}
+
+ virtual ~StandardErrorOutputStream(void) {}
+
+ /**
+ * 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( 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();
+ }
+
+ /**
+ * 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 )
+ {
+ std::cerr << c;
+ }
+
+ /**
+ * Writes an array of bytes to the output stream.
+ * @param buffer The array of bytes to write.
+ * @param len The number of bytes from the buffer to be written.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( const unsigned char* buffer, int len )
+ throw ( IOException )
+ {
+ for(int i = 0; i < len; ++i)
+ {
+ std::cerr << buffer[i];
+ }
+ }
+
+ /**
+ * Invokes flush on the target output stream.
+ * throws IOException if an error occurs
+ */
+ virtual void flush() throw ( IOException ){
+ std::cerr.flush();
+ }
+
+ /**
+ * Invokes close on the target output stream.
+ * throws CMSException if an error occurs
+ */
+ void close() throw( lang::Exception ){
+ std::cerr.flush();
+ }
+
+ };
+
+}
+
+#endif /*_DECAF_IO_STANDARDERROROUTPUTSTREAM_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/io/Writer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/io/Writer.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/io/Writer.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/io/Writer.h Thu May 31 04:55:59 2007
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_IO_WRITER_H
+#define _DECAF_IO_WRITER_H
+
+#include <string>
+#include <decaf/io/IOException.h>
+#include <decaf/io/OutputStream.h>
+
+namespace decaf{
+namespace io{
+
+ /*
+ * Writer interface for an object that wraps around an output
+ * stream
+ */
+ class Writer
+ {
+ public:
+
+ virtual ~Writer(){};
+
+ /**
+ * Sets the target output stream.
+ * @param Outputstream to use
+ */
+ virtual void setOutputStream( OutputStream* os ) = 0;
+
+ /**
+ * Gets the target output stream.
+ * @returns the output stream currently being used
+ */
+ virtual OutputStream* getOutputStream() = 0;
+
+ /**
+ * Writes a byte array to the output stream.
+ * @param buffer a byte array
+ * @param count the number of bytes in the array to write.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void write( const unsigned char* buffer,
+ std::size_t count ) throw( IOException ) = 0;
+
+ /**
+ * Writes a byte to the output stream.
+ * @param v The value to be written.
+ * @throws IOException thrown if an error occurs.
+ */
+ virtual void writeByte( unsigned char v ) throw( IOException ) = 0;
+ };
+
+}}
+
+#endif /*_DECAF_IO_WRITER_H*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/Boolean.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/Boolean.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/Boolean.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/Boolean.h Thu May 31 04:55:59 2007
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_LANG_BOOLEAN_H_
+#define _DECAF_LANG_BOOLEAN_H_
+
+#include <decaf/lang/Number.h>
+
+namespace decaf{
+namespace lang{
+
+ class Boolean : public Number
+ {
+ public:
+
+ Boolean() {}
+ virtual ~Boolean() {}
+
+ /**
+ * Parses the String passed and extracts an bool.
+ * @param String to parse
+ * @return bool value
+ */
+ static bool parseBoolean( const std::string& value ){
+ bool ret = 0;
+ std::istringstream istream(value);
+ istream.clear();
+ istream >> std::boolalpha >> ret;
+ return ret;
+ }
+
+ /**
+ * Converts the bool to a String representation
+ * @param bool to convert
+ * @return string representation
+ */
+ static std::string toString( bool value ){
+ std::ostringstream ostream;
+ ostream << std::boolalpha << value;
+ return ostream.str();
+ }
+
+ };
+
+}}
+
+#endif /*_DECAF_LANG_BOOLEAN_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/Character.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/Character.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/Character.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/Character.h Thu May 31 04:55:59 2007
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_LANG_CHARACTER_H_
+#define _DECAF_LANG_CHARACTER_H_
+
+namespace decaf{
+namespace lang{
+
+ class Character{
+
+ public:
+
+ /**
+ * Indicates whether or not the given character is considered
+ * whitespace.
+ */
+ static bool isWhitespace( char c ){
+ switch ( c )
+ {
+ case '\n':
+ case '\t':
+ case '\r':
+ case '\f':
+ case ' ':
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Indicates whether or not the given character is
+ * a digit.
+ */
+ static bool isDigit( char c ){
+ return c >= '0' && c <= '9';
+ }
+
+ /**
+ * Indicates whether or not the given character is
+ * a lower case character.
+ */
+ static bool isLowerCase( char c ){
+ return c >= 'a' && c <= 'z';
+ }
+
+ /**
+ * Indicates whether or not the given character is
+ * a upper case character.
+ */
+ static bool isUpperCase( char c ){
+ return c >= 'A' && c <= 'Z';
+ }
+
+ /**
+ * Indicates whether or not the given character is
+ * a letter.
+ */
+ static bool isLetter( char c ){
+ return isUpperCase(c) || isLowerCase(c);
+ }
+
+ /**
+ * Indicates whether or not the given character is
+ * either a letter or a digit.
+ */
+ static bool isLetterOrDigit( char c ){
+ return isLetter(c) || isDigit(c);
+ }
+ };
+
+}}
+
+#endif /*_DECAF_LANG_CHARACTER_H_*/
Added: activemq/activemq-cpp/trunk/src/decaf/lang/Exception.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/lang/Exception.cpp?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/lang/Exception.cpp (added)
+++ activemq/activemq-cpp/trunk/src/decaf/lang/Exception.cpp Thu May 31 04:55:59 2007
@@ -0,0 +1,155 @@
+/*
+ * 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 <stdio.h>
+#include "Exception.h"
+#include <decaf/util/logging/LoggerDefines.h>
+#include <sstream>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::util::logging;
+
+// For supporting older versions of msvc (<=2003)
+#if defined(_MSC_VER) && (_MSC_VER < 1400)
+ #define vsnprintf _vsnprintf
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+Exception::Exception() throw(){
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Exception::Exception( const Exception& ex ) throw() : Throwable() {
+ *this = ex;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Exception::Exception( const char* file, const int lineNumber,
+ const char* msg, ... ) throw() {
+ va_list vargs;
+ va_start( vargs, msg ) ;
+ buildMessage( msg, vargs );
+
+ // Set the first mark for this exception.
+ setMark( file, lineNumber );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Exception::~Exception() throw(){
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Exception::setMessage( const char* msg, ... ){
+ va_list vargs;
+ va_start(vargs, msg);
+ buildMessage(msg, vargs);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Exception::buildMessage(const char* format, va_list& vargs) {
+
+ // Allocate buffer with a guess of it's size
+ int size = 128;
+
+ // Format string
+ while( true ){
+
+ // Allocate a buffer of the specified size.
+ char* buffer = new char[size];
+
+ int written = vsnprintf(buffer, size, format, vargs);
+ if (written > -1 && written < size-1) {
+
+ // Guessed size was enough. Assign the string.
+ message.assign (buffer, written);
+
+ // assign isn't passing ownership, just copying, delete
+ // the allocated buffer.
+ delete [] buffer;
+
+ break;
+ }
+
+ // Our buffer wasn't big enough - destroy the old buffer,
+ // double the size and try again.
+ delete [] buffer;
+ size *= 2;
+ }
+
+ //activemq::logger::SimpleLogger logger("com.yadda1");
+ //logger.log( message );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Exception::setMark( const char* file, const int lineNumber ) {
+
+ // Add this mark to the end of the stack trace.
+ stackTrace.push_back( std::make_pair( (std::string)file, (int)lineNumber ) );
+
+ std::ostringstream stream;
+ stream << "\tFILE: " << stackTrace[stackTrace.size()-1].first;
+ stream << ", LINE: " << stackTrace[stackTrace.size()-1].second;
+
+ //activemq::logger::SimpleLogger logger("com.yadda2");
+ //logger.log( stream.str() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Exception* Exception::clone() const {
+ return new Exception( *this );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::vector< std::pair< std::string, int> > Exception::getStackTrace() const {
+ return stackTrace;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Exception::printStackTrace() const {
+ printStackTrace( std::cerr );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Exception::printStackTrace( std::ostream& stream ) const {
+ stream << getStackTraceString();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Exception::getStackTraceString() const {
+
+ // Create the output stream.
+ std::ostringstream stream;
+
+ // Write the message and each stack entry.
+ stream << message << std::endl;
+ for( unsigned int ix=0; ix<stackTrace.size(); ++ix ){
+ stream << "\tFILE: " << stackTrace[ix].first;
+ stream << ", LINE: " << stackTrace[ix].second;
+ stream << std::endl;
+ }
+
+ // Return the string from the output stream.
+ return stream.str();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Exception& Exception::operator =( const Exception& ex ){
+ this->message = ex.message;
+ this->stackTrace = ex.stackTrace;
+ return *this;
+}