Here you can find the source of readFully(FileChannel channel, ByteBuffer dst)
Parameter | Description |
---|---|
channel | the file channel |
dst | the byte buffer |
public static void readFully(FileChannel channel, ByteBuffer dst) throws IOException
//package com.java2s; /*//from www . j ava2 s . c om * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (http://h2database.com/html/license.html). * Initial Developer: H2 Group */ import java.io.EOFException; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class Main { /** * Fully read from the file. This will read all remaining bytes, * or throw an EOFException if not successful. * * @param channel the file channel * @param dst the byte buffer */ public static void readFully(FileChannel channel, ByteBuffer dst) throws IOException { do { int r = channel.read(dst); if (r < 0) { throw new EOFException(); } } while (dst.remaining() > 0); } }