directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r762140 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/util/ByteBuffer.java test/java/org/apache/directory/shared/ldap/util/ByteBufferTest.java
Date Sun, 05 Apr 2009 19:43:57 GMT
Author: seelmann
Date: Sun Apr  5 19:43:56 2009
New Revision: 762140

URL: http://svn.apache.org/viewvc?rev=762140&view=rev
Log:
o fixed copyOfUsedBytes method
o added append(byte[]) method
o added tests

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/ByteBuffer.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/ByteBufferTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/ByteBuffer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/ByteBuffer.java?rev=762140&r1=762139&r2=762140&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/ByteBuffer.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/ByteBuffer.java
Sun Apr  5 19:43:56 2009
@@ -97,11 +97,23 @@
     public final byte[] copyOfUsedBytes()
     {
         byte[] copy = new byte[pos];
-        System.arraycopy( buf, 0, copy, 0, pos+1 );
+        System.arraycopy( buf, 0, copy, 0, pos );
         return copy;
     }
     
-
+    
+    /**
+     * Appends the bytes to this buffer.
+     */
+    public final void append( byte[] bytes )
+    {
+        for ( byte b : bytes )
+        {
+            append( b );
+        }
+    }
+    
+    
     /**
      * Appends a byte to this buffer.
      */

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/ByteBufferTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/ByteBufferTest.java?rev=762140&r1=762139&r2=762140&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/ByteBufferTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/ByteBufferTest.java
Sun Apr  5 19:43:56 2009
@@ -63,4 +63,31 @@
         buf.append( 5 );
         assertEquals( 10, buf.capacity() );
     }
+    
+    public void testCopyOfUsedBytes()
+    {
+        ByteBuffer buf = new ByteBuffer();
+        byte[] bytes = buf.copyOfUsedBytes();
+        assertEquals( 0, bytes.length );
+        
+        for ( int ii = 0; ii < 20; ii++ )
+        {
+            buf.append( ii );
+            assertEquals( ii, buf.get( ii ) );
+            assertEquals( ii, buf.buffer()[ii] );
+            assertEquals( ii, buf.copyOfUsedBytes()[ii] );
+        }
+    }
+    
+    public void testAppendByteArray()
+    {
+        ByteBuffer buf = new ByteBuffer();
+        buf.append( new byte[]{ 0, 1, 2, 3, 4 } );
+        for ( int ii = 0; ii < 5; ii++ )
+        {
+            assertEquals( ii, buf.get( ii ) );
+            assertEquals( ii, buf.buffer()[ii] );
+            assertEquals( ii, buf.copyOfUsedBytes()[ii] );
+        }
+    }
 }



Mime
View raw message