Java FileChannel Read readFully(FileChannel channel, ByteBuffer buffer)

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

Description

read Fully

License

Apache License

Declaration

static ByteBuffer readFully(FileChannel channel, ByteBuffer buffer) throws IOException 

Method Source Code


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

Related

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