Code example for FileChannel

Methods: position, read, size

0
    @Override 
    public int readinto(ByteBuffer buf) {
        checkClosed(); 
        checkReadable(); 
        try { 
            return fileChannel.read(buf);
        } catch (IOException ioe) {
            throw Py.IOError(ioe);
        } 
    } 
 
    /** 
     * Read bytes into each of the specified ByteBuffers via scatter 
     * i/o. 
     * 
     * @param bufs {@inheritDoc} 
     * @return {@inheritDoc} 
     */ 
    @Override 
    public long readinto(ByteBuffer[] bufs) {
        checkClosed(); 
        checkReadable(); 
        try { 
            return fileChannel.read(bufs);
        } catch (IOException ioe) {
            throw Py.IOError(ioe);
        } 
    } 
 
    /** 
     * Read until EOF with one readinto() call. 
     * 
     * Takes advantage of the fact that the underlying file's size is 
     * available. 
     * 
     * @return {@inheritDoc} 
     */ 
    @Override 
    public ByteBuffer readall() {
        checkClosed(); 
        checkReadable(); 
        // NOTE: This could be less accurate than multiple reads if 
        // the file is growing 
        long toRead;
        try { 
            toRead = Math.max(0, fileChannel.size() - fileChannel.position());
        } catch (IOException ioe) {
            throw Py.IOError(ioe);
        } 
 
        if (toRead > Integer.MAX_VALUE) {