Here you can find the source of readFromChannel(ReadableByteChannel channel, ByteBuffer buffer)
public static int readFromChannel(ReadableByteChannel channel, ByteBuffer buffer) throws IOException
//package com.java2s; /**/*from www. j a v a 2 s. c om*/ * This class is part of JCodec ( www.jcodec.org ) This software is distributed * under FreeBSD License * * @author The JCodec project * */ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.ReadableByteChannel; public class Main { public static int readFromChannel(ReadableByteChannel channel, ByteBuffer buffer) throws IOException { int rem = buffer.position(); while (channel.read(buffer) != -1 && buffer.hasRemaining()) ; return buffer.position() - rem; } public static final ByteBuffer read(ByteBuffer buffer, int count) { ByteBuffer slice = buffer.duplicate(); int limit = buffer.position() + count; slice.limit(limit); buffer.position(limit); return slice; } public static ByteBuffer duplicate(ByteBuffer bb) { ByteBuffer out = ByteBuffer.allocate(bb.remaining()); out.put(bb.duplicate()); out.flip(); return out; } }