use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testUnsignedShort.
public void testUnsignedShort() throws IOException {
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(20);
out.writeShort(-22);
out.writeShort(22);
ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
short num = in.readShort();
assert num == -22;
num = in.readShort();
assert num == 22;
in.position(0);
int val = in.readUnsignedShort();
assert val == 65514;
val = in.readUnsignedShort();
assert val == 22;
}
use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testDouble.
public void testDouble() throws IOException {
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(1024);
double[] numbers = { -322649.25, 100.7531, 0.0, 1.5, 2.75, 3.1425, 322649, 322649.75 };
for (double i : numbers) out.writeDouble(i);
ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
for (double i : numbers) {
double num = in.readDouble();
assert num == i;
}
}
use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testInt.
public void testInt() throws IOException {
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(1024);
int[] numbers = { Integer.MIN_VALUE, -322649, -500, 0, 1, 100, 322649, Integer.MAX_VALUE };
for (int i : numbers) out.writeInt(i);
ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
for (int i : numbers) {
int num = in.readInt();
assert num == i;
}
}
use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.
the class ByteArrayDataInputOutputStreamTest method testFloat.
public void testFloat() throws IOException {
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(1024);
float[] numbers = { -322649.25f, 100.7531f, 0f, 1f, 2.75f, 3.1425f, 322649f, 322649.75f };
for (float i : numbers) out.writeFloat(i);
ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer());
for (float i : numbers) {
float num = in.readFloat();
assert num == i;
}
}
use of org.jgroups.util.ByteArrayDataInputStream in project JGroups by belaban.
the class BPING method run.
public void run() {
final byte[] receive_buf = new byte[65535];
DatagramPacket packet = new DatagramPacket(receive_buf, receive_buf.length);
DataInput inp;
while (sock != null && receiver != null && Thread.currentThread().equals(receiver)) {
packet.setData(receive_buf, 0, receive_buf.length);
try {
sock.receive(packet);
inp = new ByteArrayDataInputStream(packet.getData(), packet.getOffset(), packet.getLength());
Message msg = new Message();
msg.readFrom(inp);
up(msg);
} catch (SocketException socketEx) {
break;
} catch (Throwable ex) {
log.error(Util.getMessage("FailedReceivingPacketFrom"), packet.getSocketAddress(), ex);
}
}
if (log.isTraceEnabled())
log.trace("receiver thread terminated");
}
Aggregations