use of org.xnio.channels.BlockingReadableByteChannel in project camel by apache.
the class DefaultUndertowHttpBinding method readFromChannel.
byte[] readFromChannel(StreamSourceChannel source) throws IOException {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final ByteBuffer buffer = ByteBuffer.wrap(new byte[1024]);
ReadableByteChannel blockingSource = new BlockingReadableByteChannel(source);
for (; ; ) {
int res = blockingSource.read(buffer);
if (res == -1) {
return out.toByteArray();
} else if (res == 0) {
LOG.error("Channel did not block");
} else {
buffer.flip();
out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.arrayOffset() + buffer.limit());
buffer.clear();
}
}
}
Aggregations