mirror of
https://github.com/xerial/snappy-java.git
synced 2025-07-23 14:04:39 +02:00
Fixes for #100
This commit is contained in:
parent
3fe32512e4
commit
6d9925ba36
@ -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;
|
||||
if(readLen > 0) {
|
||||
Snappy.arrayCopy(array, byteOffset + cursor, readLen, inputBuffer, inputCursor);
|
||||
inputCursor += readLen;
|
||||
}
|
||||
if(inputCursor < blockSize)
|
||||
return;
|
||||
|
||||
compressInput();
|
||||
|
||||
for(int readBytes = 0; readBytes < byteLength; ) {
|
||||
int inputLen = Math.min(blockSize, byteLength - readBytes);
|
||||
if(!hasSufficientOutputBufferFor(inputLen)) {
|
||||
dumpOutput();
|
||||
}
|
||||
int compressedSize = Snappy.rawCompress(array, byteOffset + readBytes, inputLen, outputBuffer, outputCursor + 4);
|
||||
writeInt(outputBuffer, outputCursor, compressedSize);
|
||||
outputCursor += 4 + compressedSize;
|
||||
readBytes += inputLen;
|
||||
cursor += readLen;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user