Fix for Unexpected End of PackBits Stream for padded streams.
@@ -71,8 +71,6 @@ public final class PackBitsDecoder implements Decoder {
private final boolean disableNoOp;
private final byte[] sample;
- private int leftOfRun;
- private boolean splitRun;
private boolean reachedEOF;
/** Creates a {@code PackBitsDecoder}. */
@@ -114,43 +112,22 @@ public final class PackBitsDecoder implements Decoder {
* @param buffer a byte array, minimum 128 (or 129 if no-op is disabled) bytes long
* @return The number of bytes decoded
*
- * @throws java.io.IOException
+ * @throws java.io.IOException if a problem occurs during decoding.
*/
public int decode(final InputStream stream, final ByteBuffer buffer) throws IOException {
if (reachedEOF) {
return -1;
}
- // TODO: Don't decode more than single runs, because some writers add pad bytes inside the stream...
- while (buffer.hasRemaining()) {
- int n;
-
- if (splitRun) {
- // Continue run
- n = leftOfRun;
- splitRun = false;
- }
- else {
+ // NOTE: We don't decode more than single runs, because some writers add pad bytes inside the stream...
// Start new run
int b = stream.read();
if (b < 0) {
reachedEOF = true;
- break;
- }
- n = (byte) b;
+ return 0;
}
- // Split run at or before max
- if (n >= 0 && n + 1 > buffer.remaining()) {
- leftOfRun = n;
- splitRun = true;
- break;
- }
- else if (n < 0 && -n + 1 > buffer.remaining()) {
- leftOfRun = n;
- splitRun = true;
- break;
- }
+ int n = (byte) b;
try {
if (n >= 0) {
@@ -173,7 +150,6 @@ public final class PackBitsDecoder implements Decoder {
catch (IndexOutOfBoundsException e) {
throw new DecodeException("Error in PackBits decompression, data seems corrupt", e);
}
- }
return buffer.position();
}
