Search in sources :

Example 31 with ByteArrayDataInputStream

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

the class ByteArrayDataInputOutputStreamTest method testCompressedLongSequence.

public void testCompressedLongSequence() throws IOException {
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(1024);
    long[] numbers = { 0, 1, 100, 322649, Long.MAX_VALUE - 1000 };
    for (long i : numbers) Bits.writeLongSequence(i, i + 100, out);
    ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
    for (long i : numbers) {
        long[] seq = { 0, 0 };
        Bits.readLongSequence(in, seq, 0);
        assert Arrays.equals(seq, new long[] { i, i + 100 });
    }
}
Also used : ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 32 with ByteArrayDataInputStream

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

the class RouterStub method receive.

@Override
public void receive(Address sender, byte[] buf, int offset, int length) {
    ByteArrayDataInputStream in = new ByteArrayDataInputStream(buf, offset, length);
    GossipData data = new GossipData();
    try {
        data.readFrom(in);
        switch(data.getType()) {
            case MESSAGE:
            case SUSPECT:
                if (receiver != null)
                    receiver.receive(data);
                break;
            case GET_MBRS_RSP:
                notifyResponse(data.getGroup(), data.getPingData());
                break;
        }
    } catch (Exception ex) {
        log.error(Util.getMessage("FailedReadingData"), ex);
    }
}
Also used : 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