Search in sources :

Example 6 with ByteArrayDataInputStream

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

the class ByteArrayDataInputOutputStreamTest method testLong.

public void testLong() throws IOException {
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(1024);
    long[] numbers = { Long.MIN_VALUE, -322649, -500, 0, 1, 100, 322649, Long.MAX_VALUE };
    for (long i : numbers) out.writeLong(i);
    ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
    for (long i : numbers) {
        long num = in.readLong();
        assert num == i;
    }
}
Also used : ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 7 with ByteArrayDataInputStream

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

the class ByteArrayDataInputOutputStreamTest method testWriteBytes.

public void testWriteBytes() {
    String name = "Bela";
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(2);
    out.writeBytes(name);
    assert out.position() == name.length();
    ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
    byte[] tmp = new byte[name.length()];
    int read = in.read(tmp, 0, tmp.length);
    assert read == name.length();
    assert name.equals(new String(tmp));
}
Also used : ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 8 with ByteArrayDataInputStream

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

the class ByteArrayDataInputOutputStreamTest method testPosition.

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

Example 9 with ByteArrayDataInputStream

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

the class ByteArrayDataInputOutputStreamTest method testWriteChars.

public void testWriteChars() throws IOException {
    String name = "Bela";
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(2);
    out.writeChars(name);
    assert out.position() == name.length() * 2;
    ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
    char[] tmp = new char[name.length()];
    for (int i = 0; i < name.length(); i++) tmp[i] = in.readChar();
    assert name.equals(new String(tmp));
}
Also used : ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 10 with ByteArrayDataInputStream

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

the class ByteArrayDataInputOutputStreamTest method testShort.

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;
    }
}
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