mirror of
https://github.com/xerial/snappy-java.git
synced 2025-07-23 14:04:39 +02:00
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_CXX := g++ -arch $(OS_ARCH)
|
||||||
Mac-x86_64_STRIP := strip -x
|
Mac-x86_64_STRIP := strip -x
|
||||||
Mac-x86_64_CXXFLAGS := -I$(JAVA_HOME)/include -O2 -fPIC
|
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_LIBNAME := libsnappy.jnilib
|
||||||
Mac-x86_64_SNAPPY_FLAGS :=
|
Mac-x86_64_SNAPPY_FLAGS :=
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ import java.io.InputStream;
|
|||||||
*/
|
*/
|
||||||
public class SnappyInputStream extends InputStream
|
public class SnappyInputStream extends InputStream
|
||||||
{
|
{
|
||||||
protected final InputStream in;
|
|
||||||
private boolean finishedReading = false;
|
private boolean finishedReading = false;
|
||||||
|
protected final InputStream in;
|
||||||
private int blockSize = SnappyOutputStream.DEFAULT_BLOCK_SIZE;
|
private int blockSize = SnappyOutputStream.DEFAULT_BLOCK_SIZE;
|
||||||
|
|
||||||
private byte[] compressed;
|
private byte[] compressed;
|
||||||
@ -60,6 +60,8 @@ public class SnappyInputStream extends InputStream
|
|||||||
protected void readHeader() throws IOException {
|
protected void readHeader() throws IOException {
|
||||||
byte[] header = new byte[SnappyCodec.headerSize()];
|
byte[] header = new byte[SnappyCodec.headerSize()];
|
||||||
int readBytes = in.read(header, 0, header.length);
|
int readBytes = in.read(header, 0, header.length);
|
||||||
|
|
||||||
|
// Quick test of the header
|
||||||
if (header[0] != SnappyCodec.MAGIC_HEADER[0]) {
|
if (header[0] != SnappyCodec.MAGIC_HEADER[0]) {
|
||||||
// do the default uncompression
|
// do the default uncompression
|
||||||
readFully(header, readBytes);
|
readFully(header, readBytes);
|
||||||
@ -123,7 +125,7 @@ public class SnappyInputStream extends InputStream
|
|||||||
return writtenBytes == 0 ? -1 : writtenBytes;
|
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);
|
System.arraycopy(uncompressed, uncompressedCursor, b, off + writtenBytes, bytesToWrite);
|
||||||
writtenBytes += bytesToWrite;
|
writtenBytes += bytesToWrite;
|
||||||
uncompressedCursor += bytesToWrite;
|
uncompressedCursor += bytesToWrite;
|
||||||
|
@ -31,8 +31,8 @@ import java.io.OutputStream;
|
|||||||
* This class implements a stream filter for writing compressed data using
|
* This class implements a stream filter for writing compressed data using
|
||||||
* Snappy.
|
* Snappy.
|
||||||
*
|
*
|
||||||
* The input data is blocked into 32KB size, and each block is compressed and
|
* The input data is blocked into 4 MB size (in default), and each block is
|
||||||
* then passed to the given {@link OutputStream}.
|
* compressed and then passed to the given {@link OutputStream}.
|
||||||
*
|
*
|
||||||
* The output data format is a sequence of (compressed chunk size, compressed
|
* The output data format is a sequence of (compressed chunk size, compressed
|
||||||
* data chunk binary...) pair.
|
* 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 static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -76,4 +77,22 @@ public class SnappyOutputStreamTest
|
|||||||
assertArrayEquals(orig.toByteArray(), decompressed.toByteArray());
|
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…
x
Reference in New Issue
Block a user