private void copyToTailBuffer(byte[] buf, int ofs, int length) {
        int remaining = tailSize - currentIndex;
        int size1 = Math.min(remaining, length);
        System.arraycopy(buf, ofs, tailBuffer, currentIndex, size1);
        System.arraycopy(buf, ofs + size1, tailBuffer, 0, length - size1);
        currentIndex = (currentIndex + length) % tailSize;
    }
Copies the given buffer into the internal tail buffer at the current
position. This method is called if a buffer is read from the underlying
stream whose length is smaller than the tail buffer. In this case the
tail buffer is only partly overwritten.

@param buf    the buffer
@param ofs    the start offset in the buffer
@param length the number of bytes to be copied
tika-core/src/main/java/org/apache/tika/io/TailStream.java