Package org.jgroups.util

Examples of org.jgroups.util.ByteArrayDataInputStream


        while(sock != null && receiver != null && Thread.currentThread().equals(receiver)) {
            packet.setData(receive_buf, 0, receive_buf.length);
            try {
                sock.receive(packet);
                inp=new ByteArrayDataInputStream(packet.getData(), packet.getOffset(), packet.getLength());
                Message msg=new Message();
                msg.readFrom(inp);
                up(new Event(Event.MSG, msg));
            }
            catch(SocketException socketEx) {
View Full Code Here


        assert in.position() == 11;
    }

    public void testRead() {
        byte[] buf={'b', 'e', 'l', 'a'};
        ByteArrayDataInputStream  in=new ByteArrayDataInputStream(buf);
        for(byte b: buf)
            assert b == in.read();
        assert -1 == in.read();

        in=new ByteArrayDataInputStream(buf, 2, 2);
        assert in.read() == 'l';
        assert in.read() == 'a';
        assert -1 == in.read();

        ByteBuffer buffer=ByteBuffer.wrap(buf);
        System.out.println("buffer = " + buffer);
    }
View Full Code Here

        System.out.println("buffer = " + buffer);
    }

    public void testReadFully() {
        byte[] name="Bela".getBytes();
        ByteArrayDataInputStream  in=new ByteArrayDataInputStream(name);
        byte[] buf=new byte[10];
        int read=in.read(buf, 0, buf.length);
        assert read == 4;
        assert in.position() == 4;

        in.position(0);
        try {
            in.readFully(buf, 0, buf.length);
            assert false : "readFully() should have thrown an EOFException";
        }
        catch(Exception eof_ex) {
            System.out.println("got exception as expected: " + eof_ex);
            assert eof_ex instanceof EOFException;
View Full Code Here

    public void testByte() throws IOException {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(Byte.MAX_VALUE * 2);
        for(short i=Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++)
            out.writeByte(i);

        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        for(short i=Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
            byte read=in.readByte();
            assert i == read;
        }
    }
View Full Code Here

    public void testUnsignedByte() throws IOException {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(20);
        byte[] bytes={-100, -50, 0, 1, 100, 127};
        for(byte b: bytes)
            out.writeByte(b);
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        for(byte b: bytes) {
            int tmp=in.readUnsignedByte();
            assert tmp == (b & 0xff);
        }
    }
View Full Code Here

    public void testBoolean() throws Exception {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(2);
        out.writeBoolean(true);
        out.writeBoolean(false);
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        assert in.readBoolean();
        assert !in.readBoolean();
    }
View Full Code Here

    public void testShort() throws IOException {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(Short.MAX_VALUE * 4 + 10);
        for(int i=Short.MIN_VALUE; i <= Short.MAX_VALUE; i++)
            out.writeShort(i);

        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        for(int i=Short.MIN_VALUE; i <= Short.MAX_VALUE; i++) {
            short read=in.readShort();
            assert i == read;
        }
    }
View Full Code Here

    public void testUnsignedShort() throws IOException {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(20);
        out.writeShort(-22);
        out.writeShort(22);
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        short num=in.readShort();
        assert num == -22;
        num=in.readShort();
        assert num == 22;

        in.position(0);
        int val=in.readUnsignedShort();
        assert val == 65514;
        val=in.readUnsignedShort();
        assert val == 22;
    }
View Full Code Here

        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(1024);
        for(int i=0; i < 500; i++) {
            int ch='a' + i;
            out.writeChar(ch);
        }
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        for(int i=0; i < 500; i++) {
            char ch=in.readChar();
            assert ch == 'a' + i;
        }
    }
View Full Code Here

    public void testInt() throws IOException {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(1024);
        int[] numbers={Integer.MIN_VALUE, -322649, -500, 0, 1, 100, 322649, Integer.MAX_VALUE};
        for(int i: numbers)
            out.writeInt(i);
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        for(int i: numbers) {
            int num=in.readInt();
            assert num == i;
        }
    }
View Full Code Here

TOP

Related Classes of org.jgroups.util.ByteArrayDataInputStream

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.