You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by el...@apache.org on 2013/04/10 12:11:03 UTC

[4/5] git commit: Revert "o Fixed an infinite loop when the buffer is empty while decoding"

Revert "o Fixed an infinite loop when the buffer is empty while decoding"

This reverts commit f274585830c82da8e989b45707472b7777f9207a.


Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/df8c5798
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/df8c5798
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/df8c5798

Branch: refs/heads/trunk
Commit: df8c57981b50e1264fa073f205b05a7f362b39a5
Parents: 3ce5c6d
Author: Emmanuel Lécharny <el...@apache.org>
Authored: Wed Apr 10 12:09:48 2013 +0200
Committer: Emmanuel Lécharny <el...@apache.org>
Committed: Wed Apr 10 12:09:48 2013 +0200

----------------------------------------------------------------------
 .../apache/mina/codec/textline/LineDelimiter.java  |   13 ++++++++++++-
 .../mina/codec/textline/TextLineDecoder.java       |   15 ++++-----------
 2 files changed, 16 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/df8c5798/codec/src/main/java/org/apache/mina/codec/textline/LineDelimiter.java
----------------------------------------------------------------------
diff --git a/codec/src/main/java/org/apache/mina/codec/textline/LineDelimiter.java b/codec/src/main/java/org/apache/mina/codec/textline/LineDelimiter.java
index bc74f38..c6f858a 100644
--- a/codec/src/main/java/org/apache/mina/codec/textline/LineDelimiter.java
+++ b/codec/src/main/java/org/apache/mina/codec/textline/LineDelimiter.java
@@ -19,6 +19,9 @@
  */
 package org.apache.mina.codec.textline;
 
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+
 /**
  * A delimiter which is appended to the end of a text line, such as
  * <tt>CR/LF</tt>. This class defines default delimiters for various
@@ -33,7 +36,15 @@ package org.apache.mina.codec.textline;
  */
 public class LineDelimiter {
     /** the line delimiter constant of the current O/S. */
-    public static final LineDelimiter DEFAULT = new LineDelimiter(System.getProperty("line.separator"));
+    public static final LineDelimiter DEFAULT;
+
+    /** Compute the default delimiter on he current OS */
+    static {
+        ByteArrayOutputStream bout = new ByteArrayOutputStream();
+        PrintWriter out = new PrintWriter(bout, true);
+        out.println();
+        DEFAULT = new LineDelimiter(new String(bout.toByteArray()));
+    }
 
     /**
      * A special line delimiter which is used for auto-detection of

http://git-wip-us.apache.org/repos/asf/mina/blob/df8c5798/codec/src/main/java/org/apache/mina/codec/textline/TextLineDecoder.java
----------------------------------------------------------------------
diff --git a/codec/src/main/java/org/apache/mina/codec/textline/TextLineDecoder.java b/codec/src/main/java/org/apache/mina/codec/textline/TextLineDecoder.java
index 41a3582..845ee24 100644
--- a/codec/src/main/java/org/apache/mina/codec/textline/TextLineDecoder.java
+++ b/codec/src/main/java/org/apache/mina/codec/textline/TextLineDecoder.java
@@ -95,7 +95,7 @@ public class TextLineDecoder implements ProtocolDecoder<ByteBuffer, String, Text
      */
     public TextLineDecoder(Charset charset, LineDelimiter delimiter) {
         if (charset == null) {
-            throw new IllegalArgumentException("charset parameter should not be null");
+            throw new IllegalArgumentException("charset parameter shuld not be null");
         }
 
         if (delimiter == null) {
@@ -169,11 +169,6 @@ public class TextLineDecoder implements ProtocolDecoder<ByteBuffer, String, Text
      * {@inheritDoc}
      */
     public String[] decode(ByteBuffer in, Context ctx) {
-        // Don't do anything if we don't have bytes in the buffer
-        if (!in.hasRemaining()) {
-            return null;
-        }
-
         if (LineDelimiter.AUTO.equals(delimiter)) {
             return decodeAuto(ctx, in);
         } else {
@@ -249,7 +244,6 @@ public class TextLineDecoder implements ProtocolDecoder<ByteBuffer, String, Text
                 } finally {
                     ctx.reset();
                 }
-
                 oldPos = pos;
                 matchCount = 0;
             }
@@ -260,7 +254,6 @@ public class TextLineDecoder implements ProtocolDecoder<ByteBuffer, String, Text
         ctx.append(in);
 
         ctx.setMatchCount(matchCount);
-
         return decoded.toArray(new String[decoded.size()]);
     }
 
@@ -312,6 +305,7 @@ public class TextLineDecoder implements ProtocolDecoder<ByteBuffer, String, Text
                     } finally {
                         ctx.reset();
                     }
+                    
 
                     oldPos = pos;
                     matchCount = 0;
@@ -347,7 +341,7 @@ public class TextLineDecoder implements ProtocolDecoder<ByteBuffer, String, Text
 
         /** The number of lines found so far */
         private int matchCount = 0;
-
+        
         /**
          * Overflow length
          */
@@ -374,7 +368,7 @@ public class TextLineDecoder implements ProtocolDecoder<ByteBuffer, String, Text
         public void setMatchCount(int matchCount) {
             this.matchCount = matchCount;
         }
-
+        
         public int getOverflowLength() {
             return overflowLength;
         }
@@ -394,7 +388,6 @@ public class TextLineDecoder implements ProtocolDecoder<ByteBuffer, String, Text
                 buf = b;
             }
         }
-
         public void append(ByteBuffer in) {
             if (buf.position() > maxLineLength - in.remaining()) {
                 overflowLength = buf.position() + in.remaining();