diff options
Diffstat (limited to 'java/org/brotli/wrapper/dec')
-rw-r--r-- | java/org/brotli/wrapper/dec/BrotliInputStream.java | 11 | ||||
-rw-r--r-- | java/org/brotli/wrapper/dec/Decoder.java | 6 |
2 files changed, 16 insertions, 1 deletions
diff --git a/java/org/brotli/wrapper/dec/BrotliInputStream.java b/java/org/brotli/wrapper/dec/BrotliInputStream.java index 76bcf1d..26f7a82 100644 --- a/java/org/brotli/wrapper/dec/BrotliInputStream.java +++ b/java/org/brotli/wrapper/dec/BrotliInputStream.java @@ -53,7 +53,16 @@ public class BrotliInputStream extends InputStream { if (decoder.closed) { throw new IOException("read after close"); } - if (decoder.decode() == -1) { + int decoded; + // Iterate until at leat one byte is decoded, or EOF reached. + while (true) { + decoded = decoder.decode(); + if (decoded != 0) { + break; + } + } + + if (decoded == -1) { return -1; } return decoder.buffer.get() & 0xFF; diff --git a/java/org/brotli/wrapper/dec/Decoder.java b/java/org/brotli/wrapper/dec/Decoder.java index 0326403..548c14d 100644 --- a/java/org/brotli/wrapper/dec/Decoder.java +++ b/java/org/brotli/wrapper/dec/Decoder.java @@ -15,6 +15,7 @@ import java.util.ArrayList; * Base class for InputStream / Channel implementations. */ public class Decoder { + private static final ByteBuffer EMPTY_BUFER = ByteBuffer.allocate(0); private final ReadableByteChannel source; private final DecoderJNI.Wrapper decoder; ByteBuffer buffer; @@ -87,6 +88,11 @@ public class Decoder { if (bytesRead == -1) { fail("unexpected end of input"); } + if (bytesRead == 0) { + // No input data is currently available. + buffer = EMPTY_BUFER; + return 0; + } decoder.push(bytesRead); break; |