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