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/04/15 15:01:15 UTC

svn commit: r161449 - in directory/network/trunk/src/java/org/apache/mina/protocol: ProtocolEncoder.java codec/CumulativeProtocolDecoder.java

Author: trustin
Date: Fri Apr 15 06:01:14 2005
New Revision: 161449

URL: http://svn.apache.org/viewcvs?view=rev&rev=161449
Log:
Fixed: CumulativeProtocolDecoder doesn't comact buffer when exception is thrown.

Modified:
    directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolEncoder.java
    directory/network/trunk/src/java/org/apache/mina/protocol/codec/CumulativeProtocolDecoder.java

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolEncoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolEncoder.java?view=diff&r1=161448&r2=161449
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolEncoder.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolEncoder.java Fri Apr 15 06:01:14 2005
@@ -49,5 +49,5 @@
      *                                    specification
      */
     void encode( ProtocolSession session, Object message,
-                ProtocolEncoderOutput out ) throws ProtocolViolationException;
+                 ProtocolEncoderOutput out ) throws ProtocolViolationException;
 }

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/codec/CumulativeProtocolDecoder.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/codec/CumulativeProtocolDecoder.java?view=diff&r1=161448&r2=161449
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/codec/CumulativeProtocolDecoder.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/codec/CumulativeProtocolDecoder.java Fri Apr 15 06:01:14 2005
@@ -90,22 +90,27 @@
         ByteBuffer buf = this.buf;
         buf.flip();
 
-        for( ;; )
+        try
         {
-            int oldPos = buf.position();
-            if( !doDecode( session, buf, out ) )
+            for( ;; )
             {
-                break;
-            }
-            
-            if( buf.position() == oldPos )
-            {
-                throw new IllegalStateException(
-                        "doDecode() can't return true when buffer is not consumed." );
+                int oldPos = buf.position();
+                if( !doDecode( session, buf, out ) )
+                {
+                    break;
+                }
+                
+                if( buf.position() == oldPos )
+                {
+                    throw new IllegalStateException(
+                            "doDecode() can't return true when buffer is not consumed." );
+                }
             }
         }
-
-        buf.compact();
+        finally
+        {
+            buf.compact();
+        }
     }
     
     /**
@@ -115,6 +120,8 @@
      * @param in the cumulative buffer
      * @return <tt>true</tt> if and only if there's more to decode in the buffer
      *         and you want to have <tt>doDecode</tt> method invoked again.
+     *         Return <tt>false</tt> if remaining data is not enough to decode,
+     *         then this method will be invoked again when more data is cumulated.
      * @throws ProtocolViolationException if cannot decode <tt>in</tt>.
      */
     protected abstract boolean doDecode( ProtocolSession session, ByteBuffer in,