Package org.apache.directory.shared.util

Examples of org.apache.directory.shared.util.ByteBuffer


public class ByteBufferTest
{
    @Test
    public void testByteBufferGrowth()
    {
        ByteBuffer buf = new ByteBuffer();
        assertEquals(10, buf.capacity());
       
        for ( int ii = 0; ii < 20; ii++ )
        {
            buf.append( ii );
            assertEquals(ii, buf.get(ii));
            assertEquals(ii, buf.buffer()[ii]);
        }
       
        assertEquals(20, buf.capacity());
        buf.append( 20 );
        assertEquals(30, buf.capacity());

        // -------------------------------------------------------------------
       
        buf = new ByteBuffer( 5 );
        assertEquals(5, buf.capacity());
       
        for ( int ii = 0; ii < 5; ii++ )
        {
            buf.append( ii );
            assertEquals(ii, buf.get(ii));
            assertEquals(ii, buf.buffer()[ii]);
        }
       
        assertEquals(5, buf.capacity());
        buf.append( 5 );
        assertEquals(10, buf.capacity());
    }
View Full Code Here


        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]);
        }
    }
View Full Code Here

        }
    }
   
    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]);
        }
    }
View Full Code Here

    }


    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] );
        }
    }
View Full Code Here

    }


    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] );
        }
    }
View Full Code Here

public class ByteBufferTest
{
    @Test
    public void testByteBufferGrowth()
    {
        ByteBuffer buf = new ByteBuffer();
        assertEquals( 10, buf.capacity() );

        for ( int ii = 0; ii < 20; ii++ )
        {
            buf.append( ii );
            assertEquals( ii, buf.get( ii ) );
            assertEquals( ii, buf.buffer()[ii] );
        }

        assertEquals( 20, buf.capacity() );
        buf.append( 20 );
        assertEquals( 30, buf.capacity() );

        // -------------------------------------------------------------------

        buf = new ByteBuffer( 5 );
        assertEquals( 5, buf.capacity() );

        for ( int ii = 0; ii < 5; ii++ )
        {
            buf.append( ii );
            assertEquals( ii, buf.get( ii ) );
            assertEquals( ii, buf.buffer()[ii] );
        }

        assertEquals( 5, buf.capacity() );
        buf.append( 5 );
        assertEquals( 10, buf.capacity() );
    }
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.util.ByteBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.