private int writeAtMost(byte[] data, int offset, int length)
    {
        if (current >= bufferOffset + buffer.length)
            reBuffer();

        assert current < bufferOffset + buffer.length
                : String.format("File (%s) offset %d, buffer offset %d.", getPath(), current, bufferOffset);


        int toCopy = Math.min(length, buffer.length - bufferCursor());

        // copy bytes from external buffer
        System.arraycopy(data, offset, buffer, bufferCursor(), toCopy);

        assert current <= bufferOffset + buffer.length
                : String.format("File (%s) offset %d, buffer offset %d.", getPath(), current, bufferOffset);

        validBufferBytes = Math.max(validBufferBytes, bufferCursor() + toCopy);
        current += toCopy;

        return toCopy;
    }
private int writeAtMost ( byte [ ] data , int offset , int length ) { if ( current >= bufferOffset + buffer . length ) reBuffer ( ) ; assert current < bufferOffset + buffer . length : String . format ( "File (%s) offset %d, buffer offset %d." , getPath ( ) , current , bufferOffset ) ; int toCopy = Math . min ( length , buffer . length - bufferCursor ( ) ) ; System . arraycopy ( data , offset , buffer , bufferCursor ( ) , toCopy ) ; assert current <= bufferOffset + buffer . length : String . format ( "File (%s) offset %d, buffer offset %d." , getPath ( ) , current , bufferOffset ) ; validBufferBytes = Math . max ( validBufferBytes , bufferCursor ( ) + toCopy ) ; current += toCopy ; return toCopy ; }
/*
Write at most "length" bytes from "data" starting at position "offset", and
return the number of bytes written. caller is responsible for setting
isDirty.