Java ByteBuffer Set readFromChannel(FileChannel fc, ByteBuffer buffer, int bufferOffset, int num)

Here you can find the source of readFromChannel(FileChannel fc, ByteBuffer buffer, int bufferOffset, int num)

Description

read From Channel

License

Open Source License

Declaration

public static void readFromChannel(FileChannel fc, ByteBuffer buffer, int bufferOffset, int num)
            throws IOException, EOFException 

Method Source Code


//package com.java2s;
/*//  w  w w  .  j av  a 2 s .co  m
Copyright ? 2010-2011, Nitin Verma (project owner for XADisk https://xadisk.dev.java.net/). All rights reserved.
    
This source code is being made available to the public under the terms specified in the license
"Eclipse Public License 1.0" located at http://www.opensource.org/licenses/eclipse-1.0.php.
 */

import java.io.EOFException;

import java.io.IOException;

import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Main {
    public static void readFromChannel(FileChannel fc, ByteBuffer buffer, int bufferOffset, int num)
            throws IOException, EOFException {
        buffer.position(bufferOffset);
        if (buffer.remaining() < num) {
            throw new BufferUnderflowException();
        }
        buffer.limit(bufferOffset + num);
        int numRead = 0;
        int t = 0;
        while (numRead < num) {
            t = fc.read(buffer);
            if (t == -1) {
                throw new EOFException();
            }
            numRead += t;
        }
    }
}

Related

  1. parseToByteBuffer(Object value)
  2. pourBufferToArray(ByteBuffer source, byte[] destination, int offset, int sizeRequested)
  3. readBitset(ByteBuffer bb, int numbytes)
  4. readBitSet(ByteBuffer buf, int len)
  5. readBlock(ByteBuffer buffer, String fileName, long startOffset, Logger log)
  6. readKey(ByteBuffer index, int indexByteOffset, byte[] foundKey)
  7. readPackageName(ByteBuffer buffer, int offset)
  8. redByteArray(ByteBuffer buffer, int offset, int length)
  9. redInteger1(ByteBuffer buffer, int _offset)