public static final byte[] read(ReadableByteChannel ch, int length) throws IOException
    {
        ByteBuffer bb = ByteBuffer.allocate(length);
        readAll(ch, bb);
        if (bb.hasRemaining())
        {
            throw new EOFException("couldn't read "+length+" bytes");
        }
        return bb.array();
    }
public static final byte [ ] read ( ReadableByteChannel ch , int length ) throws IOException { ByteBuffer bb = ByteBuffer . allocate ( length ) ; readAll ( ch , bb ) ; if ( bb . hasRemaining ( ) ) { throw new EOFException ( "couldn't read " + length + " bytes" ) ; } return bb . array ( ) ; }
Read length bytes from channel.
Throws EOFException if couldn't read length bytes because of eof.
@param ch
@param length
@return
@throws IOException