directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nik...@apache.org
Subject svn commit: r351998 - in /directory/network/trunk/src: java/org/apache/mina/common/ByteBuffer.java java/org/apache/mina/common/ByteBufferProxy.java test/org/apache/mina/common/ByteBufferTest.java
Date Sat, 03 Dec 2005 18:31:15 GMT
Author: niklas
Date: Sat Dec  3 10:31:01 2005
New Revision: 351998

URL: http://svn.apache.org/viewcvs?rev=351998&view=rev
Log:
Added the ByteBuffer.sweep() methods resolving issue DIRMINA-136

Modified:
    directory/network/trunk/src/java/org/apache/mina/common/ByteBuffer.java
    directory/network/trunk/src/java/org/apache/mina/common/ByteBufferProxy.java
    directory/network/trunk/src/test/org/apache/mina/common/ByteBufferTest.java

Modified: directory/network/trunk/src/java/org/apache/mina/common/ByteBuffer.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/ByteBuffer.java?rev=351998&r1=351997&r2=351998&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/ByteBuffer.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/ByteBuffer.java Sat Dec  3 10:31:01
2005
@@ -871,6 +871,20 @@
      */
     public abstract ByteBuffer fillAndReset( int size );
     
+    /**
+     * Sweeps this buffer clean from any previous content. Sets the position to 
+     * zero and the limit to the capacity and sets all bytes between position 
+     * and limit to <code>NUL (0x00)</code>.
+     */
+    public abstract ByteBuffer sweep();
+    
+    /**
+     * Sweeps this buffer clean from any previous content. Sets the position to 
+     * zero and the limit to the capacity and sets all bytes between position 
+     * and limit to the specified value.
+     */
+    public abstract ByteBuffer sweep( byte value );
+    
     private static class DefaultByteBuffer extends ByteBuffer
     {
         private java.nio.ByteBuffer buf;
@@ -1876,6 +1890,18 @@
         {
             autoExpand( size );
             return position( position() + size );
+        }
+
+        public ByteBuffer sweep()
+        {
+            clear();
+            return fillAndReset( remaining() );
+        }
+
+        public ByteBuffer sweep( byte value )
+        {
+            clear();
+            return fillAndReset( value, remaining() );
         }
 
         public ByteBuffer fill( byte value, int size )

Modified: directory/network/trunk/src/java/org/apache/mina/common/ByteBufferProxy.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/ByteBufferProxy.java?rev=351998&r1=351997&r2=351998&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/ByteBufferProxy.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/ByteBufferProxy.java Sat Dec 
3 10:31:01 2005
@@ -511,6 +511,18 @@
         return this;
     }
 
+    public ByteBuffer sweep()
+    {
+        buf.sweep();
+        return this;
+    }
+
+    public ByteBuffer sweep( byte value )
+    {
+        buf.sweep( value );
+        return this;
+    }
+
     public boolean isAutoExpand()
     {
         return buf.isAutoExpand();

Modified: directory/network/trunk/src/test/org/apache/mina/common/ByteBufferTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/common/ByteBufferTest.java?rev=351998&r1=351997&r2=351998&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/common/ByteBufferTest.java (original)
+++ directory/network/trunk/src/test/org/apache/mina/common/ByteBufferTest.java Sat Dec  3
10:31:01 2005
@@ -406,4 +406,34 @@
         // This assertion is just to make sure that deserialization occurred.
         Assert.assertNotSame( o, o2 );
     }
+    
+    public void testSweepWithZeros() throws Exception
+    {
+        ByteBuffer buf = ByteBuffer.allocate( 4 );
+        buf.putInt( 0xdeadbeef );
+        buf.clear();
+        Assert.assertEquals( 0xdeadbeef, buf.getInt() );
+        Assert.assertEquals( 4, buf.position() );
+        Assert.assertEquals( 4, buf.limit() );
+        
+        buf.sweep();
+        Assert.assertEquals( 0, buf.position() );
+        Assert.assertEquals( 4, buf.limit() );
+        Assert.assertEquals( 0x0, buf.getInt() );
+    }
+    
+    public void testSweepNonZeros() throws Exception
+    {
+        ByteBuffer buf = ByteBuffer.allocate( 4 );
+        buf.putInt( 0xdeadbeef );
+        buf.clear();
+        Assert.assertEquals( 0xdeadbeef, buf.getInt() );
+        Assert.assertEquals( 4, buf.position() );
+        Assert.assertEquals( 4, buf.limit() );
+        
+        buf.sweep( ( byte ) 0x45 );
+        Assert.assertEquals( 0, buf.position() );
+        Assert.assertEquals( 4, buf.limit() );
+        Assert.assertEquals( 0x45454545, buf.getInt() );
+    }
 }



Mime
View raw message