Fixes issue 33

Applied the patch fixing a bug when reading incomplete stream.
This commit is contained in:
Taro L. Saito 2011-10-05 10:25:51 +09:00
parent 35f7e8edd6
commit 6189b561fa
2 changed files with 10 additions and 6 deletions

View File

@ -1 +1 @@
de487f1ca4da2c24a0beb139440b537221c39890 wiki
718e33e002735cb64943b4dfdb4a31e6a4d8de09 wiki

View File

@ -322,17 +322,21 @@ public class SnappyInputStream extends InputStream
uncompressedCursor = 0;
uncompressedLimit = 0;
int chunkSizeDataLen = in.read(chunkSizeBuf, 0, 4);
if (chunkSizeDataLen < 4) {
finishedReading = true;
return false;
int readBytes = 0;
while (readBytes < 4) {
int ret = in.read(chunkSizeBuf, readBytes, 4 - readBytes);
if (ret == -1) {
finishedReading = true;
return false;
}
readBytes += ret;
}
int chunkSize = SnappyOutputStream.readInt(chunkSizeBuf, 0);
// extend the compressed data buffer size
if (compressed == null || chunkSize > compressed.length) {
compressed = new byte[chunkSize];
}
int readBytes = 0;
readBytes = 0;
while (readBytes < chunkSize) {
int ret = in.read(compressed, readBytes, chunkSize - readBytes);
if (ret == -1)