change snappyOutputStream writeHeader order to fix when outputStream… (#229)

* change snappyOutputStream  writeHeader order to fix when outputStream doest't write bytes, it will also generate a snappy header after closed
This commit is contained in:
Neil 2019-03-26 11:59:24 +08:00 committed by Taro L. Saito
parent de99182a82
commit 79697cf3d4
1 changed files with 3 additions and 7 deletions

View File

@ -365,22 +365,18 @@ public class SnappyOutputStream
protected void compressInput() protected void compressInput()
throws IOException throws IOException
{ {
if (inputCursor <= 0) {
return; // no need to dump
}
if (!headerWritten) { if (!headerWritten) {
outputCursor = writeHeader(); outputCursor = writeHeader();
headerWritten = true; headerWritten = true;
} }
if (inputCursor <= 0) {
return; // no need to dump
}
// Compress and dump the buffer content // Compress and dump the buffer content
if (!hasSufficientOutputBufferFor(inputCursor)) { if (!hasSufficientOutputBufferFor(inputCursor)) {
dumpOutput(); dumpOutput();
} }
writeBlockPreemble(); writeBlockPreemble();
int compressedSize = Snappy.compress(inputBuffer, 0, inputCursor, outputBuffer, outputCursor + 4); int compressedSize = Snappy.compress(inputBuffer, 0, inputCursor, outputBuffer, outputCursor + 4);
// Write compressed data size // Write compressed data size
writeInt(outputBuffer, outputCursor, compressedSize); writeInt(outputBuffer, outputCursor, compressedSize);