directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r430684 - in /directory/branches/mina/0.8/src: java/org/apache/mina/common/ByteBuffer.java test/org/apache/mina/common/ByteBufferTest.java
Date Fri, 11 Aug 2006 05:46:32 GMT
Author: trustin
Date: Thu Aug 10 22:46:32 2006
New Revision: 430684

URL: http://svn.apache.org/viewvc?rev=430684&view=rev
Log:
Fixed issue: DIRMINA-243 (mark() and autoexpand)
* Made sure mark is preserved after expansion in branch 0.8

Modified:
    directory/branches/mina/0.8/src/java/org/apache/mina/common/ByteBuffer.java
    directory/branches/mina/0.8/src/test/org/apache/mina/common/ByteBufferTest.java

Modified: directory/branches/mina/0.8/src/java/org/apache/mina/common/ByteBuffer.java
URL: http://svn.apache.org/viewvc/directory/branches/mina/0.8/src/java/org/apache/mina/common/ByteBuffer.java?rev=430684&r1=430683&r2=430684&view=diff
==============================================================================
--- directory/branches/mina/0.8/src/java/org/apache/mina/common/ByteBuffer.java (original)
+++ directory/branches/mina/0.8/src/java/org/apache/mina/common/ByteBuffer.java Thu Aug 10
22:46:32 2006
@@ -559,6 +559,12 @@
         private boolean autoExpand;
         private boolean pooled;
 
+        /**
+         * We don't have any access to Buffer.markValue(), so we need to track it down,
+         * which will cause small extra overhead.
+         */
+        private int mark = -1;
+
         protected DefaultByteBuffer()
         {
         }
@@ -660,6 +666,10 @@
         {
             autoExpand( newPosition, 0 );
             buf.position( newPosition );
+            if( mark > newPosition )
+        	{
+            	mark = -1;
+        	}
             return this;
         }
 
@@ -672,12 +682,17 @@
         {
             autoExpand( newLimit, 0 );
             buf.limit( newLimit );
+            if( mark > newLimit )
+            {
+            	mark = -1;
+            }
             return this;
         }
 
         public ByteBuffer mark()
         {
             buf.mark();
+            mark = buf.position();
             return this;
         }
 
@@ -690,18 +705,21 @@
         public ByteBuffer clear()
         {
             buf.clear();
+            mark = -1;
             return this;
         }
 
         public ByteBuffer flip()
         {
             buf.flip();
+            mark = -1;
             return this;
         }
 
         public ByteBuffer rewind()
         {
             buf.rewind();
+            mark = -1;
             return this;
         }
 
@@ -792,6 +810,7 @@
         public ByteBuffer compact()
         {
             buf.compact();
+            mark = -1;
             return this;
         }
 
@@ -1530,7 +1549,14 @@
             int limit = oldBuf.limit();
             oldBuf.clear();
             newBuf.put( oldBuf );
-            newBuf.position( 0 );
+            
+            // Transfer marked position to the new buffer.
+            if( mark >= 0 )
+            {
+            	newBuf.position( mark );
+            	newBuf.mark();
+            }
+            
             newBuf.limit( limit );
             newBuf.position( pos );
             this.buf = newBuf;

Modified: directory/branches/mina/0.8/src/test/org/apache/mina/common/ByteBufferTest.java
URL: http://svn.apache.org/viewvc/directory/branches/mina/0.8/src/test/org/apache/mina/common/ByteBufferTest.java?rev=430684&r1=430683&r2=430684&view=diff
==============================================================================
--- directory/branches/mina/0.8/src/test/org/apache/mina/common/ByteBufferTest.java (original)
+++ directory/branches/mina/0.8/src/test/org/apache/mina/common/ByteBufferTest.java Thu Aug
10 22:46:32 2006
@@ -147,6 +147,26 @@
         Assert.assertEquals( 4, buf.capacity() );
     }
     
+    public void testAutoExpandMark() throws Exception
+    {
+    	ByteBuffer buf = ByteBuffer.allocate( 4 ).setAutoExpand( true );
+
+    	buf.put( ( byte ) 0 );
+    	buf.put( ( byte ) 0 );
+    	buf.put( ( byte ) 0 );
+
+    	// Position should be 3 when we reset this buffer.
+    	buf.mark();
+
+    	// Overflow it
+    	buf.put( ( byte ) 0 );
+    	buf.put( ( byte ) 0 );
+    	
+    	Assert.assertEquals( 5, buf.position() );
+    	buf.reset();
+    	Assert.assertEquals( 3, buf.position() );
+    }
+    
     public void testPooledProperty() throws Exception
     {
         ByteBuffer buf = ByteBuffer.allocate( 16 );



Mime
View raw message