Author: mheath
Date: Wed Aug  6 21:02:01 2008
New Revision: 683500

URL: http://svn.apache.org/viewvc?rev=683500&view=rev
Log:
Fixed DIRMINA-614 - Make TextLineDecoder extensible

Modified:
    
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java

Modified: 
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java
URL: 
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java?rev=683500&r1=683499&r2=683500&view=diff
==============================================================================
--- 
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java
 (original)
+++ 
mina/trunk/core/src/main/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java
 Wed Aug  6 21:02:01 2008
@@ -56,7 +56,7 @@
     public TextLineDecoder() {
         this(LineDelimiter.AUTO);
     }
-    
+
     /**
      * Creates a new instance with the current default [EMAIL PROTECTED] 
Charset}
      * and the specified <tt>delimiter</tt>.
@@ -64,7 +64,7 @@
     public TextLineDecoder(String delimiter) {
         this(new LineDelimiter(delimiter));
     }
-    
+
     /**
      * Creates a new instance with the current default [EMAIL PROTECTED] 
Charset}
      * and the specified <tt>delimiter</tt>.
@@ -80,7 +80,7 @@
     public TextLineDecoder(Charset charset) {
         this(charset, LineDelimiter.AUTO);
     }
-    
+
     /**
      * Creates a new instance with the spcified <tt>charset</tt>
      * and the specified <tt>delimiter</tt>.
@@ -88,7 +88,7 @@
     public TextLineDecoder(Charset charset, String delimiter) {
         this(charset, new LineDelimiter(delimiter));
     }
-    
+
     /**
      * Creates a new instance with the specified <tt>charset</tt>
      * and the specified <tt>delimiter</tt>.
@@ -135,9 +135,9 @@
         Context ctx = getContext(session);
 
         if (LineDelimiter.AUTO.equals(delimiter)) {
-            decodeAuto(ctx, in, out);
+            decodeAuto(ctx, session, in, out);
         } else {
-            decodeNormal(ctx, in, out);
+            decodeNormal(ctx, session, in, out);
         }
     }
 
@@ -162,7 +162,7 @@
         }
     }
 
-    private void decodeAuto(Context ctx, IoBuffer in, ProtocolDecoderOutput 
out)
+    private void decodeAuto(Context ctx, IoSession session, IoBuffer in, 
ProtocolDecoderOutput out)
             throws CharacterCodingException, ProtocolDecoderException {
 
         int matchCount = ctx.getMatchCount();
@@ -204,7 +204,7 @@
                     buf.flip();
                     buf.limit(buf.limit() - matchCount);
                     try {
-                        out.write(buf.getString(ctx.getDecoder()));
+                       writeText(session, buf.getString(ctx.getDecoder()), 
out);
                     } finally {
                         buf.clear();
                     }
@@ -227,7 +227,7 @@
         ctx.setMatchCount(matchCount);
     }
 
-    private void decodeNormal(Context ctx, IoBuffer in, ProtocolDecoderOutput 
out)
+    private void decodeNormal(Context ctx, IoSession session, IoBuffer in, 
ProtocolDecoderOutput out)
             throws CharacterCodingException, ProtocolDecoderException {
 
         int matchCount = ctx.getMatchCount();
@@ -262,7 +262,7 @@
                         buf.flip();
                         buf.limit(buf.limit() - matchCount);
                         try {
-                            out.write(buf.getString(ctx.getDecoder()));
+                               writeText(session, 
buf.getString(ctx.getDecoder()), out);
                         } finally {
                             buf.clear();
                         }
@@ -290,6 +290,19 @@
         ctx.setMatchCount(matchCount);
     }
 
+    /**
+     * By default, this method propagates the decoded line of text to
+     * [EMAIL PROTECTED] ProtocolDecoderOutput#write(Object)}.  You may 
override this method to modify
+     * the default behavior.
+     *
+     * @param session  the [EMAIL PROTECTED] IoSession} the received data.
+     * @param text  the decoded text
+     * @param out  the upstream [EMAIL PROTECTED] ProtocolDecoderOutput}.
+     */
+    protected void writeText(IoSession session, String text, 
ProtocolDecoderOutput out) {
+       out.write(text);
+    }
+
     private class Context {
         private final CharsetDecoder decoder;
         private final IoBuffer buf;


Reply via email to