use of org.jgroups.util.ByteArrayDataOutputStream in project JGroups by belaban.
the class ASYM_ENCRYPT_Test method marshalView.
protected static Buffer marshalView(final View view) throws Exception {
final ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(Global.SHORT_SIZE + view.serializedSize());
out.writeShort(determineFlags(view));
view.writeTo(out);
return out.getBuffer();
}
use of org.jgroups.util.ByteArrayDataOutputStream in project JGroups by belaban.
the class MessageSizeTest method marshal.
private static Buffer marshal(Message msg) throws Exception {
ByteArrayDataOutputStream dos = new ByteArrayDataOutputStream((int) (msg.size() + 50));
Address dest = msg.getDest();
boolean multicast = dest == null;
writeMessage(msg, dos, multicast);
return dos.getBuffer();
}
use of org.jgroups.util.ByteArrayDataOutputStream in project JGroups by belaban.
the class BuffersTest method testRead2.
public void testRead2() 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());
Buffers bufs = new Buffers(ByteBuffer.allocate(cookie.length), ByteBuffer.allocate(Global.SHORT_SIZE), ByteBuffer.allocate(out.position()));
boolean 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 testCompressedLong.
public void testCompressedLong() throws IOException {
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(1024);
long[] numbers = { Long.MIN_VALUE, -500, 0, 1, 100, Long.MAX_VALUE };
for (long i : numbers) Bits.writeLong(i, out);
ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
for (long i : numbers) {
long num = Bits.readLong(in);
assert num == i;
}
}
use of org.jgroups.util.ByteArrayDataOutputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testUnsignedByte.
public void testUnsignedByte() throws IOException {
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(20);
byte[] bytes = { -100, -50, 0, 1, 100, 127 };
for (byte b : bytes) out.writeByte(b);
ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
for (byte b : bytes) {
int tmp = in.readUnsignedByte();
assert tmp == (b & 0xff);
}
}
Aggregations