private final byte[] recvBuffer = new byte[1024 * 8];
@Override
public void onDelivery(Delivery delivery) throws Exception {
Receiver receiver = ((Receiver) delivery.getLink());
if (!delivery.isReadable()) {
LOG.debug("Delivery was not readable!");
return;
}
if (current == null) {
current = new ByteArrayOutputStream();
}
int count;
while ((count = receiver.recv(recvBuffer, 0, recvBuffer.length)) > 0) {
current.write(recvBuffer, 0, count);
}
// Expecting more deliveries..
if (count == 0) {
return;
}
receiver.advance();
Buffer buffer = current.toBuffer();
current = null;
onMessage(receiver, delivery, buffer);
}