Here you can find the source of readFromChannel(FileChannel fc, ByteBuffer buffer, int bufferOffset, int num)
public static void readFromChannel(FileChannel fc, ByteBuffer buffer, int bufferOffset, int num) throws IOException, EOFException
//package com.java2s; /*// w w w . j av a 2 s .co m Copyright ? 2010-2011, Nitin Verma (project owner for XADisk https://xadisk.dev.java.net/). All rights reserved. This source code is being made available to the public under the terms specified in the license "Eclipse Public License 1.0" located at http://www.opensource.org/licenses/eclipse-1.0.php. */ import java.io.EOFException; import java.io.IOException; import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class Main { public static void readFromChannel(FileChannel fc, ByteBuffer buffer, int bufferOffset, int num) throws IOException, EOFException { buffer.position(bufferOffset); if (buffer.remaining() < num) { throw new BufferUnderflowException(); } buffer.limit(bufferOffset + num); int numRead = 0; int t = 0; while (numRead < num) { t = fc.read(buffer); if (t == -1) { throw new EOFException(); } numRead += t; } } }