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 2006/12/28 20:36:58 UTC

svn commit: r490775 - in /incubator/activemq/activemq-cpp/trunk/activemq-cpp/src: main/activemq/connector/openwire/commands/ main/activemq/connector/stomp/commands/ main/activemq/io/ main/cms/ test/activemq/io/

Author: tabish
Date: Thu Dec 28 11:36:57 2006
New Revision: 490775

URL: http://svn.apache.org/viewvc?view=rev&rev=490775
Log:
http://issues.apache.org/activemq/browse/AMQCPP-37

Modified:
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/commands/ActiveMQBytesMessage.h
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/BytesMessageCommand.h
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.cpp
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.h
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.cpp
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.h
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/BytesMessage.h
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/DataInputStreamTest.h

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/commands/ActiveMQBytesMessage.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/commands/ActiveMQBytesMessage.h?view=diff&rev=490775&r1=490774&r2=490775
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/commands/ActiveMQBytesMessage.h (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/commands/ActiveMQBytesMessage.h Thu Dec 28 11:36:57 2006
@@ -654,6 +654,20 @@
          */
         virtual void writeString( const std::string& value ) throw ( cms::CMSException );
 
+        /**
+         * Reads an UTF String from the BytesMessage stream
+         * @returns String from stream
+         * @throws CMSException
+         */
+        virtual std::string readUTF() throw ( cms::CMSException );
+
+        /**
+         * Writes an UTF String to the BytesMessage stream
+         * @param value - String to write to the stream
+         * @throws CMSException
+         */
+        virtual void writeUTF( const std::string& value ) throw ( cms::CMSException );
+
     public:  // ActiveMQMessage
 
         /**

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/BytesMessageCommand.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/BytesMessageCommand.h?view=diff&rev=490775&r1=490774&r2=490775
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/BytesMessageCommand.h (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/BytesMessageCommand.h Thu Dec 28 11:36:57 2006
@@ -457,6 +457,26 @@
             checkWriteOnly();
             dataOutputStream.writeBytes( value );
         }
+
+        /**
+         * Reads an UTF String from the BytesMessage stream
+         * @returns String from stream
+         * @throws CMSException
+         */
+        virtual std::string readUTF() throw ( cms::CMSException ){
+            checkReadOnly();
+            return dataInputStream.readUTF();
+        }
+        
+        /**
+         * Writes an UTF String to the BytesMessage stream
+         * @param value The string to be written to the stream.
+         * @throws CMSException
+         */
+        virtual void writeUTF( const std::string& value ) throw ( cms::CMSException ){
+            checkWriteOnly();
+            dataOutputStream.writeUTF( value );
+        }
         
     protected:
     

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.cpp?view=diff&rev=490775&r1=490774&r2=490775
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.cpp (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.cpp Thu Dec 28 11:36:57 2006
@@ -237,7 +237,11 @@
 std::string DataInputStream::readUTF() 
     throw ( io::IOException, io::EOFException ) {
     try {
-        return "";
+        std::string buffer;
+        unsigned short len = readUnsignedShort();
+        buffer.resize(len);
+        readFully( (unsigned char*)buffer.c_str(), 0, len );
+        return buffer;
     }
     AMQ_CATCH_RETHROW( IOException )
     AMQ_CATCHALL_THROW( IOException )    

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.h?view=diff&rev=490775&r1=490774&r2=490775
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.h (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataInputStream.h Thu Dec 28 11:36:57 2006
@@ -252,7 +252,9 @@
             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
          */
@@ -260,7 +262,10 @@
             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
          */

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.cpp?view=diff&rev=490775&r1=490774&r2=490775
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.cpp (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.cpp Thu Dec 28 11:36:57 2006
@@ -180,3 +180,13 @@
     AMQ_CATCH_RETHROW( IOException )
     AMQ_CATCHALL_THROW( IOException )
 }
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStream::writeUTF( const std::string& value ) throw ( IOException ) {
+    try {
+        this->writeUnsignedShort( value.length() );
+        this->write( (const unsigned char*)value.c_str(), value.length() );
+    }
+    AMQ_CATCH_RETHROW( IOException )
+    AMQ_CATCHALL_THROW( IOException )
+}

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.h?view=diff&rev=490775&r1=490774&r2=490775
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.h (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/io/DataOutputStream.h Thu Dec 28 11:36:57 2006
@@ -199,6 +199,14 @@
          */
         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 ( io::IOException );
     };
 
 }}

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/BytesMessage.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/BytesMessage.h?view=diff&rev=490775&r1=490774&r2=490775
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/BytesMessage.h (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/BytesMessage.h Thu Dec 28 11:36:57 2006
@@ -273,6 +273,20 @@
          */
         virtual void writeString( const std::string& value ) throw ( cms::CMSException ) = 0;
 
+        /**
+         * Reads an UTF String from the BytesMessage stream
+         * @returns String from stream
+         * @throws CMSException
+         */
+        virtual std::string readUTF() throw ( cms::CMSException ) = 0;
+
+        /**
+         * Writes an UTF String to the BytesMessage stream
+         * @param value - String to write to the stream
+         * @throws CMSException
+         */
+        virtual void writeUTF( const std::string& value ) throw ( cms::CMSException ) = 0;
+
         virtual BytesMessage* clone() const = 0;
    };
 }

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/DataInputStreamTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/DataInputStreamTest.h?view=diff&rev=490775&r1=490774&r2=490775
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/DataInputStreamTest.h (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/DataInputStreamTest.h Thu Dec 28 11:36:57 2006
@@ -60,6 +60,8 @@
 			unsigned char arrayVal[3] = {
 				'a', 'b', 'c'
 			};
+            std::string stringVal1 = "ASCII_String";
+            std::string stringVal2 = "UTF8_String";
 			
 			int size = sizeof(char);
 			memcpy( (char*)(buffer+ix), (char*)&byteVal, size );
@@ -93,6 +95,16 @@
 			size = 3;
 			memcpy( (char*)(buffer+ix), (char*)&arrayVal, size );
 			ix += size;
+            
+            memcpy( (char*)(buffer+ix), stringVal1.c_str(), stringVal1.size() + 1 );
+            ix += stringVal1.size() + 1;
+
+            size = sizeof(uint16_t);
+            uint16_t tempShort2 = util::Endian::byteSwap((unsigned short)stringVal2.size());
+            memcpy( (char*)(buffer+ix), (char*)&tempShort2, size );
+            ix += size;
+            memcpy( (char*)(buffer+ix), stringVal2.c_str(), stringVal2.size() );
+            ix += stringVal2.size();
 
 			// Create the stream with the buffer we just wrote to.
 			ByteArrayInputStream myStream( buffer, 1000 );
@@ -120,6 +132,13 @@
 			CPPUNIT_ASSERT( arrayVal[0] == 'a' );
 			CPPUNIT_ASSERT( arrayVal[1] == 'b' );
 			CPPUNIT_ASSERT( arrayVal[2] == 'c' );
+            
+            std::string resultStrVal1 = reader.readString();
+            CPPUNIT_ASSERT( resultStrVal1 == stringVal1 );
+
+            std::string resultStrVal2 = reader.readUTF();
+            CPPUNIT_ASSERT( resultStrVal2 == stringVal2 );
+
 		}
 
 	};