Search in sources :

Example 26 with ByteArrayDataInputStream

use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.

the class ByteArrayDataInputOutputStreamTest method testBoolean.

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();
}
Also used : ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 27 with ByteArrayDataInputStream

use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.

the class ByteArrayDataInputOutputStreamTest method testOffsetAndLimit.

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));
}
Also used : ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream)

Example 28 with ByteArrayDataInputStream

use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.

the class ByteArrayDataInputOutputStreamTest method testRead.

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);
}
Also used : ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteBuffer(java.nio.ByteBuffer)

Example 29 with ByteArrayDataInputStream

use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.

the class ByteArrayDataInputOutputStreamTest method testSkipBytes.

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;
}
Also used : ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream)

Example 30 with ByteArrayDataInputStream

use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.

the class ByteArrayDataInputOutputStreamTest method testByte.

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;
    }
}
Also used : ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Aggregations

ByteArrayDataInputStream (org.jgroups.util.ByteArrayDataInputStream)32 ByteArrayDataOutputStream (org.jgroups.util.ByteArrayDataOutputStream)19 EOFException (java.io.EOFException)3 IOException (java.io.IOException)3 ByteBuffer (java.nio.ByteBuffer)3 Message (org.jgroups.Message)3 IpAddress (org.jgroups.stack.IpAddress)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInput (java.io.DataInput)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 DatagramPacket (java.net.DatagramPacket)1 SocketException (java.net.SocketException)1 ArrayList (java.util.ArrayList)1 IpAddressUUID (org.jgroups.stack.IpAddressUUID)1