Fixes issue 17. Applied 0xFF mask when returning int representation of byte data.

This commit is contained in:
Taro L. Saito 2011-06-07 08:43:29 +09:00
parent 712c3f6c2b
commit 578883f1a8
2 changed files with 25 additions and 1 deletions

View File

@ -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())

View File

@ -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);
}
}
}