mirror of
https://github.com/xerial/snappy-java.git
synced 2025-07-24 22:44:46 +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
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void rawWrite(Object array, int byteOffset, int byteLength) throws IOException {
|
public void rawWrite(Object array, int byteOffset, int byteLength) throws IOException {
|
||||||
|
int cursor = 0;
|
||||||
if(inputCursor + byteLength < blockSize) {
|
while(cursor < byteLength) {
|
||||||
|
int readLen = Math.min(byteLength - cursor, blockSize - inputCursor);
|
||||||
// copy the input data to uncompressed buffer
|
// copy the input data to uncompressed buffer
|
||||||
Snappy.arrayCopy(array, byteOffset, byteLength, inputBuffer, inputCursor);
|
if(readLen > 0) {
|
||||||
inputCursor += byteLength;
|
Snappy.arrayCopy(array, byteOffset + cursor, readLen, inputBuffer, inputCursor);
|
||||||
return;
|
inputCursor += readLen;
|
||||||
}
|
}
|
||||||
|
if(inputCursor < blockSize)
|
||||||
|
return;
|
||||||
|
|
||||||
compressInput();
|
compressInput();
|
||||||
|
cursor += readLen;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ public class SnappyOutputStreamTest
|
|||||||
int[] chunkSizes = new int[] { 1, 100, 1023, 1024, 10000};
|
int[] chunkSizes = new int[] { 1, 100, 1023, 1024, 10000};
|
||||||
for (int chunkSize : chunkSizes) {
|
for (int chunkSize : chunkSizes) {
|
||||||
byte[] compressedData = compressAsChunks(orig, chunkSize);
|
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);
|
assertArrayEquals(expectedCompressedData, compressedData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user