Here you can find the source of readFully(FileChannel channel, ByteBuffer buffer, long ptr)
Parameter | Description |
---|---|
channel | The channel. |
buffer | The buffer. |
ptr | The initial position in the channel. |
Parameter | Description |
---|---|
IOException | if an I/O error occurs. |
EOFException | if the end of the file was reached and the buffercould not be completely populated. |
public static void readFully(FileChannel channel, ByteBuffer buffer, long ptr) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.EOFException; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class Main { /**/*from ww w .j a v a 2 s . co m*/ * Reads as much as possible from the channel into the buffer. * @param channel The channel. * @param buffer The buffer. * @param ptr The initial position in the channel. * @throws IOException if an I/O error occurs. * @throws EOFException if the end of the file was reached and the buffer * could not be completely populated. */ public static void readFully(FileChannel channel, ByteBuffer buffer, long ptr) throws IOException { while (buffer.remaining() > 0) { long read = channel.read(buffer, ptr); if (read == -1) { throw new EOFException(); } else { ptr += read; } } } }