Package org.jgroups.util

Examples of org.jgroups.util.ByteArrayDataInputStream


    public static void testReadLine() throws IOException {
        String str="Gallia est omnis divisa in partes tres,\n\rquarum unam incolunt Belgae,\naliam Aquitani," +
          "\ntertiam qui ipsorum lingua Celtae, nostra Galli appellantur";
        byte[] buf=str.getBytes();
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(buf);
        List<String> lines=new ArrayList<String>(4);
        String line;
        while((line=in.readLine()) !=  null) {
            System.out.println(line);
            lines.add(line);
        }
        assert lines.size() == 4;
    }
View Full Code Here


public class ByteArrayDataInputOutputStreamTest {

    public void testLimit() {
        byte[] buf=new byte[100];
        buf[0]='B'; buf[1]='e'; buf[2]='l'; buf[3]='a';
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(buf);
        assert in.position() == 0;
        assert in.limit() == buf.length;
        assert in.capacity() == buf.length;

        in=new ByteArrayDataInputStream(buf, 0, 4);
        assert in.position() == 0;
        assert in.limit() == 4;
        assert in.capacity() == buf.length;
        byte tmp[]=new byte[4];
        in.read(tmp, 0, tmp.length);
        assert "Bela".equals(new String(tmp));
    }
View Full Code Here

    }

    public void testOffsetAndLimit() {
        byte[] buf=new byte[100];
        buf[10]='B'; buf[11]='e'; buf[12]='l'; buf[13]='a';
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(buf, 10, 4);
        assert in.position() == 10;
        assert in.limit() == 14;
        assert in.capacity() == buf.length;
        byte tmp[]=new byte[4];
        in.read(tmp, 0, tmp.length);
        assert "Bela".equals(new String(tmp));
    }
View Full Code Here

    }

    public void testReadBeyondLimit() {
        byte[] buf=new byte[100];
        buf[10]='B'; buf[11]='e'; buf[12]='l'; buf[13]='a';
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(buf, 10, 4);
        assert in.position() == 10;
        assert in.limit() == 14;
        assert in.capacity() == buf.length;
        byte tmp[]=new byte[5];
        try {
            in.readFully(tmp, 0, tmp.length);
            assert false : " should have gotten an exception";
        }
        catch(Exception ex) {
            System.out.println("caught exception as expected: " + ex);
            assert ex instanceof EOFException;
        }

        in.position(10);
        for(int i=0; i < 4; i++) in.read();
        assert in.read() == -1;
    }
View Full Code Here


    public void testPosition() {
        byte[] buf=new byte[100];
        buf[10]='B'; buf[11]='e'; buf[12]='l'; buf[13]='a';
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(buf, 10, 4);
        in.position(13);
        try {
            in.position(14);
        }
        catch(Exception ex) {
            System.out.println("caught exception as expected: " + ex);
            assert ex instanceof IndexOutOfBoundsException;
        }
View Full Code Here

        out.writeInt(24);
    }

    public void testSkipBytes() {
        byte[] buf={'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'};
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(buf);
        assert in.position() == 0;
        int skipped=in.skipBytes(6);
        assert skipped == 6;
        assert in.position() == 6;

        skipped=in.skipBytes(0);
        assert skipped == 0;
        assert in.position() == 6;

        skipped=in.skipBytes(-1);
        assert skipped == 0;
        assert in.position() == 6;

        skipped=in.skipBytes(5);
        assert skipped == 5;
        assert in.position() == 11;

        in.position(6);
        skipped=in.skipBytes(20);
        assert skipped == 5;
        assert in.position() == 11;
    }
View Full Code Here

        addHeaders(msg);
        byte[] buf=Util.streamableToByteBuffer(msg);

        // ExposedByteArrayInputStream input=new ExposedByteArrayInputStream(buf);
        // DataInput in=new DataInputStream(input);
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(buf);

        Message msg2=new Message(false);
        int payload_position=msg2.readFromSkipPayload(in);
        msg2.setBuffer(buf, payload_position, buf.length - payload_position);
        assert msg2.getOffset() == payload_position;
View Full Code Here

        addHeaders(msg);
        byte[] buf=Util.streamableToByteBuffer(msg);

        // ExposedByteArrayInputStream input=new ExposedByteArrayInputStream(buf);
        // DataInput in=new DataInputStream(input);
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(buf);
        Message msg2=new Message(false);
        int payload_position=msg2.readFromSkipPayload(in);
        if(payload_position >= 0)
            msg2.setBuffer(buf, payload_position, buf.length - payload_position);
        assert msg2.getOffset() == 0;
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.