MCPcopy Index your code
hub / github.com/google/brotli / decompress

Method decompress

java/org/brotli/wrapper/dec/Decoder.java:143–190  ·  view source on GitHub ↗

Decodes the given data buffer starting at offset till length.

(byte[] data, int offset, int length)

Source from the content-addressed store, hash-verified

141
142 /** Decodes the given data buffer starting at offset till length. */
143 public static byte[] decompress(byte[] data, int offset, int length) throws IOException {
144 ArrayList<byte[]> output = new ArrayList<>();
145 int totalOutputSize = 0;
146 DecoderJNI.Wrapper decoder = new DecoderJNI.Wrapper(length);
147 try {
148 decoder.getInputBuffer().put(data, offset, length);
149 decoder.push(length);
150 while (decoder.getStatus() != DecoderJNI.Status.DONE) {
151 switch (decoder.getStatus()) {
152 case OK:
153 decoder.push(0);
154 break;
155
156 case NEEDS_MORE_OUTPUT:
157 ByteBuffer buffer = decoder.pull();
158 byte[] chunk = new byte[buffer.remaining()];
159 buffer.get(chunk);
160 output.add(chunk);
161 totalOutputSize += chunk.length;
162 break;
163
164 case NEEDS_MORE_INPUT:
165 // Give decoder a chance to process the remaining of the buffered byte.
166 decoder.push(0);
167 // If decoder still needs input, this means that stream is truncated.
168 if (decoder.getStatus() == DecoderJNI.Status.NEEDS_MORE_INPUT) {
169 throw new IOException("corrupted input");
170 }
171 break;
172
173 default:
174 throw new IOException("corrupted input");
175 }
176 }
177 } finally {
178 decoder.destroy();
179 }
180 if (output.size() == 1) {
181 return output.get(0);
182 }
183 byte[] result = new byte[totalOutputSize];
184 int resultOffset = 0;
185 for (byte[] chunk : output) {
186 System.arraycopy(chunk, 0, result, resultOffset, chunk.length);
187 resultOffset += chunk.length;
188 }
189 return result;
190 }
191
192 /** Decodes the given data buffer. */
193 public static byte[] decompress(byte[] data) throws IOException {

Callers 10

deepThoughtMethod · 0.95
testPowerOfTwoInputMethod · 0.95
testInputOffsetMethod · 0.95
runMethod · 0.95
testEmptyInputMethod · 0.95
mainFunction · 0.45
_check_decompressionMethod · 0.45
_decompressMethod · 0.45
test_garbage_appendedMethod · 0.45
_check_decompressionMethod · 0.45

Calls 6

getInputBufferMethod · 0.95
pushMethod · 0.95
getStatusMethod · 0.95
pullMethod · 0.95
destroyMethod · 0.95
addMethod · 0.80

Tested by 8

testPowerOfTwoInputMethod · 0.76
testInputOffsetMethod · 0.76
runMethod · 0.76
testEmptyInputMethod · 0.76
_check_decompressionMethod · 0.36
_decompressMethod · 0.36
test_garbage_appendedMethod · 0.36
_check_decompressionMethod · 0.36