RLPark 1.0.0
Reinforcement Learning Framework in Java
|
00001 /* 00002 * The Apache Software License, Version 1.1 00003 * 00004 * Copyright (c) 2001-2003 The Apache Software Foundation. All rights 00005 * reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * 1. Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * 00014 * 2. Redistributions in binary form must reproduce the above copyright 00015 * notice, this list of conditions and the following disclaimer in 00016 * the documentation and/or other materials provided with the 00017 * distribution. 00018 * 00019 * 3. The end-user documentation included with the redistribution, if 00020 * any, must include the following acknowlegement: 00021 * "This product includes software developed by the 00022 * Apache Software Foundation (http://www.apache.org/)." 00023 * Alternately, this acknowlegement may appear in the software itself, 00024 * if and wherever such third-party acknowlegements normally appear. 00025 * 00026 * 4. The names "Ant" and "Apache Software 00027 * Foundation" must not be used to endorse or promote products derived 00028 * from this software without prior written permission. For written 00029 * permission, please contact apache@apache.org. 00030 * 00031 * 5. Products derived from this software may not be called "Apache" 00032 * nor may "Apache" appear in their names without prior written 00033 * permission of the Apache Group. 00034 * 00035 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 00036 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00037 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00038 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 00039 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00040 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00041 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 00042 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00043 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00044 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00045 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00046 * SUCH DAMAGE. 00047 * ==================================================================== 00048 * 00049 * This software consists of voluntary contributions made by many 00050 * individuals on behalf of the Apache Software Foundation. For more 00051 * information on the Apache Software Foundation, please see 00052 * <http://www.apache.org/>. 00053 */ 00054 00055 /* 00056 * This package is based on the work done by Keiron Liddle, Aftex Software 00057 * <keiron@aftexsw.com> to whom the Ant project is very grateful for his 00058 * great code. 00059 */ 00060 package zephyr.plugin.core.api.internal.bz2; 00061 00062 import static zephyr.plugin.core.api.internal.bz2.BZip2Constants.G_SIZE; 00063 import static zephyr.plugin.core.api.internal.bz2.BZip2Constants.MAX_ALPHA_SIZE; 00064 import static zephyr.plugin.core.api.internal.bz2.BZip2Constants.MAX_CODE_LEN; 00065 import static zephyr.plugin.core.api.internal.bz2.BZip2Constants.MAX_SELECTORS; 00066 import static zephyr.plugin.core.api.internal.bz2.BZip2Constants.N_GROUPS; 00067 import static zephyr.plugin.core.api.internal.bz2.BZip2Constants.RUNA; 00068 import static zephyr.plugin.core.api.internal.bz2.BZip2Constants.RUNB; 00069 import static zephyr.plugin.core.api.internal.bz2.BZip2Constants.baseBlockSize; 00070 import static zephyr.plugin.core.api.internal.bz2.BZip2Constants.rNums; 00071 00072 import java.io.IOException; 00073 import java.io.InputStream; 00074 00081 public class CBZip2InputStream extends InputStream { 00082 private static void cadvise() { 00083 System.out.println("CRC Error"); 00084 // throw new CCoruptionError(); 00085 } 00086 00087 private static void compressedStreamEOF() { 00088 cadvise(); 00089 } 00090 00091 private void makeMaps() { 00092 int i; 00093 nInUse = 0; 00094 for (i = 0; i < 256; i++) 00095 if (inUse[i]) { 00096 seqToUnseq[nInUse] = (char) i; 00097 unseqToSeq[i] = (char) nInUse; 00098 nInUse++; 00099 } 00100 } 00101 00102 /* 00103 * index of the last char in the block, so the block size == last + 1. 00104 */ 00105 private int last; 00106 00107 /* 00108 * index in zptr[] of original string after sorting. 00109 */ 00110 private int origPtr; 00111 00112 /* 00113 * always: in the range 0 .. 9. The current block size is 100000 * this 00114 * number. 00115 */ 00116 private int blockSize100k; 00117 00118 private boolean blockRandomised; 00119 00120 private int bsBuff; 00121 private int bsLive; 00122 private final CRC mCrc = new CRC(); 00123 00124 private final boolean[] inUse = new boolean[256]; 00125 private int nInUse; 00126 00127 private final char[] seqToUnseq = new char[256]; 00128 private final char[] unseqToSeq = new char[256]; 00129 00130 private final char[] selector = new char[MAX_SELECTORS]; 00131 private final char[] selectorMtf = new char[MAX_SELECTORS]; 00132 00133 private int[] tt; 00134 private char[] ll8; 00135 00136 /* 00137 * freq table collected to save a pass over the data during decompression. 00138 */ 00139 private final int[] unzftab = new int[256]; 00140 00141 private final int[][] limit = new int[N_GROUPS][MAX_ALPHA_SIZE]; 00142 private final int[][] base = new int[N_GROUPS][MAX_ALPHA_SIZE]; 00143 private final int[][] perm = new int[N_GROUPS][MAX_ALPHA_SIZE]; 00144 private final int[] minLens = new int[N_GROUPS]; 00145 00146 private InputStream bsStream; 00147 00148 private boolean streamEnd = false; 00149 00150 private int currentChar = -1; 00151 00152 private static final int START_BLOCK_STATE = 1; 00153 private static final int RAND_PART_A_STATE = 2; 00154 private static final int RAND_PART_B_STATE = 3; 00155 private static final int RAND_PART_C_STATE = 4; 00156 private static final int NO_RAND_PART_A_STATE = 5; 00157 private static final int NO_RAND_PART_B_STATE = 6; 00158 private static final int NO_RAND_PART_C_STATE = 7; 00159 00160 private int currentState = START_BLOCK_STATE; 00161 00162 private int storedBlockCRC, storedCombinedCRC; 00163 private int computedBlockCRC, computedCombinedCRC; 00164 00165 int i2, count, chPrev, ch2; 00166 int i, tPos; 00167 int rNToGo = 0; 00168 int rTPos = 0; 00169 int j2; 00170 char z; 00171 00172 public CBZip2InputStream(InputStream zStream) { 00173 ll8 = null; 00174 tt = null; 00175 bsSetStream(zStream); 00176 initialize(); 00177 initBlock(); 00178 setupBlock(); 00179 } 00180 00181 @Override 00182 public int read() { 00183 if (streamEnd) 00184 return -1; 00185 int retChar = currentChar; 00186 switch (currentState) { 00187 case START_BLOCK_STATE: 00188 break; 00189 case RAND_PART_A_STATE: 00190 break; 00191 case RAND_PART_B_STATE: 00192 setupRandPartB(); 00193 break; 00194 case RAND_PART_C_STATE: 00195 setupRandPartC(); 00196 break; 00197 case NO_RAND_PART_A_STATE: 00198 break; 00199 case NO_RAND_PART_B_STATE: 00200 setupNoRandPartB(); 00201 break; 00202 case NO_RAND_PART_C_STATE: 00203 setupNoRandPartC(); 00204 break; 00205 default: 00206 break; 00207 } 00208 return retChar; 00209 } 00210 00211 private void initialize() { 00212 char magic1, magic2, magic3, magic4; 00213 magic1 = bsGetUChar(); 00214 magic2 = bsGetUChar(); 00215 magic3 = bsGetUChar(); 00216 magic4 = bsGetUChar(); 00217 if (magic1 != 'B' || magic2 != 'Z' || magic3 != 'h' || magic4 < '1' || magic4 > '9') { 00218 bsFinishedWithStream(); 00219 streamEnd = true; 00220 return; 00221 } 00222 00223 setDecompressStructureSizes(magic4 - '0'); 00224 computedCombinedCRC = 0; 00225 } 00226 00227 private void initBlock() { 00228 char magic1, magic2, magic3, magic4; 00229 char magic5, magic6; 00230 magic1 = bsGetUChar(); 00231 magic2 = bsGetUChar(); 00232 magic3 = bsGetUChar(); 00233 magic4 = bsGetUChar(); 00234 magic5 = bsGetUChar(); 00235 magic6 = bsGetUChar(); 00236 if (magic1 == 0x17 && magic2 == 0x72 && magic3 == 0x45 && magic4 == 0x38 && magic5 == 0x50 && magic6 == 0x90) { 00237 complete(); 00238 return; 00239 } 00240 00241 if (magic1 != 0x31 || magic2 != 0x41 || magic3 != 0x59 || magic4 != 0x26 || magic5 != 0x53 || magic6 != 0x59) { 00242 badBlockHeader(); 00243 streamEnd = true; 00244 return; 00245 } 00246 00247 storedBlockCRC = bsGetInt32(); 00248 00249 if (bsR(1) == 1) 00250 blockRandomised = true; 00251 else 00252 blockRandomised = false; 00253 00254 // currBlockNo++; 00255 getAndMoveToFrontDecode(); 00256 00257 mCrc.initialiseCRC(); 00258 currentState = START_BLOCK_STATE; 00259 } 00260 00261 private void endBlock() { 00262 computedBlockCRC = mCrc.getFinalCRC(); 00263 /* A bad CRC is considered a fatal error. */ 00264 if (storedBlockCRC != computedBlockCRC) 00265 crcError(); 00266 00267 computedCombinedCRC = computedCombinedCRC << 1 | computedCombinedCRC >>> 31; 00268 computedCombinedCRC ^= computedBlockCRC; 00269 } 00270 00271 private void complete() { 00272 storedCombinedCRC = bsGetInt32(); 00273 if (storedCombinedCRC != computedCombinedCRC) 00274 crcError(); 00275 00276 bsFinishedWithStream(); 00277 streamEnd = true; 00278 } 00279 00280 private static void blockOverrun() { 00281 cadvise(); 00282 } 00283 00284 private static void badBlockHeader() { 00285 cadvise(); 00286 } 00287 00288 private static void crcError() { 00289 cadvise(); 00290 } 00291 00292 private void bsFinishedWithStream() { 00293 try { 00294 if (bsStream != null) 00295 if (bsStream != System.in) { 00296 bsStream.close(); 00297 bsStream = null; 00298 } 00299 } catch (IOException ioe) { 00300 // ignore 00301 } 00302 } 00303 00304 private void bsSetStream(InputStream f) { 00305 bsStream = f; 00306 bsLive = 0; 00307 bsBuff = 0; 00308 } 00309 00310 private int bsR(int n) { 00311 int v; 00312 while (bsLive < n) { 00313 int zzi; 00314 char thech = 0; 00315 try { 00316 thech = (char) bsStream.read(); 00317 } catch (IOException e) { 00318 compressedStreamEOF(); 00319 } 00320 if (thech == (char) -1) 00321 compressedStreamEOF(); 00322 zzi = thech; 00323 bsBuff = bsBuff << 8 | zzi & 0xff; 00324 bsLive += 8; 00325 } 00326 00327 v = bsBuff >> bsLive - n & (1 << n) - 1; 00328 bsLive -= n; 00329 return v; 00330 } 00331 00332 private char bsGetUChar() { 00333 return (char) bsR(8); 00334 } 00335 00336 private int bsGetint() { 00337 int u = 0; 00338 u = u << 8 | bsR(8); 00339 u = u << 8 | bsR(8); 00340 u = u << 8 | bsR(8); 00341 u = u << 8 | bsR(8); 00342 return u; 00343 } 00344 00345 private int bsGetIntVS(int numBits) { 00346 return bsR(numBits); 00347 } 00348 00349 private int bsGetInt32() { 00350 return bsGetint(); 00351 } 00352 00353 private static void hbCreateDecodeTables(int[] limit, int[] base, int[] perm, char[] length, int minLen, int maxLen, 00354 int alphaSize) { 00355 int pp, i, j, vec; 00356 00357 pp = 0; 00358 for (i = minLen; i <= maxLen; i++) 00359 for (j = 0; j < alphaSize; j++) 00360 if (length[j] == i) { 00361 perm[pp] = j; 00362 pp++; 00363 } 00364 00365 for (i = 0; i < MAX_CODE_LEN; i++) 00366 base[i] = 0; 00367 for (i = 0; i < alphaSize; i++) 00368 base[length[i] + 1]++; 00369 00370 for (i = 1; i < MAX_CODE_LEN; i++) 00371 base[i] += base[i - 1]; 00372 00373 for (i = 0; i < MAX_CODE_LEN; i++) 00374 limit[i] = 0; 00375 vec = 0; 00376 00377 for (i = minLen; i <= maxLen; i++) { 00378 vec += base[i + 1] - base[i]; 00379 limit[i] = vec - 1; 00380 vec <<= 1; 00381 } 00382 for (i = minLen + 1; i <= maxLen; i++) 00383 base[i] = (limit[i - 1] + 1 << 1) - base[i]; 00384 } 00385 00386 private void recvDecodingTables() { 00387 char len[][] = new char[N_GROUPS][MAX_ALPHA_SIZE]; 00388 int i, j, t, nGroups, nSelectors, alphaSize; 00389 int minLen, maxLen; 00390 boolean[] inUse16 = new boolean[16]; 00391 00392 /* Receive the mapping table */ 00393 for (i = 0; i < 16; i++) 00394 if (bsR(1) == 1) 00395 inUse16[i] = true; 00396 else 00397 inUse16[i] = false; 00398 00399 for (i = 0; i < 256; i++) 00400 inUse[i] = false; 00401 00402 for (i = 0; i < 16; i++) 00403 if (inUse16[i]) 00404 for (j = 0; j < 16; j++) 00405 if (bsR(1) == 1) 00406 inUse[i * 16 + j] = true; 00407 00408 makeMaps(); 00409 alphaSize = nInUse + 2; 00410 00411 /* Now the selectors */ 00412 nGroups = bsR(3); 00413 nSelectors = bsR(15); 00414 for (i = 0; i < nSelectors; i++) { 00415 j = 0; 00416 while (bsR(1) == 1) 00417 j++; 00418 selectorMtf[i] = (char) j; 00419 } 00420 00421 /* Undo the MTF values for the selectors. */ 00422 { 00423 char[] pos = new char[N_GROUPS]; 00424 char tmp, v; 00425 for (v = 0; v < nGroups; v++) 00426 pos[v] = v; 00427 00428 for (i = 0; i < nSelectors; i++) { 00429 v = selectorMtf[i]; 00430 tmp = pos[v]; 00431 while (v > 0) { 00432 pos[v] = pos[v - 1]; 00433 v--; 00434 } 00435 pos[0] = tmp; 00436 selector[i] = tmp; 00437 } 00438 } 00439 00440 /* Now the coding tables */ 00441 for (t = 0; t < nGroups; t++) { 00442 int curr = bsR(5); 00443 for (i = 0; i < alphaSize; i++) { 00444 while (bsR(1) == 1) 00445 if (bsR(1) == 0) 00446 curr++; 00447 else 00448 curr--; 00449 len[t][i] = (char) curr; 00450 } 00451 } 00452 00453 /* Create the Huffman decoding tables */ 00454 for (t = 0; t < nGroups; t++) { 00455 minLen = 32; 00456 maxLen = 0; 00457 for (i = 0; i < alphaSize; i++) { 00458 if (len[t][i] > maxLen) 00459 maxLen = len[t][i]; 00460 if (len[t][i] < minLen) 00461 minLen = len[t][i]; 00462 } 00463 hbCreateDecodeTables(limit[t], base[t], perm[t], len[t], minLen, maxLen, alphaSize); 00464 minLens[t] = minLen; 00465 } 00466 } 00467 00468 private void getAndMoveToFrontDecode() { 00469 char[] yy = new char[256]; 00470 int i, j, nextSym, limitLast; 00471 int EOB, groupNo, groupPos; 00472 00473 limitLast = baseBlockSize * blockSize100k; 00474 origPtr = bsGetIntVS(24); 00475 00476 recvDecodingTables(); 00477 EOB = nInUse + 1; 00478 groupNo = -1; 00479 groupPos = 0; 00480 00481 /* 00482 * Setting up the unzftab entries here is not strictly necessary, but it 00483 * does save having to do it later in a separate pass, and so saves a 00484 * block's worth of cache misses. 00485 */ 00486 for (i = 0; i <= 255; i++) 00487 unzftab[i] = 0; 00488 00489 for (i = 0; i <= 255; i++) 00490 yy[i] = (char) i; 00491 00492 last = -1; 00493 00494 { 00495 int zt, zn, zvec, zj; 00496 if (groupPos == 0) { 00497 groupNo++; 00498 groupPos = G_SIZE; 00499 } 00500 groupPos--; 00501 zt = selector[groupNo]; 00502 zn = minLens[zt]; 00503 zvec = bsR(zn); 00504 while (zvec > limit[zt][zn]) { 00505 zn++; 00506 { 00507 { 00508 while (bsLive < 1) { 00509 int zzi; 00510 char thech = 0; 00511 try { 00512 thech = (char) bsStream.read(); 00513 } catch (IOException e) { 00514 compressedStreamEOF(); 00515 } 00516 if (thech == (char) -1) 00517 compressedStreamEOF(); 00518 zzi = thech; 00519 bsBuff = bsBuff << 8 | zzi & 0xff; 00520 bsLive += 8; 00521 } 00522 } 00523 zj = bsBuff >> bsLive - 1 & 1; 00524 bsLive--; 00525 } 00526 zvec = zvec << 1 | zj; 00527 } 00528 nextSym = perm[zt][zvec - base[zt][zn]]; 00529 } 00530 00531 while (true) { 00532 00533 if (nextSym == EOB) 00534 break; 00535 00536 if (nextSym == RUNA || nextSym == RUNB) { 00537 char ch; 00538 int s = -1; 00539 int N = 1; 00540 do { 00541 if (nextSym == RUNA) 00542 s = s + (0 + 1) * N; 00543 else if (nextSym == RUNB) 00544 s = s + (1 + 1) * N; 00545 N = N * 2; 00546 { 00547 int zt, zn, zvec, zj; 00548 if (groupPos == 0) { 00549 groupNo++; 00550 groupPos = G_SIZE; 00551 } 00552 groupPos--; 00553 zt = selector[groupNo]; 00554 zn = minLens[zt]; 00555 zvec = bsR(zn); 00556 while (zvec > limit[zt][zn]) { 00557 zn++; 00558 { 00559 { 00560 while (bsLive < 1) { 00561 int zzi; 00562 char thech = 0; 00563 try { 00564 thech = (char) bsStream.read(); 00565 } catch (IOException e) { 00566 compressedStreamEOF(); 00567 } 00568 if (thech == (char) -1) 00569 compressedStreamEOF(); 00570 zzi = thech; 00571 bsBuff = bsBuff << 8 | zzi & 0xff; 00572 bsLive += 8; 00573 } 00574 } 00575 zj = bsBuff >> bsLive - 1 & 1; 00576 bsLive--; 00577 } 00578 zvec = zvec << 1 | zj; 00579 } 00580 nextSym = perm[zt][zvec - base[zt][zn]]; 00581 } 00582 } while (nextSym == RUNA || nextSym == RUNB); 00583 00584 s++; 00585 ch = seqToUnseq[yy[0]]; 00586 unzftab[ch] += s; 00587 00588 while (s > 0) { 00589 last++; 00590 ll8[last] = ch; 00591 s--; 00592 } 00593 00594 if (last >= limitLast) 00595 blockOverrun(); 00596 continue; 00597 } 00598 char tmp; 00599 last++; 00600 if (last >= limitLast) 00601 blockOverrun(); 00602 00603 tmp = yy[nextSym - 1]; 00604 unzftab[seqToUnseq[tmp]]++; 00605 ll8[last] = seqToUnseq[tmp]; 00606 00607 /* 00608 * This loop is hammered during decompression, hence the unrolling. 00609 * 00610 * for (j = nextSym-1; j > 0; j--) yy[j] = yy[j-1]; 00611 */ 00612 00613 j = nextSym - 1; 00614 for (; j > 3; j -= 4) { 00615 yy[j] = yy[j - 1]; 00616 yy[j - 1] = yy[j - 2]; 00617 yy[j - 2] = yy[j - 3]; 00618 yy[j - 3] = yy[j - 4]; 00619 } 00620 for (; j > 0; j--) 00621 yy[j] = yy[j - 1]; 00622 00623 yy[0] = tmp; 00624 { 00625 int zt, zn, zvec, zj; 00626 if (groupPos == 0) { 00627 groupNo++; 00628 groupPos = G_SIZE; 00629 } 00630 groupPos--; 00631 zt = selector[groupNo]; 00632 zn = minLens[zt]; 00633 zvec = bsR(zn); 00634 while (zvec > limit[zt][zn]) { 00635 zn++; 00636 { 00637 { 00638 while (bsLive < 1) { 00639 int zzi; 00640 char thech = 0; 00641 try { 00642 thech = (char) bsStream.read(); 00643 } catch (IOException e) { 00644 compressedStreamEOF(); 00645 } 00646 zzi = thech; 00647 bsBuff = bsBuff << 8 | zzi & 0xff; 00648 bsLive += 8; 00649 } 00650 } 00651 zj = bsBuff >> bsLive - 1 & 1; 00652 bsLive--; 00653 } 00654 zvec = zvec << 1 | zj; 00655 } 00656 nextSym = perm[zt][zvec - base[zt][zn]]; 00657 } 00658 continue; 00659 } 00660 } 00661 00662 private void setupBlock() { 00663 int[] cftab = new int[257]; 00664 char ch; 00665 00666 cftab[0] = 0; 00667 for (i = 1; i <= 256; i++) 00668 cftab[i] = unzftab[i - 1]; 00669 for (i = 1; i <= 256; i++) 00670 cftab[i] += cftab[i - 1]; 00671 00672 for (i = 0; i <= last; i++) { 00673 ch = ll8[i]; 00674 tt[cftab[ch]] = i; 00675 cftab[ch]++; 00676 } 00677 00678 tPos = tt[origPtr]; 00679 00680 count = 0; 00681 i2 = 0; 00682 ch2 = 256; /* not a char and not EOF */ 00683 00684 if (blockRandomised) { 00685 rNToGo = 0; 00686 rTPos = 0; 00687 setupRandPartA(); 00688 } else 00689 setupNoRandPartA(); 00690 } 00691 00692 private void setupRandPartA() { 00693 if (i2 <= last) { 00694 chPrev = ch2; 00695 ch2 = ll8[tPos]; 00696 tPos = tt[tPos]; 00697 if (rNToGo == 0) { 00698 rNToGo = rNums[rTPos]; 00699 rTPos++; 00700 if (rTPos == 512) 00701 rTPos = 0; 00702 } 00703 rNToGo--; 00704 ch2 ^= rNToGo == 1 ? 1 : 0; 00705 i2++; 00706 00707 currentChar = ch2; 00708 currentState = RAND_PART_B_STATE; 00709 mCrc.updateCRC(ch2); 00710 } else { 00711 endBlock(); 00712 initBlock(); 00713 setupBlock(); 00714 } 00715 } 00716 00717 private void setupNoRandPartA() { 00718 if (i2 <= last) { 00719 chPrev = ch2; 00720 ch2 = ll8[tPos]; 00721 tPos = tt[tPos]; 00722 i2++; 00723 00724 currentChar = ch2; 00725 currentState = NO_RAND_PART_B_STATE; 00726 mCrc.updateCRC(ch2); 00727 } else { 00728 endBlock(); 00729 initBlock(); 00730 setupBlock(); 00731 } 00732 } 00733 00734 private void setupRandPartB() { 00735 if (ch2 != chPrev) { 00736 currentState = RAND_PART_A_STATE; 00737 count = 1; 00738 setupRandPartA(); 00739 } else { 00740 count++; 00741 if (count >= 4) { 00742 z = ll8[tPos]; 00743 tPos = tt[tPos]; 00744 if (rNToGo == 0) { 00745 rNToGo = rNums[rTPos]; 00746 rTPos++; 00747 if (rTPos == 512) 00748 rTPos = 0; 00749 } 00750 rNToGo--; 00751 z ^= rNToGo == 1 ? 1 : 0; 00752 j2 = 0; 00753 currentState = RAND_PART_C_STATE; 00754 setupRandPartC(); 00755 } else { 00756 currentState = RAND_PART_A_STATE; 00757 setupRandPartA(); 00758 } 00759 } 00760 } 00761 00762 private void setupRandPartC() { 00763 if (j2 < z) { 00764 currentChar = ch2; 00765 mCrc.updateCRC(ch2); 00766 j2++; 00767 } else { 00768 currentState = RAND_PART_A_STATE; 00769 i2++; 00770 count = 0; 00771 setupRandPartA(); 00772 } 00773 } 00774 00775 private void setupNoRandPartB() { 00776 if (ch2 != chPrev) { 00777 currentState = NO_RAND_PART_A_STATE; 00778 count = 1; 00779 setupNoRandPartA(); 00780 } else { 00781 count++; 00782 if (count >= 4) { 00783 z = ll8[tPos]; 00784 tPos = tt[tPos]; 00785 currentState = NO_RAND_PART_C_STATE; 00786 j2 = 0; 00787 setupNoRandPartC(); 00788 } else { 00789 currentState = NO_RAND_PART_A_STATE; 00790 setupNoRandPartA(); 00791 } 00792 } 00793 } 00794 00795 private void setupNoRandPartC() { 00796 if (j2 < z) { 00797 currentChar = ch2; 00798 mCrc.updateCRC(ch2); 00799 j2++; 00800 } else { 00801 currentState = NO_RAND_PART_A_STATE; 00802 i2++; 00803 count = 0; 00804 setupNoRandPartA(); 00805 } 00806 } 00807 00808 private void setDecompressStructureSizes(int newSize100k) { 00809 if (!(0 <= newSize100k && newSize100k <= 9 && 0 <= blockSize100k && blockSize100k <= 9)) { 00810 // throw new IOException("Invalid block size"); 00811 } 00812 00813 blockSize100k = newSize100k; 00814 00815 if (newSize100k == 0) 00816 return; 00817 00818 int n = baseBlockSize * newSize100k; 00819 ll8 = new char[n]; 00820 tt = new int[n]; 00821 } 00822 }