Search in sources :

Example 6 with ByteArrayDataOutputStream

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

the class ByteArrayDataInputOutputStreamTest method testExpanding.

public void testExpanding() throws IOException {
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(1);
    for (int i = 'A'; i < 'A' + 20; i++) out.write(i);
    assert out.position() == 20;
    byte[] buffer = new byte[20];
    for (int i = 0; i < 5; i++) out.write(buffer);
    assert out.position() == 120;
}
Also used : ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 7 with ByteArrayDataOutputStream

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

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

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

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

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