Java ReadableByteChannel Read read(ReadableByteChannel channel, int amount, ByteBuffer dest)

Here you can find the source of read(ReadableByteChannel channel, int amount, ByteBuffer dest)

Description

read

License

Open Source License

Declaration

public static int read(ReadableByteChannel channel, int amount, ByteBuffer dest) throws IOException 

Method Source Code

//package com.java2s;

import java.io.IOException;

import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;

import java.nio.channels.ReadableByteChannel;

public class Main {
    public static int read(ReadableByteChannel channel, int amount, ByteBuffer dest) throws IOException {
        int read = 0;
        int last = 0;
        if (dest.remaining() < amount) {
            throw new BufferOverflowException();
        }/*ww w. java 2  s .  com*/
        while (read < amount && last != -1) {
            last = channel.read(dest);
            if (last != -1)
                read += last;
        }
        return (read == 0 && last == -1) ? -1 : read;
    }
}

Related

  1. infiniteReadableByteChannelFor(ByteBuffer... buffers)
  2. read(ReadableByteChannel channel, ByteBuffer buffer)
  3. read(ReadableByteChannel channel, ByteBuffer buffer)
  4. read(ReadableByteChannel channel, ByteBuffer[] dsts)
  5. read(ReadableByteChannel channel, ByteBuffer[] dsts, int offset, int length)
  6. readAll(ReadableByteChannel ch, ByteBuffer dst)
  7. readAllBytesOrNone(ReadableByteChannel channel, ByteBuffer buffer, int numBytes)
  8. readAnerisHeader(ReadableByteChannel from, ByteBuffer buffer)
  9. readBuffer(ReadableByteChannel chan, ByteBuffer buf)