You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by tr...@apache.org on 2005/12/07 17:48:55 UTC

svn commit: r354798 - in /directory/network/trunk/src/java/org/apache/mina/filter/codec/textline: TextLineCodecFactory.java TextLineDecoder.java TextLineEncoder.java

Author: trustin
Date: Wed Dec  7 08:48:51 2005
New Revision: 354798

URL: http://svn.apache.org/viewcvs?rev=354798&view=rev
Log:
* Revised JavaDoc for textline package
* TextLineDecoder now releases resources properly.

Modified:
    directory/network/trunk/src/java/org/apache/mina/filter/codec/textline/TextLineCodecFactory.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java
    directory/network/trunk/src/java/org/apache/mina/filter/codec/textline/TextLineEncoder.java

Modified: directory/network/trunk/src/java/org/apache/mina/filter/codec/textline/TextLineCodecFactory.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/textline/TextLineCodecFactory.java?rev=354798&r1=354797&r2=354798&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/textline/TextLineCodecFactory.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/textline/TextLineCodecFactory.java Wed Dec  7 08:48:51 2005
@@ -24,13 +24,11 @@
 import org.apache.mina.filter.codec.ProtocolCodecFactory;
 import org.apache.mina.filter.codec.ProtocolDecoder;
 import org.apache.mina.filter.codec.ProtocolEncoder;
-import org.apache.mina.filter.codec.serialization.ObjectSerializationDecoder;
-import org.apache.mina.filter.codec.serialization.ObjectSerializationEncoder;
 
 /**
- * A {@link ProtocolCodecFactory} that serializes and deserializes Java objects.
- * This codec is very useful when you have to prototype your application rapidly
- * without any specific codec.
+ * A {@link ProtocolCodecFactory} that performs encoding and decoding between
+ * a text line data and a Java string object.  This codec is useful especially
+ * when you work with a text-based protocols such as SMTP and IMAP.
  *
  * @author The Apache Directory Project (dev@directory.apache.org)
  * @version $Rev$, $Date$
@@ -53,8 +51,8 @@
      */
     public TextLineCodecFactory( Charset charset )
     {
-        encoder = new TextLineEncoder( charset, LineDelimiter.WINDOWS );
-        decoder = new TextLineDecoder( charset, LineDelimiter.WINDOWS );
+        encoder = new TextLineEncoder( charset, LineDelimiter.UNIX );
+        decoder = new TextLineDecoder( charset, LineDelimiter.AUTO );
     }
 
     public ProtocolEncoder getEncoder()
@@ -68,12 +66,12 @@
     }
     
     /**
-     * Returns the allowed maximum size of the encoded object.
-     * If the size of the encoded object exceeds this value, the encoder
+     * Returns the allowed maximum size of the encoded line.
+     * If the size of the encoded line exceeds this value, the encoder
      * will throw a {@link IllegalArgumentException}.  The default value
      * is {@link Integer#MAX_VALUE}.
      * <p>
-     * This method does the same job with {@link ObjectSerializationEncoder#setMaxObjectSize(int)}.
+     * This method does the same job with {@link TextLineEncoder#getMaxLineLength()}.
      */
     public int gerEncoderMaxLineLength()
     {
@@ -81,12 +79,12 @@
     }
     
     /**
-     * Sets the allowed maximum size of the encoded object.
-     * If the size of the encoded object exceeds this value, the encoder
+     * Sets the allowed maximum size of the encoded line.
+     * If the size of the encoded line exceeds this value, the encoder
      * will throw a {@link IllegalArgumentException}.  The default value
      * is {@link Integer#MAX_VALUE}.
      * <p>
-     * This method does the same job with {@link ObjectSerializationEncoder#setMaxObjectSize(int)}.
+     * This method does the same job with {@link TextLineEncoder#setMaxLineLength(int)}.
      */
     public void setEncoderMaxLineLength( int maxLineLength )
     {
@@ -94,12 +92,12 @@
     }
     
     /**
-     * Returns the allowed maximum size of the object to be decoded.
-     * If the size of the object to be decoded exceeds this value, the
+     * Returns the allowed maximum size of the line to be decoded.
+     * If the size of the line to be decoded exceeds this value, the
      * decoder will throw a {@link BufferDataException}.  The default
-     * value is <tt>1048576</tt> (1MB).
+     * value is <tt>1024</tt> (1KB).
      * <p>
-     * This method does the same job with {@link ObjectSerializationDecoder#getMaxObjectSize()}.
+     * This method does the same job with {@link TextLineDecoder#getMaxLineLength()}.
      */
     public int gerDecoderMaxLineLength()
     {
@@ -107,12 +105,12 @@
     }
     
     /**
-     * Sets the allowed maximum size of the object to be decoded.
-     * If the size of the object to be decoded exceeds this value, the
+     * Sets the allowed maximum size of the line to be decoded.
+     * If the size of the line to be decoded exceeds this value, the
      * decoder will throw a {@link BufferDataException}.  The default
-     * value is <tt>1048576</tt> (1MB).
+     * value is <tt>1024</tt> (1KB).
      * <p>
-     * This method does the same job with {@link ObjectSerializationDecoder#setMaxObjectSize(int)}.
+     * This method does the same job with {@link TextLineDecoder#setMaxLineLength(int)}.
      */
     public void setDecoderMaxLineLength( int maxLineLength )
     {

Modified: directory/network/trunk/src/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java?rev=354798&r1=354797&r2=354798&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java Wed Dec  7 08:48:51 2005
@@ -25,16 +25,16 @@
 import org.apache.mina.common.BufferDataException;
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
-import org.apache.mina.filter.codec.ProtocolDecoderAdapter;
+import org.apache.mina.filter.codec.ProtocolDecoder;
 import org.apache.mina.filter.codec.ProtocolDecoderOutput;
 
 /**
- * Decodes a text line into a string.
+ * A {@link ProtocolDecoder} which decodes a text line into a string.
  * 
  * @author The Apache Directory Project (dev@directory.apache.org)
  * @version $Rev$, $Date$,
  */
-public class TextLineDecoder extends ProtocolDecoderAdapter
+public class TextLineDecoder implements ProtocolDecoder
 {
     private static final String CONTEXT = TextLineDecoder.class.getName() + ".context";
 
@@ -43,16 +43,28 @@
     private ByteBuffer delimBuf;
     private int maxLineLength = 1024;
     
+    /**
+     * Creates a new instance with the current default {@link Charset}
+     * and {@link LineDelimiter#AUTO} delimiter.
+     */
     public TextLineDecoder()
     {
         this( Charset.defaultCharset(), LineDelimiter.AUTO );
     }
     
+    /**
+     * Creates a new instance with the spcified <tt>charset</tt>
+     * and {@link LineDelimiter#AUTO} delimiter.
+     */
     public TextLineDecoder( Charset charset )
     {
         this( charset, LineDelimiter.AUTO );
     }
-    
+
+    /**
+     * Creates a new instance with the specified <tt>charset</tt>
+     * and the specified <tt>delimiter</tt>.
+     */
     public TextLineDecoder( Charset charset, LineDelimiter delimiter )
     {
         if( charset == null )
@@ -69,8 +81,8 @@
     }
     
     /**
-     * Returns the allowed maximum size of the line to be encoded.
-     * If the length of the line to be encoded exceeds this value, this
+     * Returns the allowed maximum size of the line to be decoded.
+     * If the size of the line to be decoded exceeds this value, the
      * decoder will throw a {@link BufferDataException}.  The default
      * value is <tt>1024</tt> (1KB).
      */
@@ -80,8 +92,8 @@
     }
     
     /**
-     * Sets the allowed maximum size of the object to be decoded.
-     * If the size of the object to be decoded exceeds this value, this
+     * Sets the allowed maximum size of the line to be decoded.
+     * If the size of the line to be decoded exceeds this value, the
      * decoder will throw a {@link BufferDataException}.  The default
      * value is <tt>1024</tt> (1KB).
      */
@@ -125,6 +137,16 @@
                             ctx.getMatchCount(),
                             ctx.getDecoder(),
                             out ) );
+        }
+    }
+
+    public void dispose( IoSession session ) throws Exception
+    {
+        Context ctx = ( Context ) session.getAttribute( CONTEXT );
+        if( ctx != null )
+        {
+            ctx.getBuffer().release();
+            session.removeAttribute( CONTEXT );
         }
     }
 

Modified: directory/network/trunk/src/java/org/apache/mina/filter/codec/textline/TextLineEncoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/codec/textline/TextLineEncoder.java?rev=354798&r1=354797&r2=354798&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/codec/textline/TextLineEncoder.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/codec/textline/TextLineEncoder.java Wed Dec  7 08:48:51 2005
@@ -21,14 +21,15 @@
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetEncoder;
 
-import org.apache.mina.common.BufferDataException;
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolEncoder;
 import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
 import org.apache.mina.filter.codec.ProtocolEncoderOutput;
 
 /**
- * Encodes a string into a text line which ends with <code>"\r\n"</code>.
+ * A {@link ProtocolEncoder} which encodes a string into a text line
+ * which ends with the delimiter.
  * 
  * @author The Apache Directory Project (dev@directory.apache.org)
  * @version $Rev$, $Date$,
@@ -39,7 +40,7 @@
 
     private final Charset charset;
     private final LineDelimiter delimiter;
-    private int maxLineLength = 1024;
+    private int maxLineLength = Integer.MAX_VALUE;
 
     public TextLineEncoder()
     {
@@ -77,10 +78,10 @@
     }
     
     /**
-     * Returns the allowed maximum size of the line to be encoded.
-     * If the length of the line to be encoded exceeds this value, this
-     * decoder will throw a {@link BufferDataException}.  The default
-     * value is <tt>1024</tt> (1KB).
+     * Returns the allowed maximum size of the encoded line.
+     * If the size of the encoded line exceeds this value, the encoder
+     * will throw a {@link IllegalArgumentException}.  The default value
+     * is {@link Integer#MAX_VALUE}.
      */
     public int getMaxLineLength()
     {
@@ -88,10 +89,10 @@
     }
     
     /**
-     * Sets the allowed maximum size of the object to be decoded.
-     * If the size of the object to be decoded exceeds this value, this
-     * decoder will throw a {@link BufferDataException}.  The default
-     * value is <tt>1024</tt> (1KB).
+     * Sets the allowed maximum size of the encoded line.
+     * If the size of the encoded line exceeds this value, the encoder
+     * will throw a {@link IllegalArgumentException}.  The default value
+     * is {@link Integer#MAX_VALUE}.
      */
     public void setMaxLineLength( int maxLineLength )
     {