use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.
the class MessageTest method testReadFromSkipPayloadNullPayload.
public static void testReadFromSkipPayloadNullPayload() throws Exception {
Message msg = new Message(Util.createRandomAddress("A")).src(Util.createRandomAddress("B"));
addHeaders(msg);
byte[] buf = Util.streamableToByteBuffer(msg);
// ExposedByteArrayInputStream input=new ExposedByteArrayInputStream(buf);
// DataInput in=new DataInputStream(input);
ByteArrayDataInputStream in = new ByteArrayDataInputStream(buf);
Message msg2 = new Message(false);
int payload_position = msg2.readFromSkipPayload(in);
if (payload_position >= 0)
msg2.setBuffer(buf, payload_position, buf.length - payload_position);
assert msg2.getOffset() == 0;
assert msg2.getLength() == msg.getLength();
assert msg.getRawBuffer() == null;
assert msg2.getRawBuffer() == null;
assert msg.getBuffer() == null;
assert msg2.getBuffer() == null;
assert msg2.size() == msg.size();
Message copy = msg2.copy();
assert copy.getOffset() == 0;
assert copy.getLength() == msg.getLength();
assert copy.getRawBuffer() == null;
assert copy.getBuffer() == null;
assert copy.size() == msg2.size();
}
use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.
the class IpAddressTest method testStreamable.
public void testStreamable() throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream oos = new DataOutputStream(bos);
byte[] buf = null;
ByteArrayInputStream bis = null;
DataInputStream ois;
IpAddress a2, b2, x, x2, y, y2;
x = createStackConformantAddress(5555);
y = createStackConformantAddress(1111);
a.writeTo(oos);
b.writeTo(oos);
x.writeTo(oos);
y.writeTo(oos);
buf = bos.toByteArray();
bis = new ByteArrayInputStream(buf);
ois = new DataInputStream(bis);
a2 = new IpAddress();
a2.readFrom(ois);
b2 = new IpAddress();
b2.readFrom(ois);
x2 = new IpAddress();
x2.readFrom(ois);
y2 = new IpAddress();
y2.readFrom(ois);
Assert.assertEquals(a, a2);
Assert.assertEquals(b, b2);
assert y2.getIpAddress() != null;
Assert.assertEquals(1111, y2.getPort());
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream();
j.writeTo(out);
k.writeTo(out);
ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer(), 0, out.position());
IpAddressUUID tmp = new IpAddressUUID();
tmp.readFrom(in);
assert tmp.equals(j);
tmp = new IpAddressUUID();
tmp.readFrom(in);
assert tmp.equals(k);
}
use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testReadFully.
public void testReadFully() {
byte[] name = "Bela".getBytes();
ByteArrayDataInputStream in = new ByteArrayDataInputStream(name);
byte[] buf = new byte[10];
int read = in.read(buf, 0, buf.length);
assert read == 4;
assert in.position() == 4;
in.position(0);
try {
in.readFully(buf, 0, buf.length);
assert false : "readFully() should have thrown an EOFException";
} catch (Exception eof_ex) {
System.out.println("got exception as expected: " + eof_ex);
assert eof_ex instanceof EOFException;
}
}
use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testLimit.
public void testLimit() {
byte[] buf = new byte[100];
buf[0] = 'B';
buf[1] = 'e';
buf[2] = 'l';
buf[3] = 'a';
ByteArrayDataInputStream in = new ByteArrayDataInputStream(buf);
assert in.position() == 0;
assert in.limit() == buf.length;
assert in.capacity() == buf.length;
in = new ByteArrayDataInputStream(buf, 0, 4);
assert in.position() == 0;
assert in.limit() == 4;
assert in.capacity() == buf.length;
byte[] tmp = new byte[4];
in.read(tmp, 0, tmp.length);
assert "Bela".equals(new String(tmp));
}
use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testChar.
public void testChar() throws IOException {
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(1024);
for (int i = 0; i < 500; i++) {
int ch = 'a' + i;
out.writeChar(ch);
}
ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
for (int i = 0; i < 500; i++) {
char ch = in.readChar();
assert ch == 'a' + i;
}
}
Aggregations