This commit is contained in:
Taro L. Saito 2015-04-14 15:43:50 +09:00
parent 3fe32512e4
commit 6d9925ba36
2 changed files with 12 additions and 18 deletions

View File

@ -231,25 +231,19 @@ public class SnappyOutputStream extends OutputStream {
* @throws IOException
*/
public void rawWrite(Object array, int byteOffset, int byteLength) throws IOException {
if(inputCursor + byteLength < blockSize) {
int cursor = 0;
while(cursor < byteLength) {
int readLen = Math.min(byteLength - cursor, blockSize - inputCursor);
// copy the input data to uncompressed buffer
Snappy.arrayCopy(array, byteOffset, byteLength, inputBuffer, inputCursor);
inputCursor += byteLength;
return;
}
compressInput();
for(int readBytes = 0; readBytes < byteLength; ) {
int inputLen = Math.min(blockSize, byteLength - readBytes);
if(!hasSufficientOutputBufferFor(inputLen)) {
dumpOutput();
if(readLen > 0) {
Snappy.arrayCopy(array, byteOffset + cursor, readLen, inputBuffer, inputCursor);
inputCursor += readLen;
}
int compressedSize = Snappy.rawCompress(array, byteOffset + readBytes, inputLen, outputBuffer, outputCursor + 4);
writeInt(outputBuffer, outputCursor, compressedSize);
outputCursor += 4 + compressedSize;
readBytes += inputLen;
if(inputCursor < blockSize)
return;
compressInput();
cursor += readLen;
}
}

View File

@ -152,7 +152,7 @@ public class SnappyOutputStreamTest
int[] chunkSizes = new int[] { 1, 100, 1023, 1024, 10000};
for (int chunkSize : chunkSizes) {
byte[] compressedData = compressAsChunks(orig, chunkSize);
assertEquals(expectedCompressedData.length, compressedData.length);
assertEquals(String.format("when chunk size = %,d", chunkSize), expectedCompressedData.length, compressedData.length);
assertArrayEquals(expectedCompressedData, compressedData);
}
}