private int doRead(final byte[] b, final int off, final int len) throws IOException {
        int readLen = len;

        if ((windowPos + len) > windowByteEnd) {
            readLen = (int) (windowByteEnd - windowPos);
            if (readLen == 0) {
                return -1;
            }
        }

        final int totalBytesRead = data.read(b, off, readLen);
        windowPos += totalBytesRead;
        return totalBytesRead;
    }
Do a read keeping a watch on the end window.
stroom-data/stroom-data-store-impl-fs/src/main/java/stroom/data/store/impl/fs/RASegmentInputStream.java