You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by js...@apache.org on 2006/05/05 09:31:37 UTC

svn commit: r399999 - in /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp: CommandParser.java HeaderParser.java

Author: jstrachan
Date: Fri May  5 00:31:35 2006
New Revision: 399999

URL: http://svn.apache.org/viewcvs?rev=399999&view=rev
Log:
improved null handling after suggestions from Danielius Jurna

Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/CommandParser.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/HeaderParser.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/CommandParser.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/CommandParser.java?rev=399999&r1=399998&r2=399999&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/CommandParser.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/CommandParser.java Fri May  5 00:31:35 2006
@@ -34,15 +34,20 @@
     }
 
     Command parse(DataInput in) throws IOException, JMSException {
-        String line;
-
+        String line = null;
+        
         // skip white space to next real line
-        try {
-            while ((line = in.readLine()).trim().length() == 0) {
+        while (true) {
+            line = in.readLine();
+            if (line == null) {
+                throw new IOException("connection was closed");
+            }
+            else {
+                line = line.trim();
+                if (line.length() > 0) {
+                    break;
+                }
             }
-        }
-        catch (NullPointerException e) {
-            throw new IOException("connection was closed");
         }
 
         // figure correct command and return it

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/HeaderParser.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/HeaderParser.java?rev=399999&r1=399998&r2=399999&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/HeaderParser.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/HeaderParser.java Fri May  5 00:31:35 2006
@@ -32,28 +32,38 @@
      */
     Properties parse(BufferedReader in) throws IOException {
         Properties props = new Properties();
-        String line;
-        while (((line = in.readLine()).trim().length() > 0)) {
-            int seperator_index = line.indexOf(Stomp.Headers.SEPERATOR);
-            String name = line.substring(0, seperator_index).trim();
-            String value = line.substring(seperator_index + 1, line.length()).trim();
-            props.setProperty(name, value);
+        while (true) {
+            String line = in.readLine();
+            if (line != null && line.trim().length() > 0) {
+                int seperator_index = line.indexOf(Stomp.Headers.SEPERATOR);
+                String name = line.substring(0, seperator_index).trim();
+                String value = line.substring(seperator_index + 1, line.length()).trim();
+                props.setProperty(name, value);
+            }
+            else {
+                break;
+            }
         }
         return props;
     }
 
     Properties parse(DataInput in) throws IOException {
         Properties props = new Properties();
-        String line;
-        while (((line = in.readLine()).trim().length() > 0)) {
-            try {
-                int seperator_index = line.indexOf(Stomp.Headers.SEPERATOR);
-                String name = line.substring(0, seperator_index).trim();
-                String value = line.substring(seperator_index + 1, line.length()).trim();
-                props.setProperty(name, value);
+        while (true) {
+            String line = in.readLine();
+            if (line != null && line.trim().length() > 0) {
+                try {
+                    int seperator_index = line.indexOf(Stomp.Headers.SEPERATOR);
+                    String name = line.substring(0, seperator_index).trim();
+                    String value = line.substring(seperator_index + 1, line.length()).trim();
+                    props.setProperty(name, value);
+                }
+                catch (Exception e) {
+                    throw new ProtocolException("Unable to parser header line [" + line + "]");
+                }
             }
-            catch (Exception e) {
-                throw new ProtocolException("Unable to parser header line [" + line + "]");
+            else {
+                break;
             }
         }
         return props;