1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
package org.apache.tools.bzip2; |
25 |
|
|
26 |
|
import java.io.IOException; |
27 |
|
import java.io.InputStream; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
@link |
35 |
|
|
36 |
|
@link |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@link |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
|
|
| 0% |
Uncovered Elements: 702 (702) |
Complexity: 153 |
Complexity Density: 0.33 |
|
46 |
|
public class CBZip2InputStream extends InputStream implements BZip2Constants { |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
private int last; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
private int origPtr; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
private int blockSize100k; |
63 |
|
|
64 |
|
private boolean blockRandomised; |
65 |
|
|
66 |
|
private int bsBuff; |
67 |
|
private int bsLive; |
68 |
|
private final CRC crc = new CRC(); |
69 |
|
|
70 |
|
private int nInUse; |
71 |
|
|
72 |
|
private InputStream in; |
73 |
|
private final boolean decompressConcatenated; |
74 |
|
|
75 |
|
private int currentChar = -1; |
76 |
|
|
77 |
|
private static final int EOF = 0; |
78 |
|
private static final int START_BLOCK_STATE = 1; |
79 |
|
private static final int RAND_PART_A_STATE = 2; |
80 |
|
private static final int RAND_PART_B_STATE = 3; |
81 |
|
private static final int RAND_PART_C_STATE = 4; |
82 |
|
private static final int NO_RAND_PART_A_STATE = 5; |
83 |
|
private static final int NO_RAND_PART_B_STATE = 6; |
84 |
|
private static final int NO_RAND_PART_C_STATE = 7; |
85 |
|
|
86 |
|
private int currentState = START_BLOCK_STATE; |
87 |
|
|
88 |
|
private int storedBlockCRC, storedCombinedCRC; |
89 |
|
private int computedBlockCRC, computedCombinedCRC; |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
private int su_count; |
94 |
|
private int su_ch2; |
95 |
|
private int su_chPrev; |
96 |
|
private int su_i2; |
97 |
|
private int su_j2; |
98 |
|
private int su_rNToGo; |
99 |
|
private int su_rTPos; |
100 |
|
private int su_tPos; |
101 |
|
private char su_z; |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
private CBZip2InputStream.Data data; |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
@param |
120 |
|
|
121 |
|
@throws |
122 |
|
|
123 |
|
@throws |
124 |
|
|
125 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
126 |
0 |
public CBZip2InputStream(final InputStream in) throws IOException {... |
127 |
0 |
this(in, false); |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
@param |
141 |
|
@param |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
@throws |
148 |
|
|
149 |
|
@throws |
150 |
|
|
151 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
152 |
0 |
public CBZip2InputStream(final InputStream in,... |
153 |
|
final boolean decompressConcatenated) |
154 |
|
throws IOException { |
155 |
0 |
super(); |
156 |
|
|
157 |
0 |
this.in = in; |
158 |
0 |
this.decompressConcatenated = decompressConcatenated; |
159 |
|
|
160 |
0 |
init(true); |
161 |
0 |
initBlock(); |
162 |
0 |
setupBlock(); |
163 |
|
} |
164 |
|
|
165 |
|
@inheritDoc |
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
166 |
0 |
@Override... |
167 |
|
public int read() throws IOException { |
168 |
0 |
if (this.in == null) |
169 |
0 |
throw new IOException("stream closed"); |
170 |
0 |
return read0(); |
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
@see |
177 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 8 |
Complexity Density: 0.62 |
|
178 |
0 |
@Override... |
179 |
|
public int read(final byte[] dest, final int offs, final int len) |
180 |
|
throws IOException { |
181 |
0 |
if (offs < 0) { |
182 |
0 |
throw new IndexOutOfBoundsException("offs(" + offs + ") < 0."); |
183 |
|
} |
184 |
0 |
if (len < 0) { |
185 |
0 |
throw new IndexOutOfBoundsException("len(" + len + ") < 0."); |
186 |
|
} |
187 |
0 |
if (offs + len > dest.length) { |
188 |
0 |
throw new IndexOutOfBoundsException("offs(" + offs + ") + len(" |
189 |
|
+ len + ") > dest.length(" |
190 |
|
+ dest.length + ")."); |
191 |
|
} |
192 |
0 |
if (this.in == null) { |
193 |
0 |
throw new IOException("stream closed"); |
194 |
|
} |
195 |
|
|
196 |
0 |
final int hi = offs + len; |
197 |
0 |
int destOffs = offs; |
198 |
0 |
for (int b; (destOffs < hi) && ((b = read0()) >= 0);) { |
199 |
0 |
dest[destOffs++] = (byte) b; |
200 |
|
} |
201 |
|
|
202 |
0 |
return (destOffs == offs) ? -1 : (destOffs - offs); |
203 |
|
} |
204 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
205 |
0 |
private void makeMaps() {... |
206 |
0 |
final boolean[] inUse = this.data.inUse; |
207 |
0 |
final byte[] seqToUnseq = this.data.seqToUnseq; |
208 |
|
|
209 |
0 |
int nInUseShadow = 0; |
210 |
|
|
211 |
0 |
for (int i = 0; i < 256; i++) { |
212 |
0 |
if (inUse[i]) { |
213 |
0 |
seqToUnseq[nInUseShadow++] = (byte) i; |
214 |
|
} |
215 |
|
} |
216 |
|
|
217 |
0 |
this.nInUse = nInUseShadow; |
218 |
|
} |
219 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 9 |
Complexity Density: 0.36 |
|
220 |
0 |
private int read0() throws IOException {... |
221 |
0 |
final int retChar = this.currentChar; |
222 |
|
|
223 |
0 |
switch (this.currentState) { |
224 |
0 |
case EOF: |
225 |
0 |
return -1; |
226 |
|
|
227 |
0 |
case START_BLOCK_STATE: |
228 |
0 |
throw new IllegalStateException(); |
229 |
|
|
230 |
0 |
case RAND_PART_A_STATE: |
231 |
0 |
throw new IllegalStateException(); |
232 |
|
|
233 |
0 |
case RAND_PART_B_STATE: |
234 |
0 |
setupRandPartB(); |
235 |
0 |
break; |
236 |
|
|
237 |
0 |
case RAND_PART_C_STATE: |
238 |
0 |
setupRandPartC(); |
239 |
0 |
break; |
240 |
|
|
241 |
0 |
case NO_RAND_PART_A_STATE: |
242 |
0 |
throw new IllegalStateException(); |
243 |
|
|
244 |
0 |
case NO_RAND_PART_B_STATE: |
245 |
0 |
setupNoRandPartB(); |
246 |
0 |
break; |
247 |
|
|
248 |
0 |
case NO_RAND_PART_C_STATE: |
249 |
0 |
setupNoRandPartC(); |
250 |
0 |
break; |
251 |
|
|
252 |
0 |
default: |
253 |
0 |
throw new IllegalStateException(); |
254 |
|
} |
255 |
|
|
256 |
0 |
return retChar; |
257 |
|
} |
258 |
|
|
|
|
| 0% |
Uncovered Elements: 37 (37) |
Complexity: 11 |
Complexity Density: 0.52 |
|
259 |
0 |
private boolean init(boolean isFirstStream) throws IOException {... |
260 |
0 |
if (null == in) { |
261 |
0 |
throw new IOException("No InputStream"); |
262 |
|
} |
263 |
|
|
264 |
0 |
if (isFirstStream) { |
265 |
0 |
if (in.available() == 0) { |
266 |
0 |
throw new IOException("Empty InputStream"); |
267 |
|
} |
268 |
|
} else { |
269 |
0 |
int magic0 = read(); |
270 |
0 |
if (magic0 == -1) { |
271 |
0 |
return false; |
272 |
|
} |
273 |
0 |
int magic1 = read(); |
274 |
0 |
if (magic0 != 'B' || magic1 != 'Z') { |
275 |
0 |
throw new IOException("Garbage after a valid BZip2 stream"); |
276 |
|
} |
277 |
|
} |
278 |
|
|
279 |
0 |
int magic2 = read(); |
280 |
0 |
if (magic2 != 'h') { |
281 |
0 |
throw new IOException(isFirstStream |
282 |
|
? "Stream is not in the BZip2 format" |
283 |
|
: "Garbage after a valid BZip2 stream"); |
284 |
|
} |
285 |
|
|
286 |
0 |
int blockSize = read(); |
287 |
0 |
if ((blockSize < '1') || (blockSize > '9')) { |
288 |
0 |
throw new IOException("Stream is not BZip2 formatted: illegal " |
289 |
|
+ "blocksize " + (char) blockSize); |
290 |
|
} |
291 |
|
|
292 |
0 |
this.blockSize100k = blockSize - '0'; |
293 |
|
|
294 |
0 |
this.bsLive = 0; |
295 |
0 |
this.computedCombinedCRC = 0; |
296 |
|
|
297 |
0 |
return true; |
298 |
|
} |
299 |
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 15 |
Complexity Density: 0.56 |
|
300 |
0 |
private void initBlock() throws IOException {... |
301 |
0 |
char magic0; |
302 |
0 |
char magic1; |
303 |
0 |
char magic2; |
304 |
0 |
char magic3; |
305 |
0 |
char magic4; |
306 |
0 |
char magic5; |
307 |
|
|
308 |
0 |
while (true) { |
309 |
|
|
310 |
0 |
magic0 = bsGetUByte(); |
311 |
0 |
magic1 = bsGetUByte(); |
312 |
0 |
magic2 = bsGetUByte(); |
313 |
0 |
magic3 = bsGetUByte(); |
314 |
0 |
magic4 = bsGetUByte(); |
315 |
0 |
magic5 = bsGetUByte(); |
316 |
|
|
317 |
|
|
318 |
0 |
if (magic0 != 0x17 || magic1 != 0x72 || magic2 != 0x45 || magic3 != 0x38 |
319 |
|
|| magic4 != 0x50 || magic5 != 0x90) { |
320 |
0 |
break; |
321 |
|
} |
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
0 |
if (complete()) { |
327 |
0 |
return; |
328 |
|
} |
329 |
|
} |
330 |
|
|
331 |
0 |
if (magic0 != 0x31 || |
332 |
|
magic1 != 0x41 || |
333 |
|
magic2 != 0x59 || |
334 |
|
magic3 != 0x26 || |
335 |
|
magic4 != 0x53 || |
336 |
|
magic5 != 0x59 |
337 |
|
) { |
338 |
0 |
this.currentState = EOF; |
339 |
0 |
throw new IOException("bad block header"); |
340 |
|
} |
341 |
0 |
this.storedBlockCRC = bsGetInt(); |
342 |
0 |
this.blockRandomised = bsR(1) == 1; |
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
0 |
if (this.data == null) { |
349 |
0 |
this.data = new Data(this.blockSize100k); |
350 |
|
} |
351 |
|
|
352 |
|
|
353 |
0 |
getAndMoveToFrontDecode(); |
354 |
|
|
355 |
0 |
this.crc.initialiseCRC(); |
356 |
0 |
this.currentState = START_BLOCK_STATE; |
357 |
|
} |
358 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
359 |
0 |
private void endBlock() throws IOException {... |
360 |
0 |
this.computedBlockCRC = this.crc.getFinalCRC(); |
361 |
|
|
362 |
|
|
363 |
0 |
if (this.storedBlockCRC != this.computedBlockCRC) { |
364 |
|
|
365 |
|
|
366 |
0 |
this.computedCombinedCRC |
367 |
|
= (this.storedCombinedCRC << 1) |
368 |
|
| (this.storedCombinedCRC >>> 31); |
369 |
0 |
this.computedCombinedCRC ^= this.storedBlockCRC; |
370 |
|
|
371 |
0 |
reportCRCError(); |
372 |
|
} |
373 |
|
|
374 |
0 |
this.computedCombinedCRC |
375 |
|
= (this.computedCombinedCRC << 1) |
376 |
|
| (this.computedCombinedCRC >>> 31); |
377 |
0 |
this.computedCombinedCRC ^= this.computedBlockCRC; |
378 |
|
} |
379 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
380 |
0 |
private boolean complete() throws IOException {... |
381 |
0 |
this.storedCombinedCRC = bsGetInt(); |
382 |
0 |
this.currentState = EOF; |
383 |
0 |
this.data = null; |
384 |
|
|
385 |
0 |
if (this.storedCombinedCRC != this.computedCombinedCRC) { |
386 |
0 |
reportCRCError(); |
387 |
|
} |
388 |
|
|
389 |
|
|
390 |
|
|
391 |
0 |
return !decompressConcatenated || !init(false); |
392 |
|
} |
393 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
394 |
0 |
@Override... |
395 |
|
public void close() throws IOException { |
396 |
0 |
InputStream inShadow = this.in; |
397 |
0 |
if (inShadow != null) { |
398 |
0 |
try { |
399 |
0 |
if (inShadow != System.in) { |
400 |
0 |
inShadow.close(); |
401 |
|
} |
402 |
|
} finally { |
403 |
0 |
this.data = null; |
404 |
0 |
this.in = null; |
405 |
|
} |
406 |
|
} |
407 |
|
} |
408 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 4 |
Complexity Density: 0.31 |
|
409 |
0 |
private int bsR(final int n) throws IOException {... |
410 |
0 |
int bsLiveShadow = this.bsLive; |
411 |
0 |
int bsBuffShadow = this.bsBuff; |
412 |
|
|
413 |
0 |
if (bsLiveShadow < n) { |
414 |
0 |
final InputStream inShadow = this.in; |
415 |
0 |
do { |
416 |
0 |
int thech = read(); |
417 |
|
|
418 |
0 |
if (thech < 0) { |
419 |
0 |
throw new IOException("unexpected end of stream"); |
420 |
|
} |
421 |
|
|
422 |
0 |
bsBuffShadow = (bsBuffShadow << 8) | thech; |
423 |
0 |
bsLiveShadow += 8; |
424 |
0 |
} while (bsLiveShadow < n); |
425 |
|
|
426 |
0 |
this.bsBuff = bsBuffShadow; |
427 |
|
} |
428 |
|
|
429 |
0 |
this.bsLive = bsLiveShadow - n; |
430 |
0 |
return (bsBuffShadow >> (bsLiveShadow - n)) & ((1 << n) - 1); |
431 |
|
} |
432 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
433 |
0 |
private boolean bsGetBit() throws IOException {... |
434 |
0 |
int bsLiveShadow = this.bsLive; |
435 |
0 |
int bsBuffShadow = this.bsBuff; |
436 |
|
|
437 |
0 |
if (bsLiveShadow < 1) { |
438 |
0 |
int thech = read(); |
439 |
|
|
440 |
0 |
if (thech < 0) { |
441 |
0 |
throw new IOException("unexpected end of stream"); |
442 |
|
} |
443 |
|
|
444 |
0 |
bsBuffShadow = (bsBuffShadow << 8) | thech; |
445 |
0 |
bsLiveShadow += 8; |
446 |
0 |
this.bsBuff = bsBuffShadow; |
447 |
|
} |
448 |
|
|
449 |
0 |
this.bsLive = bsLiveShadow - 1; |
450 |
0 |
return ((bsBuffShadow >> (bsLiveShadow - 1)) & 1) != 0; |
451 |
|
} |
452 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
453 |
0 |
private char bsGetUByte() throws IOException {... |
454 |
0 |
return (char) bsR(8); |
455 |
|
} |
456 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
457 |
0 |
private int bsGetInt() throws IOException {... |
458 |
0 |
return (((((bsR(8) << 8) | bsR(8)) << 8) | bsR(8)) << 8) | bsR(8); |
459 |
|
} |
460 |
|
|
461 |
|
|
462 |
|
|
463 |
|
@param |
464 |
|
@param |
465 |
|
@param |
466 |
|
@param |
467 |
|
@param |
468 |
|
@param |
469 |
|
@param |
470 |
|
|
|
|
| 0% |
Uncovered Elements: 36 (36) |
Complexity: 9 |
Complexity Density: 0.45 |
|
471 |
0 |
private static void hbCreateDecodeTables(final int[] limit,... |
472 |
|
final int[] base, |
473 |
|
final int[] perm, |
474 |
|
final char[] length, |
475 |
|
final int minLen, |
476 |
|
final int maxLen, |
477 |
|
final int alphaSize) { |
478 |
0 |
for (int i = minLen, pp = 0; i <= maxLen; i++) { |
479 |
0 |
for (int j = 0; j < alphaSize; j++) { |
480 |
0 |
if (length[j] == i) { |
481 |
0 |
perm[pp++] = j; |
482 |
|
} |
483 |
|
} |
484 |
|
} |
485 |
|
|
486 |
0 |
for (int i = MAX_CODE_LEN; --i > 0;) { |
487 |
0 |
base[i] = 0; |
488 |
0 |
limit[i] = 0; |
489 |
|
} |
490 |
|
|
491 |
0 |
for (int i = 0; i < alphaSize; i++) { |
492 |
0 |
base[length[i] + 1]++; |
493 |
|
} |
494 |
|
|
495 |
0 |
for (int i = 1, b = base[0]; i < MAX_CODE_LEN; i++) { |
496 |
0 |
b += base[i]; |
497 |
0 |
base[i] = b; |
498 |
|
} |
499 |
|
|
500 |
0 |
for (int i = minLen, vec = 0, b = base[i]; i <= maxLen; i++) { |
501 |
0 |
final int nb = base[i + 1]; |
502 |
0 |
vec += nb - b; |
503 |
0 |
b = nb; |
504 |
0 |
limit[i] = vec - 1; |
505 |
0 |
vec <<= 1; |
506 |
|
} |
507 |
|
|
508 |
0 |
for (int i = minLen + 1; i <= maxLen; i++) { |
509 |
0 |
base[i] = ((limit[i - 1] + 1) << 1) - base[i]; |
510 |
|
} |
511 |
|
} |
512 |
|
|
|
|
| 0% |
Uncovered Elements: 77 (77) |
Complexity: 17 |
Complexity Density: 0.38 |
|
513 |
0 |
private void recvDecodingTables() throws IOException {... |
514 |
0 |
final Data dataShadow = this.data; |
515 |
0 |
final boolean[] inUse = dataShadow.inUse; |
516 |
0 |
final byte[] pos = dataShadow.recvDecodingTables_pos; |
517 |
0 |
final byte[] selector = dataShadow.selector; |
518 |
0 |
final byte[] selectorMtf = dataShadow.selectorMtf; |
519 |
|
|
520 |
0 |
int inUse16 = 0; |
521 |
|
|
522 |
|
|
523 |
0 |
for (int i = 0; i < 16; i++) { |
524 |
0 |
if (bsGetBit()) { |
525 |
0 |
inUse16 |= 1 << i; |
526 |
|
} |
527 |
|
} |
528 |
|
|
529 |
0 |
for (int i = 256; --i >= 0;) { |
530 |
0 |
inUse[i] = false; |
531 |
|
} |
532 |
|
|
533 |
0 |
for (int i = 0; i < 16; i++) { |
534 |
0 |
if ((inUse16 & (1 << i)) != 0) { |
535 |
0 |
final int i16 = i << 4; |
536 |
0 |
for (int j = 0; j < 16; j++) { |
537 |
0 |
if (bsGetBit()) { |
538 |
0 |
inUse[i16 + j] = true; |
539 |
|
} |
540 |
|
} |
541 |
|
} |
542 |
|
} |
543 |
|
|
544 |
0 |
makeMaps(); |
545 |
0 |
final int alphaSize = this.nInUse + 2; |
546 |
|
|
547 |
|
|
548 |
0 |
final int nGroups = bsR(3); |
549 |
0 |
final int nSelectors = bsR(15); |
550 |
|
|
551 |
0 |
for (int i = 0; i < nSelectors; i++) { |
552 |
0 |
int j = 0; |
553 |
0 |
while (bsGetBit()) { |
554 |
0 |
j++; |
555 |
|
} |
556 |
0 |
selectorMtf[i] = (byte) j; |
557 |
|
} |
558 |
|
|
559 |
|
|
560 |
0 |
for (int v = nGroups; --v >= 0;) { |
561 |
0 |
pos[v] = (byte) v; |
562 |
|
} |
563 |
|
|
564 |
0 |
for (int i = 0; i < nSelectors; i++) { |
565 |
0 |
int v = selectorMtf[i] & 0xff; |
566 |
0 |
final byte tmp = pos[v]; |
567 |
0 |
while (v > 0) { |
568 |
|
|
569 |
0 |
pos[v] = pos[v - 1]; |
570 |
0 |
v--; |
571 |
|
} |
572 |
0 |
pos[0] = tmp; |
573 |
0 |
selector[i] = tmp; |
574 |
|
} |
575 |
|
|
576 |
0 |
final char[][] len = dataShadow.temp_charArray2d; |
577 |
|
|
578 |
|
|
579 |
0 |
for (int t = 0; t < nGroups; t++) { |
580 |
0 |
int curr = bsR(5); |
581 |
0 |
final char[] len_t = len[t]; |
582 |
0 |
for (int i = 0; i < alphaSize; i++) { |
583 |
0 |
while (bsGetBit()) { |
584 |
0 |
curr += bsGetBit() ? -1 : 1; |
585 |
|
} |
586 |
0 |
len_t[i] = (char) curr; |
587 |
|
} |
588 |
|
} |
589 |
|
|
590 |
|
|
591 |
0 |
createHuffmanDecodingTables(alphaSize, nGroups); |
592 |
|
} |
593 |
|
|
594 |
|
|
595 |
|
|
596 |
|
@param |
597 |
|
@param |
598 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 5 |
Complexity Density: 0.28 |
|
599 |
0 |
private void createHuffmanDecodingTables(final int alphaSize,... |
600 |
|
final int nGroups) { |
601 |
0 |
final Data dataShadow = this.data; |
602 |
0 |
final char[][] len = dataShadow.temp_charArray2d; |
603 |
0 |
final int[] minLens = dataShadow.minLens; |
604 |
0 |
final int[][] limit = dataShadow.limit; |
605 |
0 |
final int[][] base = dataShadow.base; |
606 |
0 |
final int[][] perm = dataShadow.perm; |
607 |
|
|
608 |
0 |
for (int t = 0; t < nGroups; t++) { |
609 |
0 |
int minLen = 32; |
610 |
0 |
int maxLen = 0; |
611 |
0 |
final char[] len_t = len[t]; |
612 |
0 |
for (int i = alphaSize; --i >= 0;) { |
613 |
0 |
final char lent = len_t[i]; |
614 |
0 |
if (lent > maxLen) { |
615 |
0 |
maxLen = lent; |
616 |
|
} |
617 |
0 |
if (lent < minLen) { |
618 |
0 |
minLen = lent; |
619 |
|
} |
620 |
|
} |
621 |
0 |
hbCreateDecodeTables(limit[t], base[t], perm[t], len[t], minLen, |
622 |
|
maxLen, alphaSize); |
623 |
0 |
minLens[t] = minLen; |
624 |
|
} |
625 |
|
} |
626 |
|
|
|
|
| 0% |
Uncovered Elements: 161 (161) |
Complexity: 24 |
Complexity Density: 0.21 |
|
627 |
0 |
private void getAndMoveToFrontDecode() throws IOException {... |
628 |
0 |
this.origPtr = bsR(24); |
629 |
0 |
recvDecodingTables(); |
630 |
|
|
631 |
0 |
final InputStream inShadow = this.in; |
632 |
0 |
final Data dataShadow = this.data; |
633 |
0 |
final byte[] ll8 = dataShadow.ll8; |
634 |
0 |
final int[] unzftab = dataShadow.unzftab; |
635 |
0 |
final byte[] selector = dataShadow.selector; |
636 |
0 |
final byte[] seqToUnseq = dataShadow.seqToUnseq; |
637 |
0 |
final char[] yy = dataShadow.getAndMoveToFrontDecode_yy; |
638 |
0 |
final int[] minLens = dataShadow.minLens; |
639 |
0 |
final int[][] limit = dataShadow.limit; |
640 |
0 |
final int[][] base = dataShadow.base; |
641 |
0 |
final int[][] perm = dataShadow.perm; |
642 |
0 |
final int limitLast = this.blockSize100k * 100000; |
643 |
|
|
644 |
|
|
645 |
|
|
646 |
|
|
647 |
|
|
648 |
|
|
649 |
|
|
650 |
0 |
for (int i = 256; --i >= 0;) { |
651 |
0 |
yy[i] = (char) i; |
652 |
0 |
unzftab[i] = 0; |
653 |
|
} |
654 |
|
|
655 |
0 |
int groupNo = 0; |
656 |
0 |
int groupPos = G_SIZE - 1; |
657 |
0 |
final int eob = this.nInUse + 1; |
658 |
0 |
int nextSym = getAndMoveToFrontDecode0(0); |
659 |
0 |
int bsBuffShadow = this.bsBuff; |
660 |
0 |
int bsLiveShadow = this.bsLive; |
661 |
0 |
int lastShadow = -1; |
662 |
0 |
int zt = selector[groupNo] & 0xff; |
663 |
0 |
int[] base_zt = base[zt]; |
664 |
0 |
int[] limit_zt = limit[zt]; |
665 |
0 |
int[] perm_zt = perm[zt]; |
666 |
0 |
int minLens_zt = minLens[zt]; |
667 |
|
|
668 |
0 |
while (nextSym != eob) { |
669 |
0 |
if ((nextSym == RUNA) || (nextSym == RUNB)) { |
670 |
0 |
int s = -1; |
671 |
|
|
672 |
0 |
for (int n = 1; true; n <<= 1) { |
673 |
0 |
if (nextSym == RUNA) { |
674 |
0 |
s += n; |
675 |
0 |
} else if (nextSym == RUNB) { |
676 |
0 |
s += n << 1; |
677 |
|
} else { |
678 |
0 |
break; |
679 |
|
} |
680 |
|
|
681 |
0 |
if (groupPos == 0) { |
682 |
0 |
groupPos = G_SIZE - 1; |
683 |
0 |
zt = selector[++groupNo] & 0xff; |
684 |
0 |
base_zt = base[zt]; |
685 |
0 |
limit_zt = limit[zt]; |
686 |
0 |
perm_zt = perm[zt]; |
687 |
0 |
minLens_zt = minLens[zt]; |
688 |
|
} else { |
689 |
0 |
groupPos--; |
690 |
|
} |
691 |
|
|
692 |
0 |
int zn = minLens_zt; |
693 |
|
|
694 |
|
|
695 |
|
|
696 |
0 |
while (bsLiveShadow < zn) { |
697 |
0 |
final int thech = read(); |
698 |
0 |
if (thech < 0) |
699 |
0 |
throw new IOException("unexpected end of stream"); |
700 |
|
|
701 |
0 |
bsBuffShadow = (bsBuffShadow << 8) | thech; |
702 |
0 |
bsLiveShadow += 8; |
703 |
0 |
continue; |
704 |
|
} |
705 |
0 |
int zvec = (bsBuffShadow >> (bsLiveShadow - zn)) & ((1 << zn) - 1); |
706 |
0 |
bsLiveShadow -= zn; |
707 |
|
|
708 |
0 |
while (zvec > limit_zt[zn]) { |
709 |
0 |
zn++; |
710 |
0 |
while (bsLiveShadow < 1) { |
711 |
0 |
final int thech = read(); |
712 |
0 |
if (thech < 0) |
713 |
0 |
throw new IOException("unexpected end of stream"); |
714 |
0 |
bsBuffShadow = (bsBuffShadow << 8) | thech; |
715 |
0 |
bsLiveShadow += 8; |
716 |
0 |
continue; |
717 |
|
} |
718 |
0 |
bsLiveShadow--; |
719 |
0 |
zvec = (zvec << 1) | ((bsBuffShadow >> bsLiveShadow) & 1); |
720 |
|
} |
721 |
0 |
nextSym = perm_zt[zvec - base_zt[zn]]; |
722 |
|
} |
723 |
|
|
724 |
0 |
final byte ch = seqToUnseq[yy[0]]; |
725 |
0 |
unzftab[ch & 0xff] += s + 1; |
726 |
|
|
727 |
0 |
while (s-- >= 0) { |
728 |
0 |
ll8[++lastShadow] = ch; |
729 |
|
} |
730 |
|
|
731 |
0 |
if (lastShadow >= limitLast) { |
732 |
0 |
throw new IOException("block overrun"); |
733 |
|
} |
734 |
|
} else { |
735 |
0 |
if (++lastShadow >= limitLast) { |
736 |
0 |
throw new IOException("block overrun"); |
737 |
|
} |
738 |
|
|
739 |
0 |
final char tmp = yy[nextSym - 1]; |
740 |
0 |
unzftab[seqToUnseq[tmp] & 0xff]++; |
741 |
0 |
ll8[lastShadow] = seqToUnseq[tmp]; |
742 |
|
|
743 |
|
|
744 |
|
|
745 |
|
|
746 |
|
|
747 |
|
|
748 |
0 |
if (nextSym <= 16) { |
749 |
0 |
for (int j = nextSym - 1; j > 0;) { |
750 |
0 |
yy[j] = yy[--j]; |
751 |
|
} |
752 |
|
} else { |
753 |
0 |
System.arraycopy(yy, 0, yy, 1, nextSym - 1); |
754 |
|
} |
755 |
|
|
756 |
0 |
yy[0] = tmp; |
757 |
|
|
758 |
0 |
if (groupPos == 0) { |
759 |
0 |
groupPos = G_SIZE - 1; |
760 |
0 |
zt = selector[++groupNo] & 0xff; |
761 |
0 |
base_zt = base[zt]; |
762 |
0 |
limit_zt = limit[zt]; |
763 |
0 |
perm_zt = perm[zt]; |
764 |
0 |
minLens_zt = minLens[zt]; |
765 |
|
} else { |
766 |
0 |
groupPos--; |
767 |
|
} |
768 |
|
|
769 |
0 |
int zn = minLens_zt; |
770 |
|
|
771 |
|
|
772 |
|
|
773 |
0 |
while (bsLiveShadow < zn) { |
774 |
0 |
final int thech = read(); |
775 |
0 |
if (thech < 0) |
776 |
0 |
throw new IOException("unexpected end of stream"); |
777 |
0 |
bsBuffShadow = (bsBuffShadow << 8) | thech; |
778 |
0 |
bsLiveShadow += 8; |
779 |
0 |
continue; |
780 |
|
} |
781 |
0 |
int zvec = (bsBuffShadow >> (bsLiveShadow - zn)) & ((1 << zn) - 1); |
782 |
0 |
bsLiveShadow -= zn; |
783 |
|
|
784 |
0 |
while (zvec > limit_zt[zn]) { |
785 |
0 |
zn++; |
786 |
0 |
while (bsLiveShadow < 1) { |
787 |
0 |
final int thech = read(); |
788 |
0 |
if (thech <0) |
789 |
0 |
throw new IOException("unexpected end of stream"); |
790 |
0 |
bsBuffShadow = (bsBuffShadow << 8) | thech; |
791 |
0 |
bsLiveShadow += 8; |
792 |
0 |
continue; |
793 |
|
} |
794 |
0 |
bsLiveShadow--; |
795 |
0 |
zvec = (zvec << 1) | ((bsBuffShadow >> bsLiveShadow) & 1); |
796 |
|
} |
797 |
0 |
nextSym = perm_zt[zvec - base_zt[zn]]; |
798 |
|
} |
799 |
|
} |
800 |
|
|
801 |
0 |
this.last = lastShadow; |
802 |
0 |
this.bsLive = bsLiveShadow; |
803 |
0 |
this.bsBuff = bsBuffShadow; |
804 |
|
} |
805 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 4 |
Complexity Density: 0.18 |
|
806 |
0 |
private int getAndMoveToFrontDecode0(final int groupNo) throws IOException {... |
807 |
0 |
final InputStream inShadow = this.in; |
808 |
0 |
final Data dataShadow = this.data; |
809 |
0 |
final int zt = dataShadow.selector[groupNo] & 0xff; |
810 |
0 |
final int[] limit_zt = dataShadow.limit[zt]; |
811 |
0 |
int zn = dataShadow.minLens[zt]; |
812 |
0 |
int zvec = bsR(zn); |
813 |
0 |
int bsLiveShadow = this.bsLive; |
814 |
0 |
int bsBuffShadow = this.bsBuff; |
815 |
|
|
816 |
0 |
while (zvec > limit_zt[zn]) { |
817 |
0 |
zn++; |
818 |
0 |
while (bsLiveShadow < 1) { |
819 |
0 |
final int thech = read(); |
820 |
|
|
821 |
0 |
if (thech < 0) |
822 |
0 |
throw new IOException("unexpected end of stream"); |
823 |
|
|
824 |
0 |
bsBuffShadow = (bsBuffShadow << 8) | thech; |
825 |
0 |
bsLiveShadow += 8; |
826 |
0 |
continue; |
827 |
|
} |
828 |
0 |
bsLiveShadow--; |
829 |
0 |
zvec = (zvec << 1) | ((bsBuffShadow >> bsLiveShadow) & 1); |
830 |
|
} |
831 |
|
|
832 |
0 |
this.bsLive = bsLiveShadow; |
833 |
0 |
this.bsBuff = bsBuffShadow; |
834 |
|
|
835 |
0 |
return dataShadow.perm[zt][zvec - dataShadow.base[zt][zn]]; |
836 |
|
} |
837 |
|
|
|
|
| 0% |
Uncovered Elements: 33 (33) |
Complexity: 7 |
Complexity Density: 0.3 |
|
838 |
0 |
private void setupBlock() throws IOException {... |
839 |
0 |
if (this.data == null) { |
840 |
0 |
return; |
841 |
|
} |
842 |
|
|
843 |
0 |
final int[] cftab = this.data.cftab; |
844 |
0 |
final int[] tt = this.data.initTT(this.last + 1); |
845 |
0 |
final byte[] ll8 = this.data.ll8; |
846 |
0 |
cftab[0] = 0; |
847 |
0 |
System.arraycopy(this.data.unzftab, 0, cftab, 1, 256); |
848 |
|
|
849 |
0 |
for (int i = 1, c = cftab[0]; i <= 256; i++) { |
850 |
0 |
c += cftab[i]; |
851 |
0 |
cftab[i] = c; |
852 |
|
} |
853 |
|
|
854 |
0 |
for (int i = 0, lastShadow = this.last; i <= lastShadow; i++) { |
855 |
0 |
tt[cftab[ll8[i] & 0xff]++] = i; |
856 |
|
} |
857 |
|
|
858 |
0 |
if ((this.origPtr < 0) || (this.origPtr >= tt.length)) { |
859 |
0 |
throw new IOException("stream corrupted"); |
860 |
|
} |
861 |
|
|
862 |
0 |
this.su_tPos = tt[this.origPtr]; |
863 |
0 |
this.su_count = 0; |
864 |
0 |
this.su_i2 = 0; |
865 |
0 |
this.su_ch2 = 256; |
866 |
|
|
867 |
0 |
if (this.blockRandomised) { |
868 |
0 |
this.su_rNToGo = 0; |
869 |
0 |
this.su_rTPos = 0; |
870 |
0 |
setupRandPartA(); |
871 |
|
} else { |
872 |
0 |
setupNoRandPartA(); |
873 |
|
} |
874 |
|
} |
875 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 5 |
Complexity Density: 0.29 |
|
876 |
0 |
private void setupRandPartA() throws IOException {... |
877 |
0 |
if (this.su_i2 <= this.last) { |
878 |
0 |
this.su_chPrev = this.su_ch2; |
879 |
0 |
int su_ch2Shadow = this.data.ll8[this.su_tPos] & 0xff; |
880 |
0 |
this.su_tPos = this.data.tt[this.su_tPos]; |
881 |
0 |
if (this.su_rNToGo == 0) { |
882 |
0 |
this.su_rNToGo = BZip2Constants.rNums[this.su_rTPos] - 1; |
883 |
0 |
if (++this.su_rTPos == 512) { |
884 |
0 |
this.su_rTPos = 0; |
885 |
|
} |
886 |
|
} else { |
887 |
0 |
this.su_rNToGo--; |
888 |
|
} |
889 |
0 |
this.su_ch2 = su_ch2Shadow ^= (this.su_rNToGo == 1) ? 1 : 0; |
890 |
0 |
this.su_i2++; |
891 |
0 |
this.currentChar = su_ch2Shadow; |
892 |
0 |
this.currentState = RAND_PART_B_STATE; |
893 |
0 |
this.crc.updateCRC(su_ch2Shadow); |
894 |
|
} else { |
895 |
0 |
endBlock(); |
896 |
0 |
initBlock(); |
897 |
0 |
setupBlock(); |
898 |
|
} |
899 |
|
} |
900 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 2 |
Complexity Density: 0.15 |
|
901 |
0 |
private void setupNoRandPartA() throws IOException {... |
902 |
0 |
if (this.su_i2 <= this.last) { |
903 |
0 |
this.su_chPrev = this.su_ch2; |
904 |
0 |
int su_ch2Shadow = this.data.ll8[this.su_tPos] & 0xff; |
905 |
0 |
this.su_ch2 = su_ch2Shadow; |
906 |
0 |
this.su_tPos = this.data.tt[this.su_tPos]; |
907 |
0 |
this.su_i2++; |
908 |
0 |
this.currentChar = su_ch2Shadow; |
909 |
0 |
this.currentState = NO_RAND_PART_B_STATE; |
910 |
0 |
this.crc.updateCRC(su_ch2Shadow); |
911 |
|
} else { |
912 |
0 |
this.currentState = NO_RAND_PART_A_STATE; |
913 |
0 |
endBlock(); |
914 |
0 |
initBlock(); |
915 |
0 |
setupBlock(); |
916 |
|
} |
917 |
|
} |
918 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 6 |
Complexity Density: 0.32 |
|
919 |
0 |
private void setupRandPartB() throws IOException {... |
920 |
0 |
if (this.su_ch2 != this.su_chPrev) { |
921 |
0 |
this.currentState = RAND_PART_A_STATE; |
922 |
0 |
this.su_count = 1; |
923 |
0 |
setupRandPartA(); |
924 |
0 |
} else if (++this.su_count >= 4) { |
925 |
0 |
this.su_z = (char) (this.data.ll8[this.su_tPos] & 0xff); |
926 |
0 |
this.su_tPos = this.data.tt[this.su_tPos]; |
927 |
0 |
if (this.su_rNToGo == 0) { |
928 |
0 |
this.su_rNToGo = BZip2Constants.rNums[this.su_rTPos] - 1; |
929 |
0 |
if (++this.su_rTPos == 512) { |
930 |
0 |
this.su_rTPos = 0; |
931 |
|
} |
932 |
|
} else { |
933 |
0 |
this.su_rNToGo--; |
934 |
|
} |
935 |
0 |
this.su_j2 = 0; |
936 |
0 |
this.currentState = RAND_PART_C_STATE; |
937 |
0 |
if (this.su_rNToGo == 1) { |
938 |
0 |
this.su_z ^= 1; |
939 |
|
} |
940 |
0 |
setupRandPartC(); |
941 |
|
} else { |
942 |
0 |
this.currentState = RAND_PART_A_STATE; |
943 |
0 |
setupRandPartA(); |
944 |
|
} |
945 |
|
} |
946 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
947 |
0 |
private void setupRandPartC() throws IOException {... |
948 |
0 |
if (this.su_j2 < this.su_z) { |
949 |
0 |
this.currentChar = this.su_ch2; |
950 |
0 |
this.crc.updateCRC(this.su_ch2); |
951 |
0 |
this.su_j2++; |
952 |
|
} else { |
953 |
0 |
this.currentState = RAND_PART_A_STATE; |
954 |
0 |
this.su_i2++; |
955 |
0 |
this.su_count = 0; |
956 |
0 |
setupRandPartA(); |
957 |
|
} |
958 |
|
} |
959 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
960 |
0 |
private void setupNoRandPartB() throws IOException {... |
961 |
0 |
if (this.su_ch2 != this.su_chPrev) { |
962 |
0 |
this.su_count = 1; |
963 |
0 |
setupNoRandPartA(); |
964 |
0 |
} else if (++this.su_count >= 4) { |
965 |
0 |
this.su_z = (char) (this.data.ll8[this.su_tPos] & 0xff); |
966 |
0 |
this.su_tPos = this.data.tt[this.su_tPos]; |
967 |
0 |
this.su_j2 = 0; |
968 |
0 |
setupNoRandPartC(); |
969 |
|
} else { |
970 |
0 |
setupNoRandPartA(); |
971 |
|
} |
972 |
|
} |
973 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
974 |
0 |
private void setupNoRandPartC() throws IOException {... |
975 |
0 |
if (this.su_j2 < this.su_z) { |
976 |
0 |
int su_ch2Shadow = this.su_ch2; |
977 |
0 |
this.currentChar = su_ch2Shadow; |
978 |
0 |
this.crc.updateCRC(su_ch2Shadow); |
979 |
0 |
this.su_j2++; |
980 |
0 |
this.currentState = NO_RAND_PART_C_STATE; |
981 |
|
} else { |
982 |
0 |
this.su_i2++; |
983 |
0 |
this.su_count = 0; |
984 |
0 |
setupNoRandPartA(); |
985 |
|
} |
986 |
|
} |
987 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
988 |
|
private static final class Data extends Object { |
989 |
|
|
990 |
|
|
991 |
|
final boolean[] inUse = new boolean[256]; |
992 |
|
|
993 |
|
final byte[] seqToUnseq = new byte[256]; |
994 |
|
final byte[] selector = new byte[MAX_SELECTORS]; |
995 |
|
final byte[] selectorMtf = new byte[MAX_SELECTORS]; |
996 |
|
|
997 |
|
|
998 |
|
|
999 |
|
|
1000 |
|
|
1001 |
|
final int[] unzftab = new int[256]; |
1002 |
|
|
1003 |
|
final int[][] limit = new int[N_GROUPS][MAX_ALPHA_SIZE]; |
1004 |
|
final int[][] base = new int[N_GROUPS][MAX_ALPHA_SIZE]; |
1005 |
|
final int[][] perm = new int[N_GROUPS][MAX_ALPHA_SIZE]; |
1006 |
|
final int[] minLens = new int[N_GROUPS]; |
1007 |
|
|
1008 |
|
final int[] cftab = new int[257]; |
1009 |
|
final char[] getAndMoveToFrontDecode_yy = new char[256]; |
1010 |
|
final char[][] temp_charArray2d = new char[N_GROUPS][MAX_ALPHA_SIZE]; |
1011 |
|
final byte[] recvDecodingTables_pos = new byte[N_GROUPS]; |
1012 |
|
|
1013 |
|
|
1014 |
|
|
1015 |
|
int[] tt; |
1016 |
|
byte[] ll8; |
1017 |
|
|
1018 |
|
|
1019 |
|
|
1020 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
1021 |
0 |
Data(int blockSize100k) {... |
1022 |
0 |
super(); |
1023 |
|
|
1024 |
0 |
this.ll8 = new byte[blockSize100k * BZip2Constants.baseBlockSize]; |
1025 |
|
} |
1026 |
|
|
1027 |
|
|
1028 |
|
@link |
1029 |
|
|
1030 |
|
|
1031 |
|
|
1032 |
|
|
1033 |
|
|
1034 |
|
@param |
1035 |
|
@return |
1036 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
1037 |
0 |
final int[] initTT(int length) {... |
1038 |
0 |
int[] ttShadow = this.tt; |
1039 |
|
|
1040 |
|
|
1041 |
|
|
1042 |
|
|
1043 |
|
|
1044 |
0 |
if ((ttShadow == null) || (ttShadow.length < length)) { |
1045 |
0 |
this.tt = ttShadow = new int[length]; |
1046 |
|
} |
1047 |
|
|
1048 |
0 |
return ttShadow; |
1049 |
|
} |
1050 |
|
|
1051 |
|
} |
1052 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1053 |
0 |
@SuppressWarnings("unused")... |
1054 |
|
private static void reportCRCError() throws IOException { |
1055 |
|
|
1056 |
|
|
1057 |
|
|
1058 |
|
|
1059 |
0 |
System.err.println("BZip2 CRC error"); |
1060 |
|
} |
1061 |
|
|
1062 |
|
} |
1063 |
|
|