From commits-return-7147-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Sat Dec 03 18:31:41 2005 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 70453 invoked from network); 3 Dec 2005 18:31:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 Dec 2005 18:31:40 -0000 Received: (qmail 20579 invoked by uid 500); 3 Dec 2005 18:31:39 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 20410 invoked by uid 500); 3 Dec 2005 18:31:38 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 20238 invoked by uid 99); 3 Dec 2005 18:31:37 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 03 Dec 2005 10:31:37 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sat, 03 Dec 2005 10:31:37 -0800 Received: (qmail 70140 invoked by uid 65534); 3 Dec 2005 18:31:16 -0000 Message-ID: <20051203183116.70139.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@directory.apache.org From: niklas@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 NUL (0x00). + */ + 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() ); + } }