List of utility methods to do ReadableByteChannel Read
void | copyChannels(ReadableByteChannel in, WritableByteChannel out) copy Channels ByteBuffer buf = ByteBuffer.allocate(16 * 1024); while (in.read(buf) != -1) { buf.flip(); out.write(buf); buf.compact(); buf.flip(); while (buf.hasRemaining()) { ... |
long | copyChannels(ReadableByteChannel input, WritableByteChannel output, int bufferSize) copy Channels ByteBuffer buffer = ByteBuffer.allocateDirect(bufferSize); long count = 0; while (input.read(buffer) != -1) { buffer.flip(); count += output.write(buffer); buffer.compact(); buffer.flip(); ... |
ByteBuffer | fill(ReadableByteChannel in, ByteBuffer buffer) Fills the provided buffer it with bytes from the provided channel. while (buffer.hasRemaining()) if (in.read(buffer) == -1) throw new BufferUnderflowException(); buffer.flip(); return buffer; |
long | getNextVIntAsLong(ByteBuffer buffer, ReadableByteChannel readChannel) get Next V Int As Long if (buffer == null) { buffer = ByteBuffer.allocate(1); readChannel.read(buffer); byte firstByte; if (buffer.hasRemaining()) { firstByte = buffer.get(); } else { ... |
ReadableByteChannel | infiniteReadableByteChannelFor(ByteBuffer... buffers) Creates a ReadableByteChannel for a given list of ByteBuffers that does not report the end of the stream int totalSize = 0; for (ByteBuffer buffer : buffers) { totalSize += buffer.remaining(); final ByteBuffer assembledBuffer = ByteBuffer.allocate(totalSize); for (ByteBuffer buffer : buffers) { assembledBuffer.put(buffer); assembledBuffer.rewind(); ReadableByteChannel wrappedChannel = new ReadableByteChannel() { public int read(ByteBuffer dst) throws IOException { int bytesRead = Math.min(assembledBuffer.capacity() - assembledBuffer.position(), dst.remaining()); assembledBuffer.limit(assembledBuffer.position() + bytesRead); dst.put(assembledBuffer); return bytesRead; public void close() throws IOException { public boolean isOpen() { return true; }; return wrappedChannel; |
int | read(ReadableByteChannel channel, ByteBuffer buffer) read int count = channel.read(buffer); if (count == -1) throw new EOFException("Received -1 when reading from channel, socket has likely been closed."); return count; |
int | read(ReadableByteChannel channel, ByteBuffer buffer) read int rem = buffer.position(); while (channel.read(buffer) != -1 && buffer.hasRemaining()) { return buffer.position() - rem; |
long | read(ReadableByteChannel channel, ByteBuffer[] dsts) read if (channel instanceof ScatteringByteChannel) { ScatteringByteChannel sbc = (ScatteringByteChannel) channel; return sbc.read(dsts); long totalBytesRead = -1; for (ByteBuffer buf : dsts) { if (!buf.hasRemaining()) { continue; ... |
long | read(ReadableByteChannel channel, ByteBuffer[] dsts, int offset, int length) ScatteringChannel support long res = 0; for (int ii = 0; ii < length; ii++) { ByteBuffer bb = dsts[ii + offset]; if (bb.hasRemaining()) { int rc = channel.read(bb); if (rc == -1) { if (res == 0) { return -1; ... |
int | read(ReadableByteChannel channel, int amount, ByteBuffer dest) read int read = 0; int last = 0; if (dest.remaining() < amount) { throw new BufferOverflowException(); while (read < amount && last != -1) { last = channel.read(dest); if (last != -1) ... |