Search in sources :

Example 31 with ByteArrayDataOutputStream

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

Example 32 with ByteArrayDataOutputStream

use of org.jgroups.util.ByteArrayDataOutputStream 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 33 with ByteArrayDataOutputStream

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

the class RouterStub method writeRequest.

protected synchronized void writeRequest(GossipData req) throws Exception {
    int size = req.serializedSize();
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(size + 5);
    req.writeTo(out);
    client.send(remote, out.buffer(), 0, out.position());
}
Also used : 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