Search in sources :

Example 26 with ByteArrayDataOutputStream

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

the class ByteArrayDataInputOutputStreamTest method testUTF.

public void testUTF() throws IOException {
    String name = "Bela";
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(2);
    out.writeUTF(name);
    assert out.position() == name.length() + 2;
    ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
    String tmp = in.readUTF();
    assert name.equals(tmp);
}
Also used : ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 27 with ByteArrayDataOutputStream

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

the class ByteArrayDataInputOutputStreamTest method testConstructors.

public void testConstructors() throws Exception {
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(32);
    byte[] tmp = "hello world".getBytes();
    out.writeInt(tmp.length);
    out.write(tmp);
    ByteBuffer input_buf = out.getByteBuffer();
    ByteArrayDataInputStream in = new ByteArrayDataInputStream(input_buf);
    int length = in.readInt();
    byte[] tmp2 = new byte[length];
    in.read(tmp2, 0, tmp2.length);
    System.out.println("length=" + length + ", " + new String(tmp2));
    assert length == tmp.length;
    assert Arrays.equals(tmp, tmp2);
}
Also used : ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream) ByteBuffer(java.nio.ByteBuffer)

Example 28 with ByteArrayDataOutputStream

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

the class ByteArrayDataInputOutputStreamTest method testUTFWithDoubleByteChar.

public void testUTFWithDoubleByteChar() throws IOException {
    String name = "Bela\234";
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(2);
    out.writeUTF(name);
    assert out.position() == Bits.sizeUTF(name);
    ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
    String tmp = in.readUTF();
    assert name.equals(tmp);
}
Also used : ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 29 with ByteArrayDataOutputStream

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

the class ByteArrayDataInputOutputStreamTest method testUTFWithDoubleByteChar2.

public void testUTFWithDoubleByteChar2() throws IOException {
    String name = "Bela\420";
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(2);
    out.writeUTF(name);
    assert out.position() == Bits.sizeUTF(name);
    ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
    String tmp = in.readUTF();
    assert name.equals(tmp);
    name = "";
    out = new ByteArrayDataOutputStream(2);
    out.writeUTF(name);
    assert out.position() == Bits.sizeUTF(name);
    in = new ByteArrayDataInputStream(out.buffer());
    tmp = in.readUTF();
    assert name.equals(tmp);
    name = null;
    out = new ByteArrayDataOutputStream(2);
    out.writeUTF(name);
    assert out.position() == Bits.sizeUTF(name);
    in = new ByteArrayDataInputStream(out.buffer());
    tmp = in.readUTF();
    assert tmp == null;
}
Also used : ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 30 with ByteArrayDataOutputStream

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

the class ByteArrayDataInputOutputStreamTest method testBoolean.

public void testBoolean() throws Exception {
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(2);
    out.writeBoolean(true);
    out.writeBoolean(false);
    ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
    assert in.readBoolean();
    assert !in.readBoolean();
}
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