Search in sources :

Example 11 with ByteArrayDataInputStream

use of org.jgroups.util.ByteArrayDataInputStream 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 ByteArrayDataInputStream

use of org.jgroups.util.ByteArrayDataInputStream 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 ByteArrayDataInputStream

use of org.jgroups.util.ByteArrayDataInputStream 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 14 with ByteArrayDataInputStream

use of org.jgroups.util.ByteArrayDataInputStream 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)

Example 15 with ByteArrayDataInputStream

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

the class BPING method run.

public void run() {
    final byte[] receive_buf = new byte[65535];
    DatagramPacket packet = new DatagramPacket(receive_buf, receive_buf.length);
    DataInput inp;
    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(msg);
        } catch (SocketException socketEx) {
            break;
        } catch (Throwable ex) {
            log.error(Util.getMessage("FailedReceivingPacketFrom"), packet.getSocketAddress(), ex);
        }
    }
    if (log.isTraceEnabled())
        log.trace("receiver thread terminated");
}
Also used : DataInput(java.io.DataInput) SocketException(java.net.SocketException) Message(org.jgroups.Message) DatagramPacket(java.net.DatagramPacket) ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream)

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