Java ReadableByteChannel Read readFromChannel(ReadableByteChannel channel, ByteBuffer buffer)

Here you can find the source of readFromChannel(ReadableByteChannel channel, ByteBuffer buffer)

Description

read From Channel

License

BSD License

Declaration

public static int readFromChannel(ReadableByteChannel channel, ByteBuffer buffer) throws IOException 

Method Source Code

//package com.java2s;
/**/*from www. j a  v  a  2 s.  c om*/
 * This class is part of JCodec ( www.jcodec.org ) This software is distributed
 * under FreeBSD License
 * 
 * @author The JCodec project
 * 
 */

import java.io.IOException;

import java.nio.ByteBuffer;

import java.nio.channels.ReadableByteChannel;

public class Main {
    public static int readFromChannel(ReadableByteChannel channel, ByteBuffer buffer) throws IOException {
        int rem = buffer.position();
        while (channel.read(buffer) != -1 && buffer.hasRemaining())
            ;
        return buffer.position() - rem;
    }

    public static final ByteBuffer read(ByteBuffer buffer, int count) {
        ByteBuffer slice = buffer.duplicate();
        int limit = buffer.position() + count;
        slice.limit(limit);
        buffer.position(limit);
        return slice;
    }

    public static ByteBuffer duplicate(ByteBuffer bb) {
        ByteBuffer out = ByteBuffer.allocate(bb.remaining());
        out.put(bb.duplicate());
        out.flip();
        return out;
    }
}

Related

  1. readAllBytesOrNone(ReadableByteChannel channel, ByteBuffer buffer, int numBytes)
  2. readAnerisHeader(ReadableByteChannel from, ByteBuffer buffer)
  3. readBuffer(ReadableByteChannel chan, ByteBuffer buf)
  4. readCharArray(ReadableByteChannel channel, ByteBuffer buffer, char[] charArray)
  5. readFromAnerisChannel(ReadableByteChannel chan, ByteBuffer buffer)
  6. readFull(ReadableByteChannel ch, ByteBuffer dst)
  7. readFully(final ReadableByteChannel channel, final ByteBuffer buf)
  8. readFully(final ReadableByteChannel channel, final ByteBuffer buf)
  9. readFully(ReadableByteChannel channel, ByteBuffer b)