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;
}
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);
}
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);
}
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);
}
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;
}
Aggregations