Package org.activeio

Examples of org.activeio.Packet


                return EOSPacket.EOS_PACKET;
            if( size == 0 )
                return EmptyPacket.EMPTY_PACKET;

            ByteBuffer remaining = inputByteBuffer.slice();           
            Packet data = new ByteBufferPacket(((ByteBuffer)inputByteBuffer.flip()).slice());
           
            // Keep the remaining buffer around to fill with data.
            inputByteBuffer = remaining;
            return data;
           
View Full Code Here


                return EOSPacket.EOS_PACKET;
            if( size == 0 )
                return EmptyPacket.EMPTY_PACKET;
            inputPacket.position(size);
           
            Packet remaining = inputPacket.slice();
            inputPacket.flip();
            Packet data = inputPacket.slice();

            // Keep the remaining buffer around to fill with data.
            inputPacket = remaining;
            return data;
           
View Full Code Here

        assertEquals(90, packet2.limit());
    }

    public void testWriteAndReadByte() {
       
        Packet packet = createTestPacket(256);
        for(int i=0; i < 256; i++) {
            assertTrue(packet.write(i));
        }
        assertFalse(packet.write(0));
       
        packet.flip();
        for(int i=0; i < 256; i++) {
            assertEquals(i, packet.read());
        }      
        assertEquals(-1, packet.read());       
    }
View Full Code Here

    }
   
    public void testWriteAndReadBulkByte() {
       
        byte data[] = new byte[10];       
        Packet packet = createTestPacket(data.length*10);
        for(int i=0; i < 10; i++) {
            Arrays.fill(data,(byte)i);
            assertEquals(data.length, packet.write(data,0,data.length));
        }
        assertEquals(-1, packet.write(data,0,data.length));
       
        byte buffer[] = new byte[data.length];
        packet.flip();
        for(int i=0; i < 10; i++) {
            assertEquals(buffer.length, packet.read(buffer,0,buffer.length));
            Arrays.fill(data,(byte)i);
            assertEquals(buffer, data);
        }      
        assertEquals(-1, packet.read(buffer,0,buffer.length));
    }
View Full Code Here

*/
abstract public class PacketTestSupport extends TestCase {
    abstract Packet createTestPacket(int capacity);
   
    public void testInit() {
        Packet packet = createTestPacket(100);
        assertEquals( 100, packet.capacity() );       
        assertEquals( 0, packet.position());       
        assertEquals( 100, packet.limit() );       
        assertEquals( 100, packet.remaining() );       
        assertTrue( packet.hasRemaining() );       
    }
View Full Code Here

        assertEquals( 100, packet.remaining() );       
        assertTrue( packet.hasRemaining() );       
    }
   
    public void testPosition() {
        Packet packet = createTestPacket(100);
        packet.position(10);
        assertEquals( 10, packet.position() );       
    }
View Full Code Here

        packet.position(10);
        assertEquals( 10, packet.position() );       
    }

    public void testLimit() {
        Packet packet = createTestPacket(100);
        packet.limit(10);
        assertEquals( 10, packet.limit() );       
    }
View Full Code Here

        packet.limit(10);
        assertEquals( 10, packet.limit() );       
    }

    public void testRemaining() {
        Packet packet = createTestPacket(100);
        packet.position(5);
        packet.limit(95);
        assertEquals(90, packet.remaining());
        assertTrue(packet.hasRemaining());

        packet.position(5);
        packet.limit(5);
        assertEquals(0, packet.remaining());
        assertFalse(packet.hasRemaining());
    }
View Full Code Here

        assertEquals(0, packet.remaining());
        assertFalse(packet.hasRemaining());
    }
   
    public void testFlip() {
        Packet packet = createTestPacket(100);
        packet.position(95);
        packet.flip();       
        assertEquals(0, packet.position());
        assertEquals(95, packet.limit());
    }
View Full Code Here

        assertEquals(0, packet.position());
        assertEquals(95, packet.limit());
    }
   
    public void testClear() {
        Packet packet = createTestPacket(100);
        packet.position(5);
        packet.limit(95);
        packet.clear();       
        assertEquals(0, packet.position());
        assertEquals(100, packet.limit());
    }
View Full Code Here

TOP

Related Classes of org.activeio.Packet

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.