Search in sources :

Example 1 with ByteArrayDataOutputStream

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();
}
Also used : ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 2 with ByteArrayDataOutputStream

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();
}
Also used : Address(org.jgroups.Address) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 3 with ByteArrayDataOutputStream

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);
}
Also used : MockSocketChannel(org.jgroups.nio.MockSocketChannel) IpAddress(org.jgroups.stack.IpAddress) Buffers(org.jgroups.nio.Buffers) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 4 with ByteArrayDataOutputStream

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;
    }
}
Also used : ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 5 with ByteArrayDataOutputStream

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);
    }
}
Also used : ByteArrayDataInputStream(org.jgroups.util.ByteArrayDataInputStream) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Aggregations

ByteArrayDataOutputStream (org.jgroups.util.ByteArrayDataOutputStream)33 ByteArrayDataInputStream (org.jgroups.util.ByteArrayDataInputStream)19 IpAddress (org.jgroups.stack.IpAddress)3 Buffers (org.jgroups.nio.Buffers)2 MockSocketChannel (org.jgroups.nio.MockSocketChannel)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 DatagramPacket (java.net.DatagramPacket)1 SocketException (java.net.SocketException)1 UnknownHostException (java.net.UnknownHostException)1 ByteBuffer (java.nio.ByteBuffer)1 Address (org.jgroups.Address)1 IpAddressUUID (org.jgroups.stack.IpAddressUUID)1