Here you can find the source of readFully(FileChannel channel, ByteBuffer buffer)
static ByteBuffer readFully(FileChannel channel, ByteBuffer buffer) throws IOException
//package com.java2s; //License from project: Apache License import java.nio.channels.FileChannel; import java.nio.ByteBuffer; import java.nio.BufferUnderflowException; import java.io.IOException; public class Main { static ByteBuffer readFully(FileChannel channel, ByteBuffer buffer) throws IOException { int read = 0; while (buffer.hasRemaining() && read != -1) { read = channel.read(buffer); }/*from w w w . j ava 2 s .co m*/ if (buffer.hasRemaining()) { throw new BufferUnderflowException(); } buffer.flip(); return buffer; } }