lz4 / lz4-java

LZ4 compression for Java
Apache License 2.0
1.1k stars 253 forks source link

Small improvement to LZ4BlockInputStream #136

Open oobles opened 5 years ago

oobles commented 5 years ago

While doing some testing I found a bug in my code that was related to how read byte[] will only return to the end of the current decompressed buffer. It was easier in this case to modify the LZ4BlockInputStream to refill and continue to load the buffer. Feel free to integrate if you like.

` @overide

public int read(byte[] b, int off, int len) throws IOException {
    SafeUtils.checkRange(b, off, len);
    if (finished) {
        return -1;
    }
    int bytesRead = 0;
    int remaining = originalLen - o;

    while (len >= remaining) {
        System.arraycopy(buffer, o, b, off, remaining);

        o += remaining;
        len -= remaining;
        off += remaining;
        bytesRead += remaining;

        refill();
        if (finished) {
            return bytesRead;
        }

        remaining = originalLen - o;
    }

    System.arraycopy(buffer, o, b, off, len);
    bytesRead += len;
    o += len;

    return bytesRead;
}

``

odaira commented 5 years ago

Thanks, I'll review your code.