Apache Solr open-source search software
LUCENE-6140: simplify inflater usage in CompressionMode
Robert Muir7529b4bd5bc3
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressionMode.java b/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressionMode.javaindex ebd547de23f..f98a93a30f1 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressionMode.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/compressing/CompressionMode.java@@ -201,9 +201,7 @@ public abstract class CompressionMode {// pad with extra "dummy byte": see javadocs for using Inflater(true)// we do it for compliance, but it's unnecessary for years in zlib.final int paddedLength = compressedLength + 1;- if (paddedLength > compressed.length) {- compressed = new byte[ArrayUtil.oversize(paddedLength, 1)];- }+ compressed = ArrayUtil.grow(compressed, paddedLength);in.readBytes(compressed, 0, compressedLength);compressed[compressedLength] = 0; // explicitly set dummy byte to 0@@ -212,20 +210,15 @@ public abstract class CompressionMode {decompressor.setInput(compressed, 0, paddedLength);bytes.offset = bytes.length = 0;- while (true) {- final int count;- try {- final int remaining = bytes.bytes.length - bytes.length;- count = decompressor.inflate(bytes.bytes, bytes.length, remaining);- } catch (DataFormatException e) {- throw new IOException(e);- }- bytes.length += count;- if (decompressor.finished()) {- break;- } else {- bytes.bytes = ArrayUtil.grow(bytes.bytes);- }+ bytes.bytes = ArrayUtil.grow(bytes.bytes, originalLength);+ try {+ bytes.length = decompressor.inflate(bytes.bytes, bytes.length, originalLength);+ } catch (DataFormatException e) {+ throw new IOException(e);+ }+ if (!decompressor.finished()) {+ throw new CorruptIndexException("Invalid decoder state: needsInput=" + decompressor.needsInput()+ + ", needsDict=" + decompressor.needsDictionary(), in);}if (bytes.length != originalLength) {throw new CorruptIndexException("Lengths mismatch: " + bytes.length + " != " + originalLength, in);