Fixes issue 13
This commit is contained in:
parent
c739342412
commit
6771e58b46
|
@ -79,7 +79,7 @@ Mac-i386_SNAPPY_FLAGS :=
|
|||
Mac-x86_64_CXX := g++ -arch $(OS_ARCH)
|
||||
Mac-x86_64_STRIP := strip -x
|
||||
Mac-x86_64_CXXFLAGS := -I$(JAVA_HOME)/include -O2 -fPIC
|
||||
Mac-x86_64_LINKFLAGS := -dynamiclib
|
||||
Mac-x86_64_LINKFLAGS := -dynamiclib -static-libgcc
|
||||
Mac-x86_64_LIBNAME := libsnappy.jnilib
|
||||
Mac-x86_64_SNAPPY_FLAGS :=
|
||||
|
||||
|
|
|
@ -36,8 +36,8 @@ import java.io.InputStream;
|
|||
*/
|
||||
public class SnappyInputStream extends InputStream
|
||||
{
|
||||
protected final InputStream in;
|
||||
private boolean finishedReading = false;
|
||||
protected final InputStream in;
|
||||
private int blockSize = SnappyOutputStream.DEFAULT_BLOCK_SIZE;
|
||||
|
||||
private byte[] compressed;
|
||||
|
@ -60,6 +60,8 @@ public class SnappyInputStream extends InputStream
|
|||
protected void readHeader() throws IOException {
|
||||
byte[] header = new byte[SnappyCodec.headerSize()];
|
||||
int readBytes = in.read(header, 0, header.length);
|
||||
|
||||
// Quick test of the header
|
||||
if (header[0] != SnappyCodec.MAGIC_HEADER[0]) {
|
||||
// do the default uncompression
|
||||
readFully(header, readBytes);
|
||||
|
@ -123,7 +125,7 @@ public class SnappyInputStream extends InputStream
|
|||
return writtenBytes == 0 ? -1 : writtenBytes;
|
||||
}
|
||||
}
|
||||
int bytesToWrite = Math.min(uncompressedLimit - uncompressedCursor, len);
|
||||
int bytesToWrite = Math.min(uncompressedLimit - uncompressedCursor, len - writtenBytes);
|
||||
System.arraycopy(uncompressed, uncompressedCursor, b, off + writtenBytes, bytesToWrite);
|
||||
writtenBytes += bytesToWrite;
|
||||
uncompressedCursor += bytesToWrite;
|
||||
|
|
|
@ -31,8 +31,8 @@ import java.io.OutputStream;
|
|||
* This class implements a stream filter for writing compressed data using
|
||||
* Snappy.
|
||||
*
|
||||
* The input data is blocked into 32KB size, and each block is compressed and
|
||||
* then passed to the given {@link OutputStream}.
|
||||
* The input data is blocked into 4 MB size (in default), and each block is
|
||||
* compressed and then passed to the given {@link OutputStream}.
|
||||
*
|
||||
* The output data format is a sequence of (compressed chunk size, compressed
|
||||
* data chunk binary...) pair.
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -27,6 +27,7 @@ package org.xerial.snappy;
|
|||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@ -76,4 +77,22 @@ public class SnappyOutputStreamTest
|
|||
assertArrayEquals(orig.toByteArray(), decompressed.toByteArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bufferSize() throws Exception {
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
SnappyOutputStream os = new SnappyOutputStream(b, 500);
|
||||
final int bytesToWrite = 5000;
|
||||
byte[] orig = new byte[bytesToWrite];
|
||||
for (int i = 0; i < 5000; ++i) {
|
||||
byte v = (byte) (i % 128);
|
||||
orig[i] = v;
|
||||
os.write(v);
|
||||
}
|
||||
os.close();
|
||||
SnappyInputStream is = new SnappyInputStream(new ByteArrayInputStream(b.toByteArray()));
|
||||
byte[] buf = new byte[bytesToWrite / 101];
|
||||
while (is.read(buf) != -1) {}
|
||||
is.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue