use of org.jgroups.util.ByteArrayDataOutputStream in project JGroups by belaban.
the class EncryptTest method marshal.
protected static Buffer marshal(final View view) throws Exception {
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(Util.size(view));
out.writeShort(1);
if (view != null)
view.writeTo(out);
return out.getBuffer();
}
use of org.jgroups.util.ByteArrayDataOutputStream 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.ByteArrayDataOutputStream in project JGroups by belaban.
the class BuffersTest method testRead3.
public void testRead3() throws Exception {
byte[] cookie = { 'b', 'e', 'l', 'a' };
IpAddress addr = new IpAddress(7500);
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream();
addr.writeTo(out);
MockSocketChannel ch = new MockSocketChannel().bytesToRead((ByteBuffer) ByteBuffer.allocate(cookie.length + Global.SHORT_SIZE + out.position()).put(cookie).putShort(Version.version).put(out.buffer(), 0, out.position()).flip());
int remaining = ch.bytesToRead().remaining();
ch.bytesToRead().limit(remaining - 10);
Buffers bufs = new Buffers(ByteBuffer.allocate(cookie.length), ByteBuffer.allocate(Global.SHORT_SIZE), ByteBuffer.allocate(out.position()));
boolean rc = bufs.read(ch);
assert !rc;
ch.bytesToRead().limit(remaining - 2);
rc = bufs.read(ch);
assert !rc;
ch.bytesToRead().limit(remaining);
rc = bufs.read(ch);
assert rc;
readCookieVersionAndAddress(bufs, cookie, addr);
}
use of org.jgroups.util.ByteArrayDataOutputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testExpanding2.
public void testExpanding2() {
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(1);
out.write(new byte[] { 'b', 'e', 'l', 'a' });
out = new ByteArrayDataOutputStream(1);
out.writeBoolean(true);
out.writeBoolean(false);
assert out.position() == 2;
out = new ByteArrayDataOutputStream(1);
out.writeShort(22);
out.writeShort(23);
assert out.position() == 4;
out = new ByteArrayDataOutputStream(1);
out.writeInt(23);
out.writeInt(24);
assert out.position() == 8;
}
use of org.jgroups.util.ByteArrayDataOutputStream 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