Search in sources :

Example 11 with ByteArrayDataOutputStream

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

the class ByteArrayDataInputOutputStreamTest method testUnsignedShort.

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

Example 12 with ByteArrayDataOutputStream

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

the class ByteArrayDataInputOutputStreamTest method testDouble.

public void testDouble() throws IOException {
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(1024);
    double[] numbers = { -322649.25, 100.7531, 0.0, 1.5, 2.75, 3.1425, 322649, 322649.75 };
    for (double i : numbers) out.writeDouble(i);
    ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
    for (double i : numbers) {
        double num = in.readDouble();
        assert num == i;
    }
}
Also used : ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 13 with ByteArrayDataOutputStream

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

the class ByteArrayDataInputOutputStreamTest method testExpanding3.

public void testExpanding3() {
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(1024);
    out.writeInt(1);
    assert out.position() == 4;
    byte[] buf = new byte[1024];
    out.write(buf);
    System.out.println("out=" + out);
    assert out.position() == 1028;
    buf = new byte[512];
    out.write(buf);
    System.out.println("out = " + out);
    assert out.position() == 1028 + 512;
}
Also used : ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 14 with ByteArrayDataOutputStream

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

the class ByteArrayDataInputOutputStreamTest method testInt.

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

Example 15 with ByteArrayDataOutputStream

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

the class ByteArrayDataInputOutputStreamTest method testFloat.

public void testFloat() throws IOException {
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(1024);
    float[] numbers = { -322649.25f, 100.7531f, 0f, 1f, 2.75f, 3.1425f, 322649f, 322649.75f };
    for (float i : numbers) out.writeFloat(i);
    ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
    for (float i : numbers) {
        float num = in.readFloat();
        assert num == i;
    }
}
Also used : ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Aggregations

ByteArrayDataOutputStream (org.jgroups.util.ByteArrayDataOutputStream)33 ByteArrayDataInputStream (org.jgroups.util.ByteArrayDataInputStream)19 IpAddress (org.jgroups.stack.IpAddress)3 Buffers (org.jgroups.nio.Buffers)2 MockSocketChannel (org.jgroups.nio.MockSocketChannel)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 DatagramPacket (java.net.DatagramPacket)1 SocketException (java.net.SocketException)1 UnknownHostException (java.net.UnknownHostException)1 ByteBuffer (java.nio.ByteBuffer)1 Address (org.jgroups.Address)1 IpAddressUUID (org.jgroups.stack.IpAddressUUID)1