mirror of
https://github.com/xerial/snappy-java.git
synced 2025-07-22 21:44:31 +02:00
Fixes issue 17. Applied 0xFF mask when returning int representation of byte data.
This commit is contained in:
parent
712c3f6c2b
commit
578883f1a8
@ -176,7 +176,7 @@ public class SnappyInputStream extends InputStream
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
if (uncompressedCursor < uncompressedLimit) {
|
||||
return uncompressed[uncompressedCursor++];
|
||||
return uncompressed[uncompressedCursor++] & 0xFF;
|
||||
}
|
||||
else {
|
||||
if (hasNextChunk())
|
||||
|
@ -91,4 +91,28 @@ public class CalgaryTest
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void byteWiseRead() throws Exception {
|
||||
for (String f : files) {
|
||||
byte[] orig = readFile("testdata/calgary/" + f);
|
||||
|
||||
ByteArrayOutputStream compressedBuf = new ByteArrayOutputStream();
|
||||
SnappyOutputStream out = new SnappyOutputStream(compressedBuf);
|
||||
out.write(orig);
|
||||
out.close();
|
||||
|
||||
SnappyInputStream in = new SnappyInputStream(new ByteArrayInputStream(compressedBuf.toByteArray()));
|
||||
byte[] uncompressed = new byte[orig.length];
|
||||
int cursor = 0;
|
||||
for (;;) {
|
||||
int b = in.read();
|
||||
if (b == -1)
|
||||
break;
|
||||
uncompressed[cursor++] = (byte) b;
|
||||
}
|
||||
assertEquals(orig.length, cursor);
|
||||
assertArrayEquals(orig, uncompressed);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user