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/21 09:17:33 UTC

svn commit: r358225 - in /directory/network/trunk/src: java/org/apache/mina/common/ByteBuffer.java test/org/apache/mina/common/ByteBufferTest.java

Author: trustin
Date: Wed Dec 21 00:17:23 2005
New Revision: 358225

URL: http://svn.apache.org/viewcvs?rev=358225&view=rev
Log:
Related issue: DIRMINA-146 ByteBuffer.wrap(byte[] n, int offset, int length) calls clear() on the wrapped NIO buffer
* Fixed: Niklas's fix discards the position and limit of wrapped NIO buffer.

Modified:
    directory/network/trunk/src/java/org/apache/mina/common/ByteBuffer.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=358225&r1=358224&r2=358225&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 Wed Dec 21 00:17:23 2005
@@ -239,13 +239,8 @@
      */
     public static ByteBuffer wrap( java.nio.ByteBuffer nioBuffer )
     {
-        return wrap( nioBuffer, true );
-    }
-    
-    private static ByteBuffer wrap( java.nio.ByteBuffer nioBuffer, boolean clear )
-    {
         DefaultByteBuffer buf = allocateContainer();
-        buf.init( nioBuffer, clear );
+        buf.init( nioBuffer, false );
         buf.setPooled( false );
         return buf;
     }
@@ -255,7 +250,7 @@
      */
     public static ByteBuffer wrap( byte[] byteArray )
     {
-        return wrap( java.nio.ByteBuffer.wrap( byteArray ), false );
+        return wrap( java.nio.ByteBuffer.wrap( byteArray ) );
     }
     
     /**
@@ -266,7 +261,7 @@
      */
     public static ByteBuffer wrap( byte[] byteArray, int offset, int length )
     {
-        return wrap( java.nio.ByteBuffer.wrap( byteArray, offset, length ), false );
+        return wrap( java.nio.ByteBuffer.wrap( byteArray, offset, length ) );
     }
     
     private static int getBufferStackIndex( Stack[] bufferStacks, int size )

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=358225&r1=358224&r2=358225&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 Wed Dec 21 00:17:23 2005
@@ -485,6 +485,18 @@
         Assert.assertEquals( 0x45454545, buf.getInt() );
     }
     
+    public void testWrapNioBuffer() throws Exception
+    {
+        java.nio.ByteBuffer nioBuf = java.nio.ByteBuffer.allocate( 10 );
+        nioBuf.position( 3 );
+        nioBuf.limit( 7 );
+        
+        ByteBuffer buf = ByteBuffer.wrap( nioBuf );
+        Assert.assertEquals( 3, buf.position() );
+        Assert.assertEquals( 7, buf.limit() );
+        Assert.assertEquals( 10, buf.capacity() );
+    }
+    
     public void testWrapSubArray() throws Exception
     {
         byte[] array = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };