Java Utililty Methods ReadableByteChannel Read

List of utility methods to do ReadableByteChannel Read

Description

The list of methods to do ReadableByteChannel Read are organized into topic(s).

Method

voidcopyChannels(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()) {
...
longcopyChannels(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();
...
ByteBufferfill(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;
longgetNextVIntAsLong(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 {
...
ReadableByteChannelinfiniteReadableByteChannelFor(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;
intread(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;
intread(ReadableByteChannel channel, ByteBuffer buffer)
read
int rem = buffer.position();
while (channel.read(buffer) != -1 && buffer.hasRemaining()) {
return buffer.position() - rem;
longread(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;
...
longread(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;
...
intread(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)
...