mirror of
https://github.com/xerial/snappy-java.git
synced 2025-07-24 22:44:46 +02:00
Sanitize code
This commit is contained in:
parent
7adf0c1dbc
commit
50164bc210
@ -5,6 +5,7 @@ The snappy-java is a Java port of the snappy
|
||||
* Fast compression/decompression tailored to 64-bit CPU architecture.
|
||||
* JNI-based implementation to achieve comparable performance to the native C++ version.
|
||||
* Although snappy-java uses JNI, it can be used safely with multiple class loaders (e.g. Tomcat, etc.).
|
||||
* Supporting compression/decompression of Java primitive arrays (`float[]`, `double[]`, `int[]`, `short[]`, `long[]`, etc.)
|
||||
* Portable across various operating systems; Snappy-java contains native libraries built for Window/Mac/Linux (64-bit). snappy-java loads one of these libraries according to your machine environment (It looks system properties, `os.name` and `os.arch`).
|
||||
* Simple usage. Add the snappy-java-(version).jar file to your classpath. Then call compression/decompression methods in `org.xerial.snappy.Snappy`.
|
||||
* [Framing-format support](http://snappy.googlecode.com/svn/trunk/framing_format.txt) (Since 1.1.0 version)
|
||||
|
@ -74,8 +74,8 @@ public class SnappyOutputStream extends OutputStream {
|
||||
public SnappyOutputStream(OutputStream out, int blockSize) {
|
||||
this.out = out;
|
||||
this.blockSize = Math.max(MIN_BLOCK_SIZE, blockSize);
|
||||
uncompressed = new byte[blockSize];
|
||||
outputBuffer = new byte[SnappyCodec.HEADER_SIZE + 4 + Snappy.maxCompressedLength(blockSize)];
|
||||
uncompressed = new byte[this.blockSize];
|
||||
outputBuffer = new byte[SnappyCodec.HEADER_SIZE + 4 + Snappy.maxCompressedLength(this.blockSize)];
|
||||
outputCursor = SnappyCodec.currentHeader.writeHeader(outputBuffer, 0);
|
||||
}
|
||||
|
||||
@ -261,11 +261,10 @@ public class SnappyOutputStream extends OutputStream {
|
||||
}
|
||||
|
||||
static void writeInt(byte[] dst, int offset, int v) {
|
||||
int p = offset;
|
||||
dst[offset++] = (byte) ((v >> 24) & 0xFF);
|
||||
dst[offset++] = (byte) ((v >> 16) & 0xFF);
|
||||
dst[offset++] = (byte) ((v >> 8) & 0xFF);
|
||||
dst[offset++] = (byte) ((v >> 0) & 0xFF);
|
||||
dst[offset] = (byte) ((v >> 24) & 0xFF);
|
||||
dst[offset+1] = (byte) ((v >> 16) & 0xFF);
|
||||
dst[offset+2] = (byte) ((v >> 8) & 0xFF);
|
||||
dst[offset+3] = (byte) ((v >> 0) & 0xFF);
|
||||
}
|
||||
|
||||
static int readInt(byte[] buffer, int pos) {
|
||||
|
@ -80,7 +80,7 @@ public class SnappyOutputStreamTest
|
||||
@Test
|
||||
public void bufferSize() throws Exception {
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
SnappyOutputStream os = new SnappyOutputStream(b, 500);
|
||||
SnappyOutputStream os = new SnappyOutputStream(b, 1500);
|
||||
final int bytesToWrite = 5000;
|
||||
byte[] orig = new byte[bytesToWrite];
|
||||
for (int i = 0; i < 5000; ++i) {
|
||||
@ -95,6 +95,29 @@ public class SnappyOutputStreamTest
|
||||
is.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smallWrites() throws Exception {
|
||||
|
||||
byte[] orig = CalgaryTest.readFile("alice29.txt");
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
SnappyOutputStream out = new SnappyOutputStream(b);
|
||||
|
||||
for(byte c : orig) {
|
||||
out.write(c);
|
||||
}
|
||||
out.close();
|
||||
|
||||
SnappyInputStream is = new SnappyInputStream(new ByteArrayInputStream(b.toByteArray()));
|
||||
byte[] decompressed = new byte[orig.length];
|
||||
int cursor = 0;
|
||||
int readLen = 0;
|
||||
for(int i=0; i < decompressed.length && (readLen = is.read(decompressed, i, decompressed.length-i)) != -1; ) {
|
||||
i += readLen;
|
||||
}
|
||||
is.close();
|
||||
assertArrayEquals(orig, decompressed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longArrayCompress() throws Exception {
|
||||
long[] l = new long[10];
|
||||
|
Loading…
x
Reference in New Issue
Block a user