Java Utililty Methods FileChannel Read

List of utility methods to do FileChannel Read

Description

The list of methods to do FileChannel Read are organized into topic(s).

Method

ByteBufferreadFully(FileChannel channel, ByteBuffer buffer)
read Fully
int read = 0;
while (buffer.hasRemaining() && read != -1) {
    read = channel.read(buffer);
if (buffer.hasRemaining()) {
    throw new BufferUnderflowException();
buffer.flip();
...
voidreadFully(FileChannel channel, ByteBuffer buffer, long ptr)
Reads as much as possible from the channel into the buffer.
while (buffer.remaining() > 0) {
    long read = channel.read(buffer, ptr);
    if (read == -1) {
        throw new EOFException();
    } else {
        ptr += read;
voidreadFully(FileChannel channel, ByteBuffer dst)
Fully read from the file.
do {
    int r = channel.read(dst);
    if (r < 0) {
        throw new EOFException();
} while (dst.remaining() > 0);
voidreadFully(FileChannel channel, long offset, ByteBuffer buf)
read Fully
int remaining = buf.limit() - buf.position();
while (remaining > 0) {
    int read = channel.read(buf, offset);
    if (read < 0)
        throw new EOFException();
    remaining -= read;
voidreadFully(FileChannel fileChannel, long filePosition, ByteBuffer buffer)
read Fully
int startBufferPosition = buffer.position();
while (buffer.remaining() > 0 && buffer.position() < fileChannel.size()) {
    int bytesRead = fileChannel.read(buffer, filePosition + buffer.position() - startBufferPosition);
    if (bytesRead == -1)
        break;