Java FileChannel Read readFully(FileChannel channel, ByteBuffer dst)

Here you can find the source of readFully(FileChannel channel, ByteBuffer dst)

Description

Fully read from the file.

License

Mozilla Public License

Parameter

Parameter Description
channel the file channel
dst the byte buffer

Declaration

public static void readFully(FileChannel channel, ByteBuffer dst) throws IOException 

Method Source Code

//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);
    }
}

Related

  1. readFully(FileChannel channel, ByteBuffer buffer)
  2. readFully(FileChannel channel, ByteBuffer buffer, long ptr)
  3. readFully(FileChannel channel, long offset, ByteBuffer buf)
  4. readFully(FileChannel fileChannel, long filePosition, ByteBuffer buffer)