Search in sources :

Example 21 with ByteArrayDataInputStream

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

the class ByteArrayDataInputOutputStreamTest method testReadLine.

public static void testReadLine() throws IOException {
    String str = "Gallia est omnis divisa in partes tres,\n\rquarum unam incolunt Belgae,\naliam Aquitani," + "\ntertiam qui ipsorum lingua Celtae, nostra Galli appellantur";
    byte[] buf = str.getBytes();
    ByteArrayDataInputStream in = new ByteArrayDataInputStream(buf);
    List<String> lines = new ArrayList<>(4);
    String line;
    while ((line = in.readLine()) != null) {
        System.out.println(line);
        lines.add(line);
    }
    assert lines.size() == 4;
}
Also used : ArrayList(java.util.ArrayList) ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream)

Example 22 with ByteArrayDataInputStream

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

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

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

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

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