activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r551529 - in /activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/io: DataInputStream.cpp DataInputStream.h
Date Thu, 28 Jun 2007 11:06:24 GMT
Author: tabish
Date: Thu Jun 28 04:06:23 2007
New Revision: 551529

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

Building up the Decaf Library, optimizing DataInputStream

Modified:
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/io/DataInputStream.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/io/DataInputStream.h

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/io/DataInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/io/DataInputStream.cpp?view=diff&rev=551529&r1=551528&r2=551529
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/io/DataInputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/io/DataInputStream.cpp Thu Jun 28
04:06:23 2007
@@ -86,16 +86,8 @@
     try {
         unsigned char value = 0;
 
-        std::size_t n = 0;
-        do{
-            std::size_t count = inputStream->read( &value, sizeof(value) );
-            if( count == (std::size_t)-1 ) {
-                throw EOFException(
-                    __FILE__, __LINE__,
-                    "DataInputStream::readBoolean - Reached EOF" );
-            }
-            n += count;
-        } while( n < sizeof( value ) );
+        // Get the data in one shot, will throw EOF or IO Exception as needed.
+        readAllData( &value, sizeof(value) );
 
         return (bool)( value != 0 );
     }
@@ -111,16 +103,8 @@
     try {
         unsigned char value = 0;
 
-        std::size_t n = 0;
-        do{
-            std::size_t count = inputStream->read( &value, sizeof(value) );
-            if( count == (std::size_t)-1 ) {
-                throw EOFException(
-                    __FILE__, __LINE__,
-                    "DataInputStream::readByte - Reached EOF" );
-            }
-            n += count;
-        } while( n < sizeof( value ) );
+        // Get the data in one shot, will throw EOF or IO Exception as needed.
+        readAllData( &value, sizeof(value) );
 
         return (char)( value );
     }
@@ -136,16 +120,8 @@
     try {
         unsigned char value = 0;
 
-        std::size_t n = 0;
-        do{
-            std::size_t count = inputStream->read( &value, sizeof(value) );
-            if( count == (std::size_t)-1 ) {
-                throw EOFException(
-                    __FILE__, __LINE__,
-                    "DataInputStream::readUnsignedByte - Reached EOF" );
-            }
-            n += count;
-        } while( n < sizeof( value ) );
+        // Get the data in one shot, will throw EOF or IO Exception as needed.
+        readAllData( &value, sizeof(value) );
 
         return value;
     }
@@ -159,16 +135,8 @@
     try {
         unsigned char value = 0;
 
-        std::size_t n = 0;
-        do{
-            std::size_t count = inputStream->read( &value, sizeof(value) );
-            if( count == (std::size_t)-1 ) {
-                throw EOFException(
-                    __FILE__, __LINE__,
-                    "DataInputStream::readChar - Reached EOF" );
-            }
-            n += count;
-        } while( n < sizeof( value ) );
+        // Get the data in one shot, will throw EOF or IO Exception as needed.
+        readAllData( &value, sizeof(value) );
 
         return (char)( value );
     }
@@ -183,16 +151,8 @@
         short value = 0;
         unsigned char buffer[sizeof(value)] = {0};
 
-        std::size_t n = 0;
-        do{
-            std::size_t count = inputStream->read( &buffer[n], sizeof(value) - n );
-            if( count == (std::size_t)-1 ) {
-                throw EOFException(
-                    __FILE__, __LINE__,
-                    "DataInputStream::readShort - Reached EOF" );
-            }
-            n += count;
-        } while( n < sizeof( value ) );
+        // Get the data in one shot, will throw EOF or IO Exception as needed.
+        readAllData( buffer, sizeof(value) );
 
         value |= (buffer[0] << 8 | buffer[1] << 0);
 
@@ -211,16 +171,8 @@
         unsigned short value = 0;
         unsigned char buffer[sizeof(value)] = {0};
 
-        std::size_t n = 0;
-        do{
-            std::size_t count = inputStream->read( &buffer[n], sizeof(value) - n );
-            if( count == (std::size_t)-1 ) {
-                throw EOFException(
-                    __FILE__, __LINE__,
-                    "DataInputStream::readUnsignedShort - Reached EOF" );
-            }
-            n += count;
-        } while( n < sizeof( value ) );
+        // Get the data in one shot, will throw EOF or IO Exception as needed.
+        readAllData( buffer, sizeof(value) );
 
         value |= (buffer[0] << 8 | buffer[1] << 0);
 
@@ -238,16 +190,8 @@
         unsigned int value = 0;
         unsigned char buffer[sizeof(value)] = {0};
 
-        std::size_t n = 0;
-        do{
-            std::size_t count = inputStream->read( &buffer[n], sizeof(value) - n );
-            if( count == (std::size_t)-1 ) {
-                throw EOFException(
-                    __FILE__, __LINE__,
-                    "DataInputStream::readInt - Reached EOF" );
-            }
-            n += count;
-        } while( n < sizeof( value ) );
+        // Get the data in one shot, will throw EOF or IO Exception as needed.
+        readAllData( buffer, sizeof(value) );
 
         value |= (buffer[0] << 24 | buffer[1] << 16 |
                   buffer[2] << 8 | buffer[3] << 0);
@@ -295,16 +239,8 @@
         unsigned long long value = 0;
         unsigned char buffer[sizeof(value)] = {0};
 
-        std::size_t n = 0;
-        do{
-            std::size_t count = inputStream->read( &buffer[n], sizeof(value) - n );
-            if( count == (std::size_t)-1 ) {
-                throw EOFException(
-                    __FILE__, __LINE__,
-                    "DataInputStream::readLong - Reached EOF" );
-            }
-            n += count;
-        } while( n < sizeof( value ) );
+        // Get the data in one shot, will throw EOF or IO Exception as needed.
+        readAllData( buffer, sizeof(value) );
 
         // Have to do it this way because on Solaris and Cygwin we get all
         // kinds of warnings when shifting a byte up into a long long.

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/io/DataInputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/io/DataInputStream.h?view=diff&rev=551529&r1=551528&r2=551529
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/io/DataInputStream.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/io/DataInputStream.h Thu Jun 28 04:06:23
2007
@@ -351,12 +351,21 @@
 
         // Used internally to reliable get data from the underlying stream
         inline void readAllData( unsigned char* buffer,
-                          std::size_t offset,
-                          std::size_t length )
+                                 std::size_t length )
             throw ( io::IOException,
-                    io::EOFException,
-                    lang::exceptions::IndexOutOfBoundsException,
-                    lang::exceptions::NullPointerException );
+                    io::EOFException ) {
+
+            std::size_t n = 0;
+            do{
+                std::size_t count = inputStream->read( &buffer[n], length - n );
+                if( count == (std::size_t)-1 ) {
+                    throw EOFException(
+                        __FILE__, __LINE__,
+                        "DataInputStream::readLong - Reached EOF" );
+                }
+                n += count;
+            } while( n < length );
+        }
 
     };
 



Mime
View raw message