Code example for FileChannel

Methods: force, position

0
    { 
        if (syncNeeded)
        { 
            flush(); 
 
            channel.force(true); // true, because file length counts as
                                 // "meta-data" 
 
            if (skipCache)
            { 
                // clear entire file from page cache 
                CLibrary.trySkipCache(this.fd, 0, 0);
 
                minBufferOffset = Long.MAX_VALUE;
                bytesSinceCacheFlush = 0;
            } 
 
            syncNeeded = false;
        } 
    } 
 
    public void flush() throws IOException 
    { 
        if (isDirty)
        { 
            if (channel.position() != bufferOffset)
                channel.position(bufferOffset);
 
            super.write(buffer, 0, validBufferBytes);
 
            if (skipCache)
            {