SnappyInputStream must slide then window when before writing beyond buffer
may be related to
@@ -310,6 +310,7 @@ private int readLiteralLength(final int b) throws IOException {
* @return True if the decompressed data should be flushed
*/
private boolean expandLiteral(final int length) throws IOException {
+ boolean shouldFlush = ensureBufferSpace(length);
final int bytesRead = IOUtils.readFully(in, decompressBuf, writeIndex, length);
count(bytesRead);
if (length != bytesRead) {
@@ -317,7 +318,15 @@ private boolean expandLiteral(final int length) throws IOException {
}
writeIndex += length;
- return writeIndex >= 2 * this.blockSize;
+ return shouldFlush || writeIndex >= 2 * this.blockSize;
+ }
+
+ private boolean ensureBufferSpace(final int length) {
+ if (writeIndex + length >= decompressBuf.length) {
+ slideBuffer();
+ return true;
+ }
+ return false;
}
/**
@@ -344,6 +353,7 @@ private boolean expandCopy(final long off, final int length) throws IOException
throw new IOException("Offset is larger than block size");
}
final int offset = (int) off;
+ boolean shouldFlush = ensureBufferSpace(length);
if (offset == 1) {
final byte lastChar = decompressBuf[writeIndex - 1];
@@ -371,7 +381,7 @@ private boolean expandCopy(final long off, final int length) throws IOException
writeIndex += pad;
}
}
- return writeIndex >= 2 * this.blockSize;
+ return shouldFlush || writeIndex >= 2 * this.blockSize;
}
/**
