CosDocument.java 117 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.internal.io.ByteReader
 *  com.adobe.internal.io.ByteWriter
 *  com.adobe.internal.io.ByteWriterFactory
 *  com.adobe.internal.io.ByteWriterFactory$Fixed
 *  com.adobe.internal.io.stream.IO
 *  com.adobe.internal.io.stream.InputByteStream
 *  com.adobe.internal.io.stream.NullOutputByteStream
 *  com.adobe.internal.io.stream.OutputByteStream
 *  com.adobe.internal.io.stream.StreamManager
 */
package com.adobe.internal.pdftoolkit.core.cos;

import com.adobe.internal.io.ByteReader;
import com.adobe.internal.io.ByteWriter;
import com.adobe.internal.io.ByteWriterFactory;
import com.adobe.internal.io.stream.IO;
import com.adobe.internal.io.stream.InputByteStream;
import com.adobe.internal.io.stream.NullOutputByteStream;
import com.adobe.internal.io.stream.OutputByteStream;
import com.adobe.internal.io.stream.StreamManager;
import com.adobe.internal.pdftoolkit.core.cos.CosArray;
import com.adobe.internal.pdftoolkit.core.cos.CosBoolean;
import com.adobe.internal.pdftoolkit.core.cos.CosCloneMgr;
import com.adobe.internal.pdftoolkit.core.cos.CosContainer;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.cos.CosEncryption;
import com.adobe.internal.pdftoolkit.core.cos.CosLinearization;
import com.adobe.internal.pdftoolkit.core.cos.CosList;
import com.adobe.internal.pdftoolkit.core.cos.CosListInt;
import com.adobe.internal.pdftoolkit.core.cos.CosName;
import com.adobe.internal.pdftoolkit.core.cos.CosNull;
import com.adobe.internal.pdftoolkit.core.cos.CosNumeric;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.cos.CosObjectID;
import com.adobe.internal.pdftoolkit.core.cos.CosObjectInfo;
import com.adobe.internal.pdftoolkit.core.cos.CosObjectRef;
import com.adobe.internal.pdftoolkit.core.cos.CosObjectStream;
import com.adobe.internal.pdftoolkit.core.cos.CosOpenOptions;
import com.adobe.internal.pdftoolkit.core.cos.CosOptimizer;
import com.adobe.internal.pdftoolkit.core.cos.CosPDFOptimizer;
import com.adobe.internal.pdftoolkit.core.cos.CosRepairList;
import com.adobe.internal.pdftoolkit.core.cos.CosSaveParams;
import com.adobe.internal.pdftoolkit.core.cos.CosStream;
import com.adobe.internal.pdftoolkit.core.cos.CosString;
import com.adobe.internal.pdftoolkit.core.cos.CosToken;
import com.adobe.internal.pdftoolkit.core.cos.PDFCore;
import com.adobe.internal.pdftoolkit.core.cos.REPAIRTYPE;
import com.adobe.internal.pdftoolkit.core.cos.XRefTable;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFUnsupportedFeatureException;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.core.types.ASString;
import com.adobe.internal.pdftoolkit.core.util.PDFDocEncoding;
import com.adobe.internal.pdftoolkit.core.util.StringOps;
import com.adobe.internal.pdftoolkit.core.util.Utility;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.rmi.server.UID;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
public final class CosDocument {
    private static final String XREF = "xref\n";
    private static final String EOF = "\n%%EOF\n";
    private static final String STARTXREF = "startxref\n";
    private static final int OBJSTM_MAXNUMOBJS = 200;
    private static final byte[] PDF_MARKER = new byte[]{37, 80, 68, 70, 45};
    private static final int[] PDF_MARKER_KMPARRAY = Utility.ComputeKMPNextArray(PDF_MARKER);
    private static final byte[] FDF_MARKER = new byte[]{37, 70, 68, 70, 45};
    private static final int[] FDF_MARKER_KMPARRAY = Utility.ComputeKMPNextArray(FDF_MARKER);
    static final HashSet<ASName> dictionariesNotToBeCompressed = new HashSet();
    private CosOpenOptions mOptions;
    private StreamManager mStreamManager;
    private ByteReader mByteReader;
    private CosEncryption mEncryption;
    private InputByteStream mBuf;
    private XRefTable mXRef;
    private Object[] mUserData = new Object[2];
    private CosList mObjectInfos;
    private CosList mCompObjInfos;
    private int mNumObjects;
    private int mOrigNumObjects;
    private CosLinearization mCosLin;
    private String mToSaveVersion;
    private Map mToSaveExtensions;
    private boolean mToSaveExtensionsInit;
    private static final String MAX_VERSION = "1.7";
    private String mHeader = "%PDF-1.7\r\n";
    private String mHeaderToken;
    private CosDictionary mTrailer;
    private CosDictionary mRoot;
    private boolean mIsFDF;
    private boolean mCacheEnabled = true;
    private int mHeaderTrashCount;
    private int mTrailerTrashCount;
    private boolean mDocIsDirty;
    private boolean mSaveToCopy;
    private boolean mIsLinearized;
    private boolean mWasLinearized;
    private boolean mForceCompress;
    private long garbageLength = 0;
    private CosRepairList cosRepairList;
    private boolean documentCosLevelRepaired;
    private boolean useRepairList = true;
    private long nextIncrementalSectionOffset = -1;
    private static String mLoggingPath;
    private EnumSet<REPAIRTYPE> repairTypes = EnumSet.noneOf(REPAIRTYPE.class);

    private CosDocument(CosOpenOptions options) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        this.mOptions = options;
        this.mStreamManager = StreamManager.newInstance((ByteWriterFactory)options.getByteWriterFactory(), (ByteReader)null);
        this.mEncryption = new CosEncryption(null);
        this.init();
        this.mEncryption.setupDecryption();
    }

    private CosDocument(ByteReader byteReader, CosOpenOptions options) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        this.mOptions = options;
        this.mByteReader = byteReader;
        this.mStreamManager = StreamManager.newInstance((ByteWriterFactory)options.getByteWriterFactory(), (ByteReader)byteReader);
        this.init(byteReader);
    }

    public static CosDocument newDocument(ByteReader byteReader, CosOpenOptions options) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        return new CosDocument(byteReader, options);
    }

    public static CosDocument newDocument(CosOpenOptions options) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        return new CosDocument(options);
    }

    public static CosDocument newDocument(PDFCore pdfCore) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        if (pdfCore == null) {
            throw new PDFUnsupportedFeatureException("PDFCore must be non-null");
        }
        return pdfCore.getCosDoc();
    }

    public StreamManager getStreamManager() {
        return this.mStreamManager;
    }

    private int[] setWidthsArray(Object list, CosStream xrefStream, long xrefStmPos) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        ArrayList<Object> secList;
        int[] widths = new int[3];
        long maxW2 = xrefStmPos;
        int maxW3 = 0;
        if (list instanceof ArrayList) {
            secList = (ArrayList<Object>)list;
        } else {
            secList = new ArrayList<Object>();
            secList.add(list);
        }
        for (CosList infosList : secList) {
            Iterator infoIter = infosList.iterator();
            while (infoIter.hasNext()) {
                int thisW3;
                long thisW2;
                CosObjectInfo info = (CosObjectInfo)infoIter.next();
                if (info.isFree()) continue;
                if (info.isCompressed()) {
                    thisW2 = info.getStreamInfo().getObjNum();
                    thisW3 = info.getStreamNdx();
                } else {
                    thisW2 = info.getPos();
                    thisW3 = info.getObjGen();
                }
                if (thisW2 > maxW2) {
                    maxW2 = thisW2;
                }
                if (thisW3 <= maxW3) continue;
                maxW3 = thisW3;
            }
        }
        widths[0] = 1;
        boolean widthW2 = true;
        while (maxW2 > 255) {
            ++widthW2;
            maxW2 >>= 8;
        }
        widths[1] = widthW2;
        int widthW3 = 1;
        while (maxW3 > 255) {
            ++widthW3;
            maxW3 >>= 8;
        }
        widths[2] = widthW3;
        CosArray wValues = this.createCosArray();
        wValues.addInt(widths[0]);
        wValues.addInt(widths[1]);
        wValues.addInt(widths[2]);
        xrefStream.put(ASName.k_W, wValues);
        CosDictionary parmsDict = this.createDirectCosDictionary();
        parmsDict.put(ASName.k_Columns, true + widthW2 + widthW3);
        parmsDict.put(ASName.k_Predictor, 12);
        xrefStream.put(ASName.k_DecodeParms, parmsDict);
        return widths;
    }

    public PDFCore finish() {
        return new PDFCore(this);
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public void close() throws PDFIOException, PDFCosParseException, PDFSecurityException {
        try {
            try {
                if (this.mBuf != null) {
                    this.mBuf.close();
                }
            }
            finally {
                try {
                    if (this.mObjectInfos != null) {
                        this.closeAllCosObjects();
                    }
                }
                finally {
                    try {
                        if (this.mXRef != null) {
                            this.mXRef.close();
                        }
                    }
                    finally {
                        if (this.mStreamManager != null) {
                            this.mStreamManager.close();
                        }
                    }
                }
            }
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
        this.mBuf = null;
        this.mEncryption = null;
        this.mObjectInfos = null;
        this.mRoot = null;
        this.mTrailer = null;
        this.mXRef = null;
        this.mStreamManager = null;
    }

    private long headerPos(InputByteStream byteStream) throws IOException {
        byte[] pdfMarker = new byte[]{37, 80, 68, 70, 45};
        int size = 1024;
        if ((long)size > byteStream.length()) {
            size = (int)byteStream.length();
        }
        byte[] header = new byte[size];
        byteStream.seek(0);
        byteStream.read(header);
        long result = Utility.KMPFindFirst(pdfMarker, Utility.ComputeKMPNextArray(pdfMarker), header);
        if (result >= 0) {
            byte[] linearizationMarker = new byte[]{47, 76, 105, 110, 101, 97, 114, 105, 122, 101, 100, 32, 49};
            this.mIsLinearized = Utility.KMPFindFirst(linearizationMarker, Utility.ComputeKMPNextArray(linearizationMarker), header) >= 0;
            this.mWasLinearized = this.mIsLinearized;
        }
        return result;
    }

    private long fdfHeaderPos(InputByteStream byteStream) throws IOException {
        byte[] fdfMarker = new byte[]{37, 70, 68, 70, 45};
        int size = 1024;
        if ((long)size > byteStream.length()) {
            size = (int)byteStream.length();
        }
        byte[] header = new byte[size];
        byteStream.seek(0);
        byteStream.read(header);
        return Utility.KMPFindFirst(fdfMarker, Utility.ComputeKMPNextArray(fdfMarker), header);
    }

    private void init(ByteReader byteReader) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        try {
            long eof;
            InputByteStream byteStream = this.mStreamManager.getInputByteStream(byteReader);
            this.initObjectList();
            long hdr = this.headerPos(byteStream);
            this.mHeaderTrashCount = (int)hdr;
            if (hdr < 0 && (hdr = this.fdfHeaderPos(byteStream)) >= 0) {
                this.mIsFDF = true;
            }
            if ((eof = this.mOptions.getEofValue()) > byteStream.length()) {
                eof = byteStream.length();
                this.mOptions.setEofValue(eof);
            }
            if (hdr < 0) {
                throw new PDFCosParseException("Stream does not represent a PDF document.");
            }
            if (hdr == 0 && eof == byteStream.length()) {
                this.mBuf = byteStream;
            } else {
                this.mBuf = this.mStreamManager.getInputByteStream(byteReader, hdr, eof - hdr);
                byteStream.close();
            }
            this.mEncryption = new CosEncryption(this);
            this.mXRef = new XRefTable(this, this.mBuf.slice(), this.mOptions.getNoPreloadXRef(), this.mIsFDF);
            try {
                this.mXRef.loadMainInfos();
                this.mXRef.loadUpdateInfos();
                if (this.mOptions != null && this.mOptions.skipCorruptObjects()) {
                    this.linkInfos();
                }
                if (this.garbageLength > 0) {
                    this.repairTypes.add(REPAIRTYPE.xrefRepair);
                }
            }
            catch (PDFCosParseException e) {
                if (this.mOptions.getRepairEnabled()) {
                    this.mXRef.rebuild();
                    this.repairTypes.add(REPAIRTYPE.xrefRepair);
                }
                throw new PDFCosParseException("XRef repair required but not enabled", e);
            }
            this.mXRef.setupTrailerEncryption();
            CosDictionary trailer = this.mXRef.getTrailer();
            if (!this.mIsFDF) {
                CosObject sz = trailer.get(ASName.k_Size);
                int size = ((CosNumeric)sz).intValue();
                int numObjectsDefinedInXRefEntries = this.mXRef.getNumObjectsDefinedInXRefEntries();
                if (this.mOptions.getRepairEnabled()) {
                    if (size >= numObjectsDefinedInXRefEntries) {
                        this.mOrigNumObjects = this.mNumObjects = size;
                    } else {
                        this.mOrigNumObjects = this.mNumObjects = numObjectsDefinedInXRefEntries;
                        this.repairTypes.add(REPAIRTYPE.sizeEntryRepair);
                    }
                } else {
                    this.mOrigNumObjects = this.mNumObjects = size;
                }
                this.getEncryption().setupDecryption();
            }
            this.mTrailerTrashCount = (int)(this.mBuf.length() - this.mXRef.getRevisionEOF(this.mXRef.getNumRevisions() - 1));
            if (this.mXRef.getNumRevisions() != 1) {
                this.mIsLinearized = false;
            }
            this.mTrailer = trailer;
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
    }

    private void linkInfos() {
        Iterator itr = this.mObjectInfos.iterator();
        CosObjectInfo[] infos = new CosObjectInfo[this.mObjectInfos.count()];
        int index = 0;
        while (itr.hasNext()) {
            infos[index++] = (CosObjectInfo)itr.next();
        }
        Arrays.sort(infos, new Comparator<CosObjectInfo>(){

            @Override
            public int compare(CosObjectInfo o1, CosObjectInfo o2) {
                long pos2;
                long pos1 = o1.getPos();
                if (pos1 == 0 && o1.getStreamInfo() != null) {
                    pos1 = o1.getStreamInfo().getPos();
                }
                if ((pos2 = o2.getPos()) == 0 && o2.getStreamInfo() != null) {
                    pos2 = o2.getStreamInfo().getPos();
                }
                return Long.valueOf(pos1).compareTo(pos2);
            }
        });
        for (int i = 0; i < infos.length - 1; ++i) {
            if (infos[i + 1].getPos() == 0) {
                if (infos[i + 1].getStreamInfo() == null) continue;
                infos[i].setNextObjPos(infos[i + 1].getStreamInfo().getPos());
                continue;
            }
            infos[i].setNextObjPos(infos[i + 1].getPos());
        }
    }

    private void init() throws PDFCosParseException, PDFIOException, PDFSecurityException {
        this.initObjectList();
        this.mBuf = null;
        this.mXRef = new XRefTable(this);
        ++this.mNumObjects;
        CosDictionary cosCatalog = this.createCosDictionary(1);
        cosCatalog.put(ASName.k_Type, ASName.k_Catalog);
        this.mXRef.getTrailer().put(ASName.k_Root, cosCatalog);
        this.mEncryption = new CosEncryption(this);
        this.mTrailer = this.mXRef.getTrailer();
    }

    private void initObjectList() {
        this.mNumObjects = 0;
        this.mObjectInfos = new CosList();
        CosObjectInfo freeInfo = this.getObjectInfo(0, 65535);
        freeInfo.markFree();
    }

    public String getOriginalVersion() throws PDFCosParseException, PDFIOException, PDFSecurityException {
        String result = null;
        String catalogVersion = null;
        String headerVersion = null;
        CosObject version = this.getRoot().get(ASName.k_Version);
        if (version instanceof CosName) {
            catalogVersion = ((CosName)version).nameValue().asString(true);
        }
        try {
            if (catalogVersion != null) {
                Float.parseFloat(catalogVersion);
                if (catalogVersion.charAt(0) != '1') {
                    catalogVersion = null;
                }
            }
        }
        catch (NumberFormatException e) {
            catalogVersion = null;
        }
        try {
            if (this.mBuf != null) {
                String headerVersionLine;
                long verpos;
                int startindx;
                InputByteStream firstK;
                long size = 1024;
                if (size > this.mBuf.length()) {
                    size = this.mBuf.length();
                }
                if ((verpos = Utility.KMPFindFirst(PDF_MARKER, PDF_MARKER_KMPARRAY, firstK = this.mBuf.slice(0, size))) < 0) {
                    firstK.seek(0);
                    verpos = Utility.KMPFindFirst(FDF_MARKER, FDF_MARKER_KMPARRAY, firstK);
                }
                if ((startindx = (headerVersionLine = CosToken.readLine(firstK.seek(verpos), true)).indexOf("1.")) > 0) {
                    headerVersion = headerVersionLine.substring(startindx, startindx + 3);
                }
            }
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
        if (catalogVersion != null && headerVersion != null) {
            int decision = Float.compare(Float.parseFloat(catalogVersion), Float.parseFloat(headerVersion));
            result = decision > 0 ? catalogVersion : headerVersion;
        } else if (catalogVersion != null) {
            result = catalogVersion;
        } else if (headerVersion != null) {
            result = headerVersion;
        }
        return result;
    }

    public String procureOriginalVersion() throws PDFCosParseException, PDFIOException, PDFSecurityException {
        String version = this.getOriginalVersion();
        if (version == null) {
            version = "1.7";
        }
        return version;
    }

    public Map getToSaveExtensions() {
        return this.mToSaveExtensions;
    }

    public void setToSaveExtensions(Map extensions) {
        this.mToSaveExtensions = extensions;
        this.mToSaveExtensionsInit = true;
    }

    public boolean isToSaveExtensionsInitialized() {
        return this.mToSaveExtensionsInit;
    }

    public String getToSaveVersion() {
        return this.mToSaveVersion;
    }

    public void setToSaveVersion(String version) {
        this.mToSaveVersion = version;
    }

    public String procureToSaveVersion() throws PDFCosParseException, PDFIOException, PDFSecurityException {
        String version = this.getToSaveVersion();
        if (version == null) {
            version = this.getOriginalVersion();
        }
        if (version == null) {
            version = "1.7";
        }
        return version;
    }

    private CosSaveParams normalizeParams(CosSaveParams params) throws PDFCosParseException, PDFInvalidParameterException, PDFIOException, PDFSecurityException {
        String toSaveVersion;
        params = (CosSaveParams)params.clone();
        String originalVersion = this.getOriginalVersion();
        if (originalVersion == null) {
            originalVersion = "1.7";
        }
        String string = toSaveVersion = this.mToSaveVersion == null ? params.getVersion() : this.mToSaveVersion;
        if (toSaveVersion == null) {
            toSaveVersion = originalVersion;
        }
        int xrefStyle = params.getXrefStyle();
        int saveStyle = params.getSaveStyle();
        boolean saveToCopy = params.getSaveToCopy();
        if (saveStyle == 0) {
            saveStyle = 2;
        }
        if (saveStyle == 1) {
            int xrefType = this.mXRef.getType();
            xrefStyle = xrefType == 0 ? 1 : (xrefType == 1 ? 2 : 3);
            if (!originalVersion.equals(toSaveVersion)) {
                String[] originalVersionElements = originalVersion.split("\\.");
                int originalVersionMajorVal = Integer.parseInt(originalVersionElements[0]);
                int originalVersionMinorVal = 0;
                if (originalVersionElements.length > 1) {
                    originalVersionMinorVal = Integer.parseInt(originalVersionElements[1]);
                }
                String[] toSaveVersionElements = toSaveVersion.split("\\.");
                int toSaveVersionMajorVal = Integer.parseInt(toSaveVersionElements[0]);
                int toSaveVersionMinorVal = 0;
                if (toSaveVersionElements.length > 1) {
                    toSaveVersionMinorVal = Integer.parseInt(toSaveVersionElements[1]);
                }
                if (toSaveVersionMajorVal == 1 && toSaveVersionMinorVal < 4) {
                    throw new PDFInvalidParameterException("Cannot change the version during an incremental save to PDF 1.3 and earlier");
                }
                if (toSaveVersionMajorVal < originalVersionMajorVal) {
                    throw new PDFInvalidParameterException("Cannot lower version in incremental save");
                }
                if (toSaveVersionMajorVal == originalVersionMajorVal && toSaveVersionMinorVal < originalVersionMinorVal) {
                    throw new PDFInvalidParameterException("Cannot lower version in incremental save");
                }
                this.getRoot().put(ASName.k_Version, ASName.create(toSaveVersion));
            }
        } else {
            if (saveToCopy && saveStyle == 3) {
                throw new PDFInvalidParameterException("SaveToCopy mode does not support linear save");
            }
            if (params.getHeader() != null) {
                this.mHeader = params.getHeader();
            } else {
                this.mHeaderToken = params.getHeaderToken();
                if (this.mHeaderToken != null) {
                    if (this.mHeaderToken.length() > 10) {
                        throw new PDFInvalidParameterException("Header token too long");
                    }
                    for (int i = 0; i < this.mHeaderToken.length(); ++i) {
                        char c = this.mHeaderToken.charAt(i);
                        if (c != '\r' && c != '\n' && (c & 65280) == 0) continue;
                        throw new PDFInvalidParameterException("Illegal header token");
                    }
                }
                this.buildHeaderString(toSaveVersion);
            }
            if (xrefStyle == 0) {
                int xrefType;
                xrefStyle = this.mXRef.isNew() ? 1 : ((xrefType = this.mXRef.getType()) == 0 ? 1 : (xrefType == 1 ? 2 : 3));
            }
            if (xrefStyle == 2) {
                float versionVal = 0.0f;
                versionVal = Float.parseFloat(toSaveVersion);
                if ((double)versionVal < 1.5) {
                    xrefStyle = 3;
                }
            }
            if (xrefStyle == 3 && this.getRoot().get(ASName.k_StructTreeRoot) == null) {
                xrefStyle = 1;
            }
            this.getRoot().remove(ASName.k_Version);
        }
        if (this.mHeader.indexOf("%FDF-") >= 0) {
            this.mIsFDF = true;
        }
        if (this.mIsFDF) {
            if (saveStyle != 2) {
                throw new PDFInvalidParameterException("FDF mode supports full save only");
            }
            xrefStyle = 1;
        }
        params.setHeader(this.mHeader);
        params.setVersion(toSaveVersion);
        params.setXrefStyle(xrefStyle);
        params.setSaveStyle(saveStyle);
        this.mForceCompress = params.getForceCompress();
        this.mSaveToCopy = saveToCopy;
        return params;
    }

    public CosDictionary getTrailer() {
        if (this.mTrailer == null && this.mXRef != null) {
            this.mTrailer = this.mXRef.getTrailer();
        }
        return this.mTrailer;
    }

    public CosDictionary[] getTrailerList() {
        CosDictionary[] list = null;
        if (this.mXRef != null) {
            list = this.mXRef.getTrailerList();
        }
        return list;
    }

    public CosDictionary getRoot() throws PDFCosParseException, PDFIOException, PDFSecurityException {
        CosObject catalog2;
        CosObject catalog2;
        if (this.mRoot != null) {
            catalog2 = this.mRoot;
        } else {
            CosDictionary trailer = this.getTrailer();
            catalog2 = trailer.get(ASName.k_Root);
            if (!(catalog2 instanceof CosDictionary)) {
                throw new PDFCosParseException("Document does not have a catalog of type dictionary.");
            }
            this.mRoot = catalog2;
        }
        return catalog2;
    }

    public CosDictionary getInfo() throws PDFCosParseException, PDFIOException, PDFSecurityException {
        CosObject docInfo = this.getTrailer().get(ASName.k_Info);
        if (docInfo instanceof CosDictionary) {
            return (CosDictionary)docInfo;
        }
        return null;
    }

    public InputByteStream getStream(long start, long length) throws PDFIOException {
        try {
            return this.mBuf.slice(start, length);
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
    }

    public InputByteStream getStream() throws PDFIOException {
        try {
            return this.mBuf.slice();
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
    }

    InputByteStream getStreamRaw() {
        return this.mBuf;
    }

    public int getNumObjects() {
        return this.mNumObjects;
    }

    int getNumObjectsInternal() {
        return this.mObjectInfos.size();
    }

    public CosOpenOptions getOptions() {
        return this.mOptions;
    }

    public boolean isLinearized() {
        return this.mIsLinearized;
    }

    public boolean wasLinearized() {
        return this.mWasLinearized;
    }

    public boolean wasRepaired() {
        return !this.repairTypes.isEmpty() || this.documentCosLevelRepaired;
    }

    public EnumSet<REPAIRTYPE> getRepairTypes() {
        return this.repairTypes;
    }

    void setGarbageLength(long garbageLength) {
        this.garbageLength = garbageLength;
    }

    boolean forceCompress() {
        return this.mForceCompress;
    }

    XRefTable getXRef() {
        return this.mXRef;
    }

    CosObjectInfo getIndexedInfo(int index) {
        return (CosObjectInfo)this.mObjectInfos.get(index);
    }

    void putIndexedInfo(int index, CosObjectInfo info) {
        this.mObjectInfos.add(index, info);
    }

    void putRebuiltInfo(int index, CosObjectInfo info) {
        CosObjectInfo oldInfo;
        if (index >= this.mNumObjects) {
            this.mNumObjects = index + 1;
        }
        if ((oldInfo = this.getIndexedInfo(index)) == null) {
            this.putIndexedInfo(index, info);
        } else if (!oldInfo.isLoaded() && !oldInfo.isDirty()) {
            oldInfo.markAddressed();
            oldInfo.setObjGen(info.getObjGen());
            oldInfo.setPos(info.getPos());
        }
    }

    CosObjectInfo getObjectInfo(int objNum, int objGen) {
        if (objNum == 0 && objGen != 65535) {
            return null;
        }
        CosObjectInfo info = this.getIndexedInfo(objNum);
        if (objGen < 0) {
            return info;
        }
        if (info != null) {
            if (objNum != info.getObjNum() || objGen != info.getObjGen()) {
                info = null;
            }
        } else {
            info = new CosObjectInfo(this, objNum, objGen);
            this.putIndexedInfo(objNum, info);
        }
        return info;
    }

    CosObjectRef getObjectRef(CosObjectInfo info) {
        CosObjectRef ref = info.getRef();
        if (ref == null) {
            ref = new CosObjectRef(this, info);
            info.setRef(ref);
        }
        return ref;
    }

    CosObjectInfo newObjectInfo() {
        return this.getObjectInfo(this.mNumObjects++, 0);
    }

    public void setFDFDocument(Object fdfDocument) {
        this.mUserData[1] = fdfDocument;
    }

    public Object getFdfDocument() {
        return this.mUserData[1];
    }

    public void setPDFDocument(Object pdfdocument) {
        this.mUserData[0] = pdfdocument;
    }

    public Object getPdfDocument() {
        return this.mUserData[0];
    }

    CosObject resolveReference(CosObjectRef ref) throws PDFCosParseException, IOException, PDFSecurityException, PDFIOException {
        CosObjectInfo refInfo = ref.getInfo();
        CosObject result = refInfo.getObject();
        if (result == null) {
            result = this.getIndirectObject(refInfo);
        }
        if (result == null) {
            result = this.createCosNull();
        }
        return result;
    }

    void buildHeaderString(String version) {
        int vindx;
        StringBuilder result = new StringBuilder("%PDF-");
        result.append(version);
        result.append("\r%");
        result.append('\u00e2').append('\u00e3').append('\u00cf').append('\u00d3').append("\r\n");
        if (this.mHeaderToken != null) {
            result.append('%').append(this.mHeaderToken).append("\r\n");
        }
        if ((vindx = result.indexOf("1.")) > 0) {
            this.mHeader = result.toString();
        }
    }

    public void freeDuplicateResources() throws PDFCosParseException, PDFIOException, PDFSecurityException {
        CosPDFOptimizer pdfOptimizer = CosPDFOptimizer.newInstance(this);
        try {
            pdfOptimizer.freeDuplicateResources();
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
    }

    public boolean freeUnreferencedObjects() throws PDFCosParseException, PDFIOException, PDFSecurityException {
        CosContainer[] roots = new CosContainer[]{this.getRoot(), this.getInfo(), this.getEncryptionDictionary(), this.getTrailer()};
        try {
            return CosOptimizer.freeUnreferencedObjects(this, roots, false);
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
    }

    public CosObject[] getUnreferencedObjects() throws PDFCosParseException, PDFIOException, PDFSecurityException {
        CosContainer[] roots = new CosContainer[]{this.getRoot(), this.getInfo(), this.getEncryptionDictionary(), this.getTrailer()};
        try {
            return CosOptimizer.getUnreferencedObjects(this, roots);
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
    }

    /*
     * Loose catch block
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     * Lifted jumps to return sites
     */
    public void save(ByteWriter byteWriter, CosSaveParams params) throws PDFCosParseException, PDFInvalidParameterException, PDFIOException, PDFSecurityException {
        OutputByteStream outputByteStream = null;
        try {
            block33 : {
                try {
                    CosObjectStream objStm;
                    CosList objStmInfos;
                    CosObjectInfo stmInfo;
                    Iterator iter;
                    long timer = 0;
                    if (mLoggingPath != null) {
                        timer = System.currentTimeMillis();
                    }
                    long base = 0;
                    String style = null;
                    CosList saveObjectInfos = null;
                    this.mCompObjInfos = new CosList();
                    if (byteWriter == this.mByteReader) {
                        byteWriter = null;
                    }
                    params = this.normalizeParams(params);
                    int saveStyle = params.getSaveStyle();
                    if (this.mSaveToCopy || this.mIsFDF) {
                        saveObjectInfos = this.cloneObjectInfos();
                    }
                    if (byteWriter != null) {
                        outputByteStream = this.getStreamManager().getOutputByteStream(byteWriter);
                    }
                    if (saveStyle == 1) {
                        if (byteWriter == null) {
                            byteWriter = this.getInPlaceByteWriter();
                            if (byteWriter == null) {
                                throw new PDFInvalidParameterException("In-place incremental save requires ByteWriter as source ByteReader");
                            }
                            if (this.mBuf != null && mLoggingPath != null) {
                                base = this.mBuf.length();
                            }
                            style = "In-place incremental save";
                            outputByteStream = this.getStreamManager().getOutputByteStream(byteWriter);
                        } else {
                            style = "Incremental save";
                        }
                        if (this.repairTypes.contains((Object)REPAIRTYPE.xrefRepair)) {
                            throw new PDFInvalidParameterException("File cannot be saved incrementally if xref in original PDF stream was damaged.");
                        }
                        this.incrementalSave(outputByteStream, params, byteWriter);
                    } else if (saveStyle == 2) {
                        style = "Full save";
                        this.fullSave(outputByteStream, params);
                    } else if (saveStyle == 3) {
                        this.linearSave(outputByteStream, params);
                        style = params.getTempByteWriter() != null ? "Linear save with temp file" : "Linear save without temp file";
                    } else {
                        style = "Full save";
                        this.fullSave(outputByteStream, params);
                    }
                    if (!(params.getCloseAfterSave() || this.mSaveToCopy || this.mIsFDF)) {
                        objStmInfos = this.getObjStmInfos();
                        iter = objStmInfos.iterator();
                        while (iter.hasNext()) {
                            stmInfo = (CosObjectInfo)iter.next();
                            objStm = (CosObjectStream)stmInfo.getObject();
                            objStm.update();
                        }
                        outputByteStream.flush();
                        this.postSaveCleanup(outputByteStream, byteWriter);
                        this.getEncryption().setDecryptionAsEncryption();
                    }
                    if (this.mSaveToCopy || this.mIsFDF) {
                        this.restoreObjectInfos(saveObjectInfos);
                        objStmInfos = this.getObjStmInfos();
                        iter = objStmInfos.iterator();
                        while (iter.hasNext()) {
                            stmInfo = (CosObjectInfo)iter.next();
                            objStm = (CosObjectStream)stmInfo.getObject();
                            objStm.update();
                        }
                    }
                    if (mLoggingPath == null) break block33;
                    timer = System.currentTimeMillis() - timer;
                    StringBuilder styleBuilder = new StringBuilder(style);
                    styleBuilder.append(" took ").append(timer).append("ms");
                    if (this.mBuf != null) {
                        styleBuilder.append(", ").append(this.mBuf.length() - base).append(" bytes");
                    }
                    CosDocument.LogString(styleBuilder.toString());
                }
                catch (IOException e) {
                    throw new PDFIOException(e);
                }
            }
            Object var16_14 = null;
            boolean bl = this.mIsLinearized = params.getSaveStyle() == 3;
            if (params.getSaveStyle() != 1) {
                this.mWasLinearized = this.mIsLinearized;
            }
            this.mCompObjInfos = null;
            params.setTempByteWriter(null);
            if (params.getCloseAfterSave()) {
                this.close();
            }
            if (!params.getCloseAfterSave()) {
                if (!this.mSaveToCopy) return;
            }
            if (outputByteStream == null) return;
            outputByteStream.close();
            return;
            catch (IOException e) {
                throw new PDFIOException(e);
            }
        }
        catch (Throwable throwable) {
            Object var16_15 = null;
            boolean bl = this.mIsLinearized = params.getSaveStyle() == 3;
            if (params.getSaveStyle() != 1) {
                this.mWasLinearized = this.mIsLinearized;
            }
            this.mCompObjInfos = null;
            params.setTempByteWriter(null);
            if (params.getCloseAfterSave()) {
                this.close();
            }
            if (!params.getCloseAfterSave()) {
                if (!this.mSaveToCopy) throw throwable;
            }
            if (outputByteStream == null) throw throwable;
            try {}
            catch (IOException e) {
                throw new PDFIOException(e);
            }
            outputByteStream.close();
            throw throwable;
        }
    }

    /*
     * Loose catch block
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     * Lifted jumps to return sites
     */
    static void LogString(String logItem) {
        if (mLoggingPath == null) return;
        RandomAccessFile logFile = null;
        try {
            try {
                logFile = new RandomAccessFile(new File(mLoggingPath + "CosDocument.log"), "rw");
                logFile.seek(logFile.length());
                logFile.writeBytes(logItem + "\r\n");
            }
            catch (Exception e) {
                throw new RuntimeException("Cannot make logger entry", e);
            }
            Object var4_2 = null;
            if (logFile == null) return;
            logFile.close();
            return;
            catch (IOException e) {
                throw new RuntimeException("Error closing log file", e);
            }
        }
        catch (Throwable throwable) {
            Object var4_3 = null;
            if (logFile == null) throw throwable;
            try {}
            catch (IOException e) {
                throw new RuntimeException("Error closing log file", e);
            }
            logFile.close();
            throw throwable;
        }
    }

    private CosList cloneObjectInfos() {
        CosList cloneList = new CosList();
        int end = this.mObjectInfos.size();
        for (int i = 0; i < end; ++i) {
            CosObjectInfo info = (CosObjectInfo)this.mObjectInfos.get(i);
            if (info == null) continue;
            CosObjectInfo clone = new CosObjectInfo(this, 0, 0);
            clone.copyValuesFrom(info);
            cloneList.add(i, clone);
        }
        return cloneList;
    }

    private void restoreObjectInfos(CosList savedInfos) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        int end = savedInfos.size();
        while (this.mObjectInfos.size() > end) {
            this.mObjectInfos.delete(this.mObjectInfos.size() - 1);
        }
        for (int i = 0; i < end; ++i) {
            CosObjectInfo info = (CosObjectInfo)this.mObjectInfos.get(i);
            if (info == null) continue;
            CosObjectInfo clone = (CosObjectInfo)savedInfos.get(i);
            info.copyValuesFrom(clone);
        }
        this.mNumObjects = end;
        this.mRoot = null;
    }

    CosList getObjStmInfos() {
        CosList objStmInfos = new CosList();
        Iterator iter = this.mObjectInfos.iterator();
        while (iter.hasNext()) {
            CosObjectInfo info = (CosObjectInfo)iter.next();
            if (!info.isObjStm() || info.isFree()) continue;
            objStmInfos.add(info);
        }
        return objStmInfos;
    }

    boolean willBeCompressed(int objNum) {
        if (this.mCompObjInfos == null) {
            return false;
        }
        return this.mCompObjInfos.containsIndex(objNum);
    }

    public static void setLoggingPath(String loggingPath) {
        mLoggingPath = loggingPath;
    }

    public static String getLoggingPath() {
        return mLoggingPath;
    }

    public ByteWriter getInPlaceByteWriter() {
        if (this.mByteReader instanceof ByteWriter && this.mOptions.getSaveInPlace()) {
            return (ByteWriter)this.mByteReader;
        }
        return null;
    }

    public ByteReader getByteReader() {
        return this.mByteReader;
    }

    public void setNextIncrementalSectionOffset(long nextIncrementalSectionOffset) {
        this.nextIncrementalSectionOffset = nextIncrementalSectionOffset;
    }

    private void updateDocumentStream(OutputByteStream outputByteStream, boolean inPlaceSave) throws PDFCosParseException, PDFSecurityException, PDFIOException {
        try {
            if (inPlaceSave) {
                outputByteStream.seek(this.nextIncrementalSectionOffset);
            } else {
                IO.copy((InputByteStream)this.mBuf, (long)0, (long)this.nextIncrementalSectionOffset, (OutputByteStream)outputByteStream);
            }
            InputByteStream mBufCopy = this.mBuf.slice(0, this.nextIncrementalSectionOffset);
            this.mBuf.close();
            this.mBuf = mBufCopy;
            this.mXRef.resetXRef(this.mBuf);
            this.nextIncrementalSectionOffset = -1;
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
    }

    private void incrementalSave(OutputByteStream outputByteStream, CosSaveParams params, ByteWriter byteWriter) throws PDFCosParseException, PDFInvalidParameterException, IOException, PDFIOException, PDFSecurityException {
        if (this.mBuf == null) {
            throw new PDFInvalidParameterException("Incremental save can be used with existing files only");
        }
        if (this.documentCosLevelRepaired) {
            this.documentCosLevelRepaired = false;
            if (this.cosRepairList != null) {
                this.cosRepairList.clear();
            }
        }
        int xrefstyle = params.getXrefStyle();
        this.getEncryption().setupEncryption();
        if (byteWriter != this.mByteReader) {
            this.mBuf.seek(0);
            if (this.nextIncrementalSectionOffset != -1) {
                this.updateDocumentStream(outputByteStream, false);
            } else {
                IO.copy((InputByteStream)this.mBuf, (long)0, (long)(this.mBuf.length() - this.garbageLength), (OutputByteStream)outputByteStream);
            }
        } else if (this.nextIncrementalSectionOffset != -1) {
            this.updateDocumentStream(outputByteStream, true);
        } else {
            outputByteStream.seek(outputByteStream.length() - this.garbageLength);
        }
        if (this.garbageLength > 0) {
            outputByteStream.write(13);
            outputByteStream.write(10);
        }
        CosArray updateID = this.createUpdateDocID(false);
        this.getTrailer().put(ASName.k_ID, updateID);
        CosOptimizer.freeUnreferencedObjectsIncremental(this, this.mOrigNumObjects);
        CosList dirtyCompObjInfos = this.buildCompObjList(xrefstyle);
        Iterator iter = dirtyCompObjInfos.iterator();
        while (iter.hasNext()) {
            CosList stmObjList = (CosList)iter.next();
            CosObjectStream newStm = this.createCosObjectStream();
            newStm.setObjectStreamList(stmObjList);
        }
        CosList dirtyObjectInfos = this.buildObjectList(true);
        if (dirtyObjectInfos.isEmpty()) {
            return;
        }
        CosList stripped = null;
        CosList updateInfos = null;
        long curpos = outputByteStream.getPosition();
        if (xrefstyle == 3) {
            updateInfos = this.prepareHybridInfoList(dirtyObjectInfos, null, null);
            stripped = dirtyObjectInfos;
        } else {
            stripped = dirtyObjectInfos.copy();
            iter = stripped.iterator();
            while (iter.hasNext()) {
                CosObjectInfo info = (CosObjectInfo)iter.next();
                int objNum = info.getObjNum();
                if (!info.isCompressed() && !this.mCompObjInfos.containsIndex(objNum)) continue;
                iter.remove();
            }
        }
        curpos = this.writeIndirectObjects(stripped, outputByteStream, params.getSaveToCopy());
        long paddedDataLength = outputByteStream.length() - outputByteStream.getPosition();
        if (paddedDataLength > 0) {
            byte[] spacePadding = new byte[(int)paddedDataLength];
            Arrays.fill(spacePadding, 32);
            outputByteStream.write(spacePadding);
            curpos = outputByteStream.getPosition();
        }
        long xrefPos = curpos;
        long lastXrefPos = 0;
        ArrayList sections = this.prepareXRef(dirtyObjectInfos, false);
        if (xrefstyle == 1) {
            this.writeXRefTable(sections, outputByteStream);
            CosDictionary trailer = this.createCosDictionary(0);
            this.copyTrailerFields(trailer, this.getNumObjects());
            lastXrefPos = this.mXRef.getLastXRefSectionPosition();
            trailer.put(ASName.k_Prev, lastXrefPos);
            this.writeTrailer(trailer, outputByteStream);
            if (!this.mSaveToCopy) {
                this.mTrailer = trailer;
            }
            this.writeEOF(xrefPos, outputByteStream);
        } else {
            if (xrefstyle == 2) {
                this.buildXRefStream(sections, outputByteStream, null);
                try {
                    outputByteStream.write(StringOps.toByteArray("startxref\n"));
                    outputByteStream.write(StringOps.toByteArray(Long.toString(xrefPos)));
                    outputByteStream.write(StringOps.toByteArray("\n%%EOF\n"));
                }
                catch (IOException e) {
                    throw new PDFIOException("Unable to write the XRef.", e);
                }
            }
            if (xrefstyle == 3) {
                CosObjectInfo info;
                this.writeXRefTable(sections, outputByteStream);
                CosDictionary trailer = this.createCosDictionary(0);
                this.copyTrailerFields(trailer, this.getNumObjects());
                lastXrefPos = this.mXRef.getLastXRefSectionPosition();
                trailer.put(ASName.k_Prev, lastXrefPos);
                this.writeTrailer(trailer, outputByteStream);
                if (updateInfos.isEmpty()) {
                    this.writeEOF(xrefPos, outputByteStream);
                    return;
                }
                int xindx = updateInfos.size() - 1;
                CosObjectInfo xinfo = (CosObjectInfo)updateInfos.get(xindx);
                CosStream xrefstm = (CosStream)xinfo.getObject();
                xrefstm.put(ASName.k_Prev, xrefPos);
                stripped = updateInfos.copy();
                iter = stripped.iterator();
                while (iter.hasNext()) {
                    CosObjectInfo info2 = (CosObjectInfo)iter.next();
                    if (!info2.isCompressed() && info2 != xinfo) continue;
                    iter.remove();
                }
                long updatexrefpos = this.writeIndirectObjects(stripped, outputByteStream, params.getSaveToCopy());
                ArrayList<CosList> hybridSections = new ArrayList<CosList>();
                int sectionindx = 0;
                hybridSections.add(sectionindx, new CosList());
                int lastObjNum = 0;
                CosList seclist = (CosList)hybridSections.get(sectionindx);
                iter = updateInfos.iterator();
                while (iter.hasNext()) {
                    info = (CosObjectInfo)iter.next();
                    int thisObjNum = info.getObjNum();
                    if (thisObjNum - lastObjNum != 1 && lastObjNum != 0) {
                        seclist = new CosList();
                        hybridSections.add(++sectionindx, seclist);
                    }
                    seclist.add(info);
                    lastObjNum = thisObjNum;
                }
                CosArray indexVal = this.createCosArray();
                for (CosList nextsec : hybridSections) {
                    CosObjectInfo firstObjInfo = (CosObjectInfo)nextsec.get(0);
                    int firstObjNum = firstObjInfo.getObjNum();
                    int secsize = nextsec.size();
                    indexVal.addInt(firstObjNum);
                    indexVal.addInt(secsize);
                }
                xrefstm.put(ASName.k_Index, indexVal);
                int[] widths = this.setWidthsArray(updateInfos, xrefstm, outputByteStream.getPosition());
                OutputByteStream buf = this.getStreamManager().getOutputByteStreamClearDocument(ByteWriterFactory.Fixed.GROWABLE, -1);
                Iterator iterator = updateInfos.iterator();
                while (iterator.hasNext()) {
                    info = (CosObjectInfo)iterator.next();
                    info.writeXRefStreamEntry(buf, widths);
                }
                xrefstm.newDataDecoded(buf.closeAndConvert());
                try {
                    updatexrefpos = xinfo.writeIndirectObject(outputByteStream, updatexrefpos);
                    outputByteStream.write(StringOps.toByteArray("xref\n"));
                }
                catch (PDFIOException e) {
                    throw new PDFIOException("Unable to write the XRef stream.", e);
                }
                try {
                    outputByteStream.write(48);
                    outputByteStream.write(32);
                    outputByteStream.write(48);
                    outputByteStream.write(32);
                    outputByteStream.write(10);
                }
                catch (IOException e) {
                    throw new PDFIOException("Unable to write the header info.", e);
                }
                long xstmPos = xinfo.getPos();
                CosDictionary updateTrailer = this.createCosDictionary(0);
                this.copyTrailerFields(updateTrailer, this.getNumObjects());
                updateTrailer.put(ASName.k_Prev, xrefPos);
                updateTrailer.put(ASName.k_XRefStm, xstmPos);
                this.writeTrailer(updateTrailer, outputByteStream);
                if (!this.mSaveToCopy) {
                    this.mTrailer = updateTrailer;
                }
                this.writeEOF(updatexrefpos, outputByteStream);
            }
        }
    }

    private void fullSave(OutputByteStream outputByteStream, CosSaveParams params) throws PDFCosParseException, PDFInvalidParameterException, IOException, PDFIOException, PDFSecurityException {
        CosDictionary trailer;
        try {
            outputByteStream.write(StringOps.toByteArray(this.mHeader));
        }
        catch (IOException e) {
            throw new PDFIOException("Unable to write the header.", e);
        }
        if (this.mIsFDF) {
            this.getRoot().remove(ASName.k_Type);
        }
        CosArray updatedID = this.createUpdateDocID(false);
        this.getTrailer().put(ASName.k_ID, updatedID);
        int xrefstyle = params.getXrefStyle();
        this.getEncryption().setupEncryption();
        CosContainer[] roots = new CosContainer[]{this.getRoot(), this.getInfo(), this.getEncryptionDictionary(), null};
        long lastXrefPos = 0;
        if (!this.mXRef.isNew()) {
            if (this.mXRef.getType() == 2) {
                CosDictionary trailer2 = this.getTrailer();
                if (trailer2.containsKey(ASName.k_XRefStm)) {
                    lastXrefPos = trailer2.getInt(ASName.k_XRefStm).intValue();
                }
            } else if (this.mXRef.getType() == 1) {
                lastXrefPos = this.mXRef.getLastXRefSectionPosition();
            }
        }
        if (lastXrefPos == 0) {
            roots[3] = this.getTrailer();
        }
        CosOptimizer.freeUnreferencedObjects(this, roots, true);
        this.mCompObjInfos = this.buildFullSaveCompList(xrefstyle);
        CosList objStmInfos = this.getObjStmInfos();
        Iterator iter = objStmInfos.iterator();
        Iterator compIter = this.mCompObjInfos.iterator();
        CosObjectStream curObjStm = null;
        int curIndex = 200;
        while (compIter.hasNext()) {
            CosObjectInfo info = (CosObjectInfo)compIter.next();
            CosObject obj = info.getObject();
            if (curIndex == 200) {
                curIndex = 0;
                if (iter != null && iter.hasNext()) {
                    CosObjectInfo stmInfo = (CosObjectInfo)iter.next();
                    curObjStm = (CosObjectStream)stmInfo.getObject();
                    curObjStm.remove(ASName.k_Extends);
                } else {
                    iter = null;
                    curObjStm = this.createCosObjectStream();
                }
            }
            curObjStm.addObjectToStream(obj);
            ++curIndex;
        }
        CosList objStmsToBeDeleted = new CosList();
        if (iter != null) {
            while (iter.hasNext()) {
                CosObjectInfo stmInfo = (CosObjectInfo)iter.next();
                objStmsToBeDeleted.add(stmInfo.getObjNum(), stmInfo);
            }
        }
        CosList stripped = null;
        CosList updateInfos = null;
        CosList objectInfos = this.buildObjectList(false);
        if (xrefstyle == 3) {
            updateInfos = this.prepareHybridInfoList(objectInfos, this.mCompObjInfos, objStmsToBeDeleted);
            stripped = objectInfos;
        } else {
            stripped = objectInfos.copy();
            iter = stripped.iterator();
            while (iter.hasNext()) {
                CosObjectInfo info = (CosObjectInfo)iter.next();
                int objNum = info.getObjNum();
                if (!this.mCompObjInfos.containsIndex(objNum) && !objStmsToBeDeleted.containsIndex(objNum)) continue;
                iter.remove();
            }
        }
        long xrefPos = this.writeIndirectObjects(stripped, outputByteStream, params.getSaveToCopy());
        CosDictionary encryptDict = null;
        if (this.needsEncryption()) {
            Map encryptData = this.getEncryption().getEncryptionMap();
            if (encryptData == null) {
                throw new PDFInvalidParameterException("New encryption data not provided.");
            }
            encryptDict = this.createCosDictionaryFromNonCosData(encryptData);
            encryptDict.setEncryptionState(false);
            CosObjectInfo encryptInfo = encryptDict.getInfo();
            if (encryptInfo != null) {
                xrefPos = encryptInfo.writeIndirectObject(outputByteStream, xrefPos);
                objectInfos.add(encryptInfo.getObjNum(), encryptInfo);
            }
        }
        if (objStmsToBeDeleted.isEmpty()) {
            stripped = objectInfos;
        } else {
            stripped = objectInfos.copy();
            iter = stripped.iterator();
            while (iter.hasNext()) {
                CosObjectInfo info = (CosObjectInfo)iter.next();
                int objNum = info.getObjNum();
                if (!objStmsToBeDeleted.containsIndex(objNum)) continue;
                iter.remove();
            }
        }
        ArrayList sections = this.prepareXRef(stripped, true);
        if (!this.needsEncryption()) {
            this.removeEncryptionDictionary();
        } else {
            this.setEncryptionDictionary(encryptDict);
        }
        if (xrefstyle == 1) {
            if (!this.mIsFDF) {
                this.writeXRefTable(sections, outputByteStream);
            }
            trailer = this.createCosDictionary(0);
            this.copyTrailerFields(trailer, this.getNumObjects());
            this.writeTrailer(trailer, outputByteStream);
            if (!this.mSaveToCopy) {
                this.mTrailer = trailer;
            }
            if (this.mIsFDF) {
                outputByteStream.write(StringOps.toByteArray("%%EOF\n"));
            } else {
                this.writeEOF(xrefPos, outputByteStream);
            }
        } else {
            if (xrefstyle == 2) {
                this.buildXRefStream(sections, outputByteStream, objStmsToBeDeleted);
                try {
                    outputByteStream.write(StringOps.toByteArray("startxref\n"));
                    outputByteStream.write(StringOps.toByteArray(Long.toString(xrefPos)));
                    outputByteStream.write(StringOps.toByteArray("\n%%EOF\n"));
                }
                catch (IOException e) {
                    throw new PDFIOException("Unable to write XRef.", e);
                }
            }
            if (xrefstyle == 3) {
                CosObjectInfo info;
                this.writeXRefTable(sections, outputByteStream);
                trailer = this.createCosDictionary(0);
                this.copyTrailerFields(trailer, this.getNumObjects());
                this.writeTrailer(trailer, outputByteStream);
                if (updateInfos.isEmpty()) {
                    iter = objStmsToBeDeleted.iterator();
                    while (iter.hasNext()) {
                        CosObjectInfo stmInfo = (CosObjectInfo)iter.next();
                        stmInfo.markFree();
                    }
                    this.writeEOF(xrefPos, outputByteStream);
                    return;
                }
                int xindx = updateInfos.size() - 1;
                CosObjectInfo xinfo = (CosObjectInfo)updateInfos.get(xindx);
                CosStream xrefstm = (CosStream)xinfo.getObject();
                xrefstm.put(ASName.k_Prev, xrefPos);
                stripped = updateInfos.copy();
                iter = stripped.iterator();
                while (iter.hasNext()) {
                    CosObjectInfo info2 = (CosObjectInfo)iter.next();
                    if (info2.isObjStm()) continue;
                    iter.remove();
                }
                long updatexrefpos = this.writeIndirectObjects(stripped, outputByteStream, params.getSaveToCopy());
                ArrayList<CosList> hybridSections = new ArrayList<CosList>();
                int sectionindx = 0;
                hybridSections.add(sectionindx, new CosList());
                int lastObjNum = 0;
                CosList seclist = (CosList)hybridSections.get(sectionindx);
                iter = updateInfos.iterator();
                while (iter.hasNext()) {
                    info = (CosObjectInfo)iter.next();
                    int thisObjNum = info.getObjNum();
                    if (thisObjNum - lastObjNum != 1 && lastObjNum != 0) {
                        seclist = new CosList();
                        hybridSections.add(++sectionindx, seclist);
                    }
                    seclist.add(info);
                    lastObjNum = thisObjNum;
                }
                CosArray indexVal = this.createCosArray();
                for (CosList nextsec : hybridSections) {
                    CosObjectInfo firstObjInfo = (CosObjectInfo)nextsec.get(0);
                    int firstObjNum = firstObjInfo.getObjNum();
                    int secsize = nextsec.size();
                    indexVal.addInt(firstObjNum);
                    indexVal.addInt(secsize);
                }
                xrefstm.put(ASName.k_Index, indexVal);
                xrefstm.getInfo().setPos(outputByteStream.getPosition());
                int[] widths = this.setWidthsArray(updateInfos, xrefstm, outputByteStream.getPosition());
                OutputByteStream buf = this.getStreamManager().getOutputByteStreamClearDocument(ByteWriterFactory.Fixed.GROWABLE, -1);
                Iterator iterator = updateInfos.iterator();
                while (iterator.hasNext()) {
                    info = (CosObjectInfo)iterator.next();
                    info.writeXRefStreamEntry(buf, widths);
                }
                xrefstm.newDataDecoded(buf.closeAndConvert());
                try {
                    updatexrefpos = xinfo.writeIndirectObject(outputByteStream, updatexrefpos);
                    outputByteStream.write(StringOps.toByteArray("xref\n"));
                }
                catch (PDFIOException e) {
                    throw new PDFIOException("Unable to write the XRef Stream.", e);
                }
                try {
                    outputByteStream.write(48);
                    outputByteStream.write(32);
                    outputByteStream.write(48);
                    outputByteStream.write(32);
                    outputByteStream.write(10);
                }
                catch (IOException e) {
                    throw new PDFIOException("Unable to write the empty XRef section.", e);
                }
                long xstmPos = xinfo.getPos();
                CosDictionary updateTrailer = this.createCosDictionary(0);
                this.copyTrailerFields(updateTrailer, this.getNumObjects());
                updateTrailer.put(ASName.k_Prev, xrefPos);
                updateTrailer.put(ASName.k_XRefStm, xstmPos);
                this.writeTrailer(updateTrailer, outputByteStream);
                if (!this.mSaveToCopy) {
                    this.mTrailer = updateTrailer;
                }
                this.writeEOF(updatexrefpos, outputByteStream);
            }
        }
        iter = objStmsToBeDeleted.iterator();
        while (iter.hasNext()) {
            CosObjectInfo stmInfo = (CosObjectInfo)iter.next();
            stmInfo.markFree();
        }
    }

    /*
     * Unable to fully structure code
     * Enabled aggressive block sorting
     * Lifted jumps to return sites
     */
    private CosList buildFullSaveCompList(int xrefStyle) throws PDFCosParseException, PDFIOException, PDFSecurityException, IOException {
        compObjList = new CosList();
        if (xrefStyle != 3) ** GOTO lbl43
        obj = this.getRoot().get(ASName.k_StructTreeRoot);
        if (obj == null) return compObjList;
        compObjList = new CosList();
        stateStackPtr = 0;
        stateStack = new Object[65536];
        container = null;
        containerIter = null;
        block0 : do {
            if (obj == null || obj instanceof CosNull || obj instanceof CosStream) ** GOTO lbl25
            objNum = obj.getObjNum();
            if (objNum == 0) ** GOTO lbl16
            if (compObjList.get(objNum) == null) {
                compObjList.add(objNum, obj.getInfo());
lbl16: // 2 sources:
                if (obj instanceof CosContainer) {
                    if (containerIter != null) {
                        stateStack[stateStackPtr++] = container;
                        stateStack[stateStackPtr++] = containerIter;
                    }
                    if ((container = (CosContainer)obj) instanceof CosArray) {
                        containerIter = ((CosArray)container).iterator();
                    } else {
                        keys = ((CosDictionary)container).getKeys();
                        containerIter = keys.iterator();
                    }
                }
            }
lbl25: // 7 sources:
            do {
                if (containerIter == null) {
                    return compObjList;
                }
                while (!containerIter.hasNext()) {
                    if (stateStackPtr == 0) {
                        return compObjList;
                    }
                    containerIter = (Iterator)stateStack[--stateStackPtr];
                    container = (CosContainer)stateStack[--stateStackPtr];
                }
                if (container instanceof CosArray) {
                    obj = (CosObject)containerIter.next();
                    continue block0;
                }
                key = (ASName)containerIter.next();
                obj = null;
            } while (key == ASName.k_Pg);
            if (key == ASName.k_P || key == ASName.k_Stm || key == ASName.k_StmOwn || key == ASName.k_Obj) continue;
            obj = ((CosDictionary)container).get(key);
        } while (true);
lbl43: // 1 sources:
        if (xrefStyle != 2) return compObjList;
        compObjList = new CosList();
        catalog = this.getRoot();
        encrypt = this.getEncryptionDictionary();
        iter = this.mObjectInfos.iterator();
        while (iter.hasNext() != false) {
            info = (CosObjectInfo)iter.next();
            obj = info.getObject();
            if (obj == null || obj instanceof CosStream || obj == catalog || obj == encrypt || obj instanceof CosDictionary && (type = ((CosDictionary)obj).get(ASName.k_Type)) instanceof CosName && CosDocument.dictionariesNotToBeCompressed.contains(type.nameValue())) continue;
            compObjList.add(info.getObjNum(), info);
        }
        return compObjList;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    private void linearSave(OutputByteStream outputByteStream, CosSaveParams params) throws PDFCosParseException, PDFInvalidParameterException, IOException, PDFIOException, PDFSecurityException {
        CosDictionary trailer;
        long hintStmPos;
        CosObjectInfo objInfo;
        int HEADER_OVERHEAD_TABLE = 400;
        int HEADER_OVERHEAD_STREAM = 500;
        int HEADER_OVERHEAD_HYBRID = 500;
        CosArray updatedID = this.createUpdateDocID(false);
        this.getTrailer().put(ASName.k_ID, updatedID);
        int xrefstyle = params.getXrefStyle();
        this.mCosLin = new CosLinearization(this);
        this.mCosLin.buildLinearizationData(xrefstyle);
        this.getEncryption().setupEncryption();
        CosStream mainXRefStm = null;
        CosObjectInfo mainXRefStmObjInfo = null;
        CosList mainObjInfos = this.mCosLin.getMainSectionList();
        CosList mainObjInfosCompressed = this.mCosLin.getMainSectionCompressedList();
        CosList updateObjInfos = this.mCosLin.getUpdateSectionList();
        CosList updateObjInfosCompressed = this.mCosLin.getUpdateSectionCompressedList();
        if (xrefstyle == 3 && mainObjInfosCompressed.isEmpty()) {
            xrefstyle = 1;
        }
        boolean haveXRefStms = xrefstyle == 2 || xrefstyle == 3;
        CosList oldToOldObjStmMap = null;
        if (this.mXRef.getType() == 1 || this.mXRef.getType() == 2) {
            oldToOldObjStmMap = new CosList();
            Iterator iter = this.mObjectInfos.iterator();
            while (iter.hasNext()) {
                CosObjectInfo objInfo2 = (CosObjectInfo)iter.next();
                CosObjectInfo objStmInfo = objInfo2.getStreamInfo();
                if (objStmInfo == null) continue;
                oldToOldObjStmMap.add(objStmInfo.getObjNum(), objStmInfo.getObject());
            }
        }
        CosList newInfosList = new CosList();
        newInfosList.addAll(mainObjInfos);
        if (haveXRefStms) {
            newInfosList.addAll(mainObjInfosCompressed);
            if (xrefstyle == 2) {
                mainXRefStm = this.createCosStream();
                mainXRefStmObjInfo = mainXRefStm.getInfo();
                newInfosList.add(mainXRefStmObjInfo);
            }
        }
        CosDictionary linDict = this.createCosDictionary();
        CosObjectInfo linDictObjInfo = linDict.getInfo();
        CosStream updateXRefStm = null;
        CosObjectInfo updateXRefStmObjInfo = null;
        if (haveXRefStms) {
            updateXRefStm = this.createCosStream();
            updateXRefStmObjInfo = updateXRefStm.getInfo();
        }
        CosStream hintStm = this.createCosStream();
        CosObjectInfo hintStmObjInfo = hintStm.getInfo();
        CosDictionary encryptDict = null;
        if (this.needsEncryption()) {
            Map encryptData = this.getEncryption().getEncryptionMap();
            if (encryptData == null) {
                throw new PDFInvalidParameterException("New encryption data not provided.");
            }
            encryptDict = this.createCosDictionaryFromNonCosData(encryptData);
            encryptDict.setEncryptionState(false);
            this.setEncryptionDictionary(encryptDict);
        } else {
            this.removeEncryptionDictionary();
        }
        int numSpecialObjs = 2;
        if (updateXRefStm != null) {
            ++numSpecialObjs;
        }
        if (encryptDict != null) {
            ++numSpecialObjs;
        }
        newInfosList.add(linDictObjInfo);
        if (updateXRefStm != null) {
            newInfosList.add(updateXRefStmObjInfo);
        }
        updateObjInfos.add(0, encryptDict == null ? null : encryptDict.getInfo());
        newInfosList.addAll(updateObjInfos);
        newInfosList.addAll(updateObjInfosCompressed);
        newInfosList.add(hintStmObjInfo);
        CosListInt newToOldObjNumMap = new CosListInt();
        CosListInt newToOldObjGenMap = new CosListInt();
        CosListInt oldToNewObjNumMap = new CosListInt();
        this.mNumObjects = newInfosList.size();
        HashMap<Integer, Integer> objectNumbersMap = new HashMap<Integer, Integer>();
        for (int i = 1; i < this.mNumObjects; ++i) {
            CosObjectInfo objInfo3 = (CosObjectInfo)newInfosList.get(i);
            newToOldObjNumMap.add(i, objInfo3.getObjNum());
            newToOldObjGenMap.add(i, objInfo3.getObjGen());
            oldToNewObjNumMap.add(objInfo3.getObjNum(), i);
            if (this.documentCosLevelRepaired && this.cosRepairList.isObjectRepaired(objInfo3.getObjNum())) {
                objectNumbersMap.put(objInfo3.getObjNum(), i);
            }
            objInfo3.setObjNum(i);
            objInfo3.setObjGen(0);
        }
        if (this.documentCosLevelRepaired && !objectNumbersMap.isEmpty()) {
            this.cosRepairList.updateObjectNumbers(objectNumbersMap);
        }
        this.mCosLin.setNewToOldObjNumMap(newToOldObjNumMap);
        this.mCosLin.setNewToOldObjGenMap(newToOldObjGenMap);
        this.mCosLin.setOldToOldObjStmMap(oldToOldObjStmMap);
        this.mCosLin.setOldToNewObjNumMap(oldToNewObjNumMap);
        this.mObjectInfos = newInfosList;
        OutputByteStream tempSaveOutStream = null;
        ByteWriter tempByteWriter = params.getTempByteWriter();
        tempSaveOutStream = tempByteWriter == null ? this.getStreamManager().getOutputByteStreamClearDocument(ByteWriterFactory.Fixed.GROWABLE, -1) : this.getStreamManager().getOutputByteStream(tempByteWriter);
        long curPos = this.writeIndirectObjects(updateObjInfos, tempSaveOutStream, params.getSaveToCopy());
        int updateLastObjNum = ((CosObjectInfo)updateObjInfos.last()).getObjNum();
        curPos = this.writeIndirectObjects(mainObjInfos, tempSaveOutStream, params.getSaveToCopy());
        int mainLastObjNum = ((CosObjectInfo)mainObjInfos.last()).getObjNum();
        long objEndPos = curPos;
        if (xrefstyle == 1) {
            hintStmPos = 400 + (updateObjInfos.size() + numSpecialObjs) * 20;
        } else if (xrefstyle == 2) {
            hintStmPos = 500 + (updateObjInfos.size() + numSpecialObjs) * 4;
            hintStmPos += (long)(updateObjInfosCompressed.size() * 4);
        } else {
            hintStmPos = 500 + (updateObjInfos.size() + numSpecialObjs) * 20;
            hintStmPos += (long)(mainObjInfosCompressed.size() * 4);
        }
        long hintStmLen = 0;
        this.mCosLin.buildHintStream(this.mObjectInfos, hintStm, mainLastObjNum, updateLastObjNum, hintStmPos, objEndPos);
        OutputByteStream hintStmOutBuf = this.getStreamManager().getOutputByteStreamClearDocument(ByteWriterFactory.Fixed.GROWABLE, -1);
        hintStmLen = hintStmObjInfo.writeIndirectObject(hintStmOutBuf, 0);
        Iterator linIter = updateObjInfos.iterator();
        while (linIter.hasNext()) {
            objInfo = (CosObjectInfo)linIter.next();
            objInfo.setPos(objInfo.getPos() + hintStmPos + hintStmLen);
        }
        linIter = mainObjInfos.iterator();
        while (linIter.hasNext()) {
            objInfo = (CosObjectInfo)linIter.next();
            objInfo.setPos(objInfo.getPos() + hintStmPos + hintStmLen);
        }
        outputByteStream.write(StringOps.toByteArray(this.mHeader));
        long linDictPos = 0;
        long updateXRefPos = 0;
        linDictPos = outputByteStream.getPosition();
        linDict.put(ASName.k_Linearized, 1);
        linDict.put(ASName.k_L, 1234567890);
        CosArray hintValues = this.createCosArray();
        hintValues.addInt((int)hintStmPos);
        hintValues.addInt((int)hintStmLen);
        linDict.put(ASName.k_H, hintValues);
        int specialPageObjNum = this.mCosLin.getSpecialPageObj().getObjNum();
        linDict.put(ASName.k_O, specialPageObjNum);
        int specialPageEnd = (int)((CosObjectInfo)mainObjInfos.get(1)).getPos();
        linDict.put(ASName.k_E, specialPageEnd);
        linDict.put(ASName.k_N, this.mCosLin.getNumPages());
        linDict.put(ASName.k_T, 1234567890);
        NullOutputByteStream scratchStm = new NullOutputByteStream();
        updateXRefPos = linDictPos + linDictObjInfo.writeIndirectObject((OutputByteStream)scratchStm, linDictPos);
        long linDictT = 0;
        long mainXRefPos = 0;
        CosObjectInfo freeInfo = this.getObjectInfo(0, 65535);
        mainXRefPos = hintStmPos + hintStmLen + curPos;
        if (xrefstyle == 1) {
            linDictT = this.linXRefTable(tempSaveOutStream, mainObjInfos);
            trailer = this.createCosDictionary(0);
            trailer.put(ASName.k_Size, mainObjInfos.size());
            trailer.put(ASName.k_ID, updatedID);
            if (encryptDict != null) {
                trailer.put(ASName.k_Encrypt, encryptDict);
            }
            this.writeTrailer(trailer, tempSaveOutStream);
            this.writeEOF(updateXRefPos, tempSaveOutStream);
        } else if (xrefstyle == 2) {
            mainObjInfosCompressed.add(mainXRefStmObjInfo);
            linIter = mainObjInfosCompressed.iterator();
            while (linIter.hasNext()) {
                CosObjectInfo info = (CosObjectInfo)linIter.next();
                mainObjInfos.add(info.getObjNum(), info);
            }
            linDictT = this.linXRefStream(tempSaveOutStream, mainXRefStmObjInfo, mainObjInfos, mainXRefPos, encryptDict, null, null, updatedID, 0, false);
            tempSaveOutStream.write(StringOps.toByteArray("startxref\n"));
            tempSaveOutStream.write(StringOps.toByteArray(Long.toString(updateXRefPos)));
            tempSaveOutStream.write(StringOps.toByteArray("\n%%EOF\n"));
        } else {
            int freeCount = mainObjInfosCompressed.size();
            while (freeCount-- != 0) {
                mainObjInfos.add(freeInfo);
            }
            linDictT = this.linXRefTable(tempSaveOutStream, mainObjInfos);
            CosDictionary trailer2 = this.createCosDictionary(0);
            trailer2.put(ASName.k_Size, mainObjInfos.size());
            trailer2.put(ASName.k_ID, updatedID);
            if (encryptDict != null) {
                trailer2.put(ASName.k_Encrypt, encryptDict);
            }
            this.writeTrailer(trailer2, tempSaveOutStream);
            this.writeEOF(updateXRefPos, tempSaveOutStream);
        }
        linDict.put(ASName.k_L, hintStmPos + hintStmLen + tempSaveOutStream.getPosition());
        linDict.put(ASName.k_T, hintStmPos + hintStmLen + linDictT);
        for (curPos = linDictObjInfo.writeIndirectObject((OutputByteStream)outputByteStream, (long)linDictPos); curPos < updateXRefPos - 1; ++curPos) {
            outputByteStream.write(32);
        }
        outputByteStream.write(10);
        updateObjInfos = this.copyInfoList(updateObjInfos);
        updateObjInfos.add(linDictObjInfo.getObjNum(), linDictObjInfo);
        linDictObjInfo.setPos(linDictPos);
        hintStmObjInfo.setPos(hintStmPos);
        mainObjInfosCompressed = this.copyInfoList(mainObjInfosCompressed);
        if (xrefstyle == 1) {
            updateObjInfos.add(hintStmObjInfo.getObjNum(), hintStmObjInfo);
            trailer = this.createCosDictionary(0);
            this.copyTrailerFields(trailer, this.mNumObjects);
            trailer.put(ASName.k_Prev, mainXRefPos);
            this.linXRefTable(outputByteStream, updateObjInfos);
            this.writeTrailer(trailer, outputByteStream);
            this.mTrailer = trailer;
            this.writeEOF(0, outputByteStream);
        } else if (xrefstyle == 2) {
            updateObjInfos.add(updateXRefStmObjInfo.getObjNum(), updateXRefStmObjInfo);
            updateXRefStmObjInfo.setPos(updateXRefPos);
            updateObjInfos.addAll(updateObjInfosCompressed);
            updateObjInfos.add(hintStmObjInfo.getObjNum(), hintStmObjInfo);
            this.linXRefStream(outputByteStream, updateXRefStmObjInfo, updateObjInfos, updateXRefPos, encryptDict, this.getRoot(), this.getInfo(), updatedID, mainXRefPos, true);
        } else {
            updateObjInfos.add(updateXRefStmObjInfo.getObjNum(), updateXRefStmObjInfo);
            updateObjInfos.add(hintStmObjInfo.getObjNum(), hintStmObjInfo);
            trailer = this.createCosDictionary(0);
            this.copyTrailerFields(trailer, this.mNumObjects);
            trailer.put(ASName.k_Prev, mainXRefPos);
            scratchStm.seek(0);
            this.linXRefTable((OutputByteStream)scratchStm, updateObjInfos);
            curPos = scratchStm.getPosition();
            trailer.put(ASName.k_XRefStm, updateXRefPos + curPos + 500);
            this.writeTrailer(trailer, (OutputByteStream)scratchStm);
            this.writeEOF(0, (OutputByteStream)scratchStm);
            curPos = scratchStm.getPosition();
            trailer.put(ASName.k_XRefStm, updateXRefPos + curPos);
            updateXRefStmObjInfo.setPos(updateXRefPos + curPos);
            this.linXRefTable(outputByteStream, updateObjInfos);
            this.writeTrailer(trailer, outputByteStream);
            this.mTrailer = trailer;
            this.writeEOF(0, outputByteStream);
            if (outputByteStream.getPosition() < updateXRefPos + curPos) {
                outputByteStream.write(10);
            }
            this.linXRefStream(outputByteStream, updateXRefStmObjInfo, mainObjInfosCompressed, updateXRefPos + curPos, encryptDict, null, null, null, 0, false);
        }
        for (curPos = outputByteStream.getPosition(); curPos < hintStmPos - 1; ++curPos) {
            outputByteStream.write(32);
        }
        outputByteStream.write(10);
        InputByteStream hintStmInBuf = null;
        try {
            hintStmInBuf = hintStmOutBuf.closeAndConvert();
            hintStmOutBuf = null;
            IO.copy((InputByteStream)hintStmInBuf, (OutputByteStream)outputByteStream);
            Object var59_55 = null;
            if (hintStmInBuf != null) {
                hintStmInBuf.close();
            }
        }
        catch (Throwable var58_57) {
            Object var59_56 = null;
            if (hintStmInBuf != null) {
                hintStmInBuf.close();
            }
            throw var58_57;
        }
        InputByteStream tempSaveInStream = tempSaveOutStream.closeAndConvert();
        tempSaveOutStream = null;
        IO.copy((InputByteStream)tempSaveInStream, (OutputByteStream)outputByteStream);
        tempSaveInStream.close();
    }

    private long linXRefTable(OutputByteStream os, CosList objInfos) throws IOException {
        CosObjectInfo objInfo;
        long retVal = 0;
        os.write(StringOps.toByteArray("xref\n"));
        int first = 0;
        int size = objInfos.size();
        if (size != 0) {
            objInfo = (CosObjectInfo)objInfos.first();
            first = objInfo.getObjNum();
            size -= first;
        }
        os.write(StringOps.toByteArray(Integer.toString(first)));
        os.write(32);
        os.write(StringOps.toByteArray(Integer.toString(size)));
        retVal = os.getPosition();
        os.write(10);
        Iterator iter = objInfos.iterator();
        while (iter.hasNext()) {
            objInfo = (CosObjectInfo)iter.next();
            objInfo.writeXRefTableEntry(os);
        }
        return retVal;
    }

    private long linXRefStream(OutputByteStream os, CosObjectInfo xrStmObjInfo, CosList objInfos, long curPos, CosDictionary encrypt, CosDictionary root, CosDictionary info, CosArray id, long prev, boolean setTrailer) throws PDFCosParseException, IOException, PDFIOException, PDFSecurityException {
        CosObjectInfo objInfo;
        long retVal = os.getPosition() - 1;
        xrStmObjInfo.setPos(curPos);
        CosStream xrefStm = (CosStream)xrStmObjInfo.getObject();
        int first = 0;
        int size = objInfos.size();
        if (size != 0) {
            objInfo = (CosObjectInfo)objInfos.first();
            first = objInfo.getObjNum();
            size -= first;
        }
        xrefStm.put(ASName.k_Type, ASName.k_XRef);
        xrefStm.put(ASName.k_Size, first + size);
        xrefStm.put(ASName.k_Filter, ASName.k_FlateDecode);
        CosArray iValues = this.createCosArray();
        iValues.addInt(first);
        iValues.addInt(size);
        xrefStm.put(ASName.k_Index, iValues);
        if (encrypt != null) {
            xrefStm.put(ASName.k_Encrypt, encrypt);
        }
        if (root != null) {
            xrefStm.put(ASName.k_Root, root);
        }
        if (info != null) {
            xrefStm.put(ASName.k_Info, info);
        }
        if (id != null) {
            xrefStm.put(ASName.k_ID, id);
        }
        if (prev != 0) {
            xrefStm.put(ASName.k_Prev, prev);
        }
        int[] widths = this.setWidthsArray(objInfos, xrefStm, curPos);
        OutputByteStream buf = this.getStreamManager().getOutputByteStreamClearDocument(ByteWriterFactory.Fixed.GROWABLE, -1);
        Iterator iter = objInfos.iterator();
        while (iter.hasNext()) {
            objInfo = (CosObjectInfo)iter.next();
            objInfo.writeXRefStreamEntry(buf, widths);
        }
        xrefStm.newDataDecoded(buf.closeAndConvert());
        buf = null;
        xrStmObjInfo.writeIndirectObject(os, curPos);
        if (setTrailer) {
            this.mTrailer = xrefStm;
        }
        return retVal;
    }

    public boolean isCacheEnabled() {
        return this.mCacheEnabled;
    }

    long writeIndirectObjects(CosList infos, OutputByteStream os, boolean saveToCopy) throws PDFCosParseException, IOException, PDFIOException, PDFSecurityException {
        long curpos = os.getPosition();
        if (infos.isEmpty()) {
            return curpos;
        }
        Iterator iter = infos.iterator();
        while (iter.hasNext()) {
            CosObject obj;
            CosObjectInfo info = (CosObjectInfo)iter.next();
            if (info.isDirty() && (obj = info.getObject()) instanceof CosObjectStream) {
                ((CosObjectStream)obj).writeObjectsToStream();
            }
            curpos = info.writeIndirectObject(os, curpos, saveToCopy);
        }
        return curpos;
    }

    CosList copyInfoList(CosList src) {
        CosList dest = new CosList();
        Iterator iter = src.iterator();
        while (iter.hasNext()) {
            CosObjectInfo info = (CosObjectInfo)iter.next();
            dest.add(info.getObjNum(), info);
        }
        return dest;
    }

    ArrayList prepareXRef(CosList infos, boolean full) {
        ArrayList<CosList> sections = new ArrayList<CosList>();
        CosList secList = new CosList();
        sections.add(secList);
        CosObjectInfo freeInfo = this.getObjectInfo(0, 65535);
        if (infos.isEmpty()) {
            secList.add(freeInfo);
        } else {
            int infoCounter;
            Iterator infoIter = infos.iterator();
            int nextObjNum = ((CosObjectInfo)infos.iterator().next()).getObjNum();
            if (full) {
                for (infoCounter = 0; infoCounter < nextObjNum; ++infoCounter) {
                    secList.add(freeInfo);
                }
            } else {
                infoCounter = nextObjNum;
            }
            while (infoIter.hasNext()) {
                CosObjectInfo nextInfo = (CosObjectInfo)infoIter.next();
                nextObjNum = nextInfo.getObjNum();
                if (infoCounter < nextObjNum) {
                    if (full) {
                        while (infoCounter < nextObjNum) {
                            secList.add(freeInfo);
                            ++infoCounter;
                        }
                    } else {
                        secList = new CosList();
                        sections.add(secList);
                        infoCounter = nextObjNum;
                    }
                }
                secList.add(nextInfo);
                ++infoCounter;
            }
        }
        return sections;
    }

    long writeXRefTable(ArrayList sections, OutputByteStream os) throws IOException {
        os.write(StringOps.toByteArray("xref\n"));
        for (CosList nextsec : sections) {
            CosObjectInfo firstObjInfo = (CosObjectInfo)nextsec.get(0);
            int firstObjNum = firstObjInfo.getObjNum();
            os.write(StringOps.toByteArray(Integer.toString(firstObjNum)));
            os.write(32);
            os.write(StringOps.toByteArray(Integer.toString(nextsec.size())));
            os.write(32);
            os.write(10);
            Iterator secobjitr = nextsec.iterator();
            while (secobjitr.hasNext()) {
                CosObjectInfo secinfo = (CosObjectInfo)secobjitr.next();
                secinfo.writeXRefTableEntry(os);
            }
        }
        return os.getPosition();
    }

    long buildXRefStream(ArrayList sections, OutputByteStream os, CosList objStmsToBeDeleted) throws PDFCosParseException, IOException, PDFIOException, PDFSecurityException {
        long xrefpos = os.getPosition();
        CosStream xrefStream = this.createCosStream();
        xrefStream.put(ASName.k_Type, ASName.k_XRef);
        this.copyTrailerFields(xrefStream, this.getNumObjects());
        if (objStmsToBeDeleted == null) {
            xrefStream.put(ASName.k_Prev, this.mXRef.getLastXRefSectionPosition());
        }
        CosArray indexVal = this.createCosArray();
        Iterator seciter = sections.iterator();
        while (seciter.hasNext()) {
            CosList nextsec = (CosList)seciter.next();
            CosObjectInfo firstObjInfo = (CosObjectInfo)nextsec.get(0);
            int firstObjNum = firstObjInfo.getObjNum();
            int secsize = nextsec.size();
            indexVal.addInt(firstObjNum);
            if (!seciter.hasNext()) {
                int thisObjNum = xrefStream.getObjNum();
                if (thisObjNum == firstObjNum + secsize) {
                    ++secsize;
                } else if (objStmsToBeDeleted != null) {
                    CosObjectInfo freeInfo = this.getObjectInfo(0, 65535);
                    while (thisObjNum > firstObjNum + secsize++) {
                        nextsec.add(freeInfo);
                    }
                } else {
                    indexVal.addInt(secsize);
                    indexVal.addInt(thisObjNum);
                    secsize = 1;
                }
            }
            indexVal.addInt(secsize);
        }
        xrefStream.put(ASName.k_Index, indexVal);
        int[] widths = this.setWidthsArray(sections, xrefStream, xrefpos);
        xrefStream.put(ASName.k_Filter, ASName.k_FlateDecode);
        OutputByteStream buf = this.getStreamManager().getOutputByteStreamClearDocument(ByteWriterFactory.Fixed.GROWABLE, -1);
        for (CosList nextsec : sections) {
            Iterator secobjitr = nextsec.iterator();
            while (secobjitr.hasNext()) {
                CosObjectInfo secinfo = (CosObjectInfo)secobjitr.next();
                if (objStmsToBeDeleted != null && objStmsToBeDeleted.containsIndex(secinfo.getObjNum())) {
                    secinfo = this.getObjectInfo(0, 65535);
                }
                secinfo.writeXRefStreamEntry(buf, widths);
            }
        }
        CosObjectInfo xrefStreamInfo = xrefStream.getInfo();
        xrefStreamInfo.markDirty();
        xrefStreamInfo.setPos(xrefpos);
        xrefStreamInfo.writeXRefStreamEntry(buf, widths);
        xrefStream.newDataDecoded(buf.closeAndConvert());
        buf = null;
        xrefStreamInfo.writeIndirectObject(os, xrefpos);
        if (!this.mSaveToCopy) {
            this.mTrailer = xrefStream;
        }
        return os.getPosition();
    }

    CosList prepareHybridInfoList(CosList dirtyObjectInfos, CosList compressedList, CosList objStmsToBeDeleted) throws PDFCosParseException, PDFIOException, PDFSecurityException, IOException {
        CosList hybridInfos = new CosList();
        Iterator objIter = dirtyObjectInfos.iterator();
        while (objIter.hasNext()) {
            boolean compressed;
            CosObjectInfo origInfo = (CosObjectInfo)objIter.next();
            int objNum = origInfo.getObjNum();
            if (objStmsToBeDeleted != null && objStmsToBeDeleted.containsIndex(objNum)) {
                objIter.remove();
                continue;
            }
            CosObject origObj = origInfo.getObject();
            if (origObj == null || !(compressed = compressedList != null ? compressedList.containsIndex(objNum) : origInfo.isCompressed()) && !(origObj instanceof CosObjectStream)) continue;
            hybridInfos.add(objNum, origInfo);
            objIter.remove();
        }
        CosStream xref = this.createCosStream();
        CosObjectInfo xinfo = xref.getInfo();
        xref.put(ASName.k_Type, ASName.k_XRef);
        xref.put(ASName.k_Size, hybridInfos.size() + 1);
        xref.put(ASName.k_Filter, ASName.k_FlateDecode);
        hybridInfos.add(xinfo.getObjNum(), xinfo);
        return hybridInfos;
    }

    void writeTrailer(CosDictionary trailer, OutputByteStream os) throws PDFCosParseException, PDFIOException, IOException, PDFSecurityException {
        os.write(StringOps.toByteArray("trailer\n"));
        trailer.writeOut(os);
        os.write(10);
    }

    void writeEOF(long xrefPos, OutputByteStream os) throws IOException {
        os.write(StringOps.toByteArray("startxref\n"));
        os.write(StringOps.toByteArray(Long.toString(xrefPos)));
        os.write(StringOps.toByteArray("\n%%EOF\n"));
    }

    public boolean isEncrypted() {
        CosDictionary trailer = this.getTrailer();
        return trailer != null ? trailer.containsKey(ASName.k_Encrypt) : false;
    }

    public CosEncryption getEncryption() {
        return this.mEncryption;
    }

    CosDictionary getEncryptionDictionary() {
        return this.mEncryption.getEncryption();
    }

    void setEncryptionDictionary(CosDictionary encrypt) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        if (encrypt != null) {
            int savedState = 0;
            CosDictionary trailer = this.getTrailer();
            CosObjectInfo trailerInfo = trailer.getInfo();
            if (trailerInfo != null) {
                savedState = trailerInfo.getState();
            }
            trailer.put(ASName.k_Encrypt, encrypt);
            if (trailerInfo != null) {
                trailerInfo.setState(savedState);
            }
        }
    }

    void removeEncryptionDictionary() throws PDFCosParseException, PDFIOException, PDFSecurityException {
        int savedState = 0;
        CosDictionary trailer = this.getTrailer();
        CosObjectInfo trailerInfo = trailer.getInfo();
        if (trailerInfo != null) {
            savedState = trailerInfo.getState();
        }
        trailer.remove(ASName.k_Encrypt);
        if (trailerInfo != null) {
            trailerInfo.setState(savedState);
        }
    }

    boolean needsEncryption() {
        return this.getEncryption().needsEncryption();
    }

    protected CosLinearization getLinearization() {
        return this.mCosLin;
    }

    public CosObject getIndirectObjectByNumber(int objNum) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        try {
            CosObject result;
            if (objNum > this.mNumObjects) {
                return null;
            }
            CosObjectInfo indexedInfo = this.getIndexedInfo(objNum);
            CosObjectInfo info = indexedInfo;
            if (info == null) {
                info = this.mXRef.getInfo(objNum);
            } else if (info.isFree()) {
                return null;
            }
            if (info == null) {
                return null;
            }
            if (indexedInfo == null) {
                this.putIndexedInfo(objNum, info);
            }
            if ((result = info.getObject()) == null) {
                try {
                    result = this.mXRef.getIndirectObject(info);
                }
                catch (PDFCosParseException e) {
                    if (this.mOptions.getLateRepairEnabled()) {
                        if (!this.repairTypes.contains((Object)REPAIRTYPE.xrefRepair)) {
                            this.mXRef.rebuildLate();
                            this.repairTypes.add(REPAIRTYPE.xrefRepair);
                            try {
                                result = this.mXRef.getIndirectObject(info);
                            }
                            catch (PDFCosParseException ex) {}
                        }
                    }
                    throw new PDFCosParseException("XRef repair required but not enabled", e);
                }
            }
            return result;
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
    }

    public CosObjectInfo getIndirectObjectInfoByNumber(int objNum) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        try {
            if (objNum > this.mNumObjects) {
                return null;
            }
            CosObjectInfo indexedInfo = this.getIndexedInfo(objNum);
            CosObjectInfo info = indexedInfo;
            if (info == null) {
                info = this.mXRef.getInfo(objNum);
            } else if (info.isFree()) {
                return null;
            }
            if (info == null) {
                return null;
            }
            if (indexedInfo == null) {
                this.putIndexedInfo(objNum, info);
            }
            return info;
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
    }

    CosObject getIndirectObject(CosObjectInfo info) throws PDFCosParseException, IOException, PDFSecurityException, PDFIOException {
        if (info == null) {
            return null;
        }
        CosObject result = info.getObject();
        if (result == null) {
            try {
                result = this.mXRef.getIndirectObject(info);
            }
            catch (PDFCosParseException e) {
                if (e.hasErrorType(PDFCosParseException.CosParseErrorType.NumberParseError)) {
                    throw e;
                }
                if (this.mOptions.getLateRepairEnabled()) {
                    if (!this.repairTypes.contains((Object)REPAIRTYPE.xrefRepair)) {
                        this.repairTypes.add(REPAIRTYPE.xrefRepair);
                        this.mXRef.rebuildLate();
                        try {
                            result = this.mXRef.getIndirectObject(info);
                        }
                        catch (PDFCosParseException ex) {}
                    }
                }
                throw new PDFCosParseException("XRef repair required but not enabled", e);
            }
        }
        if (result == null) {
            result = this.createCosNull();
        }
        return result;
    }

    public long getObjEOF(CosObject obj) {
        return this.mXRef.getObjEOF(obj.getInfo());
    }

    public int getObjRevision(CosObject obj) {
        return this.mXRef.getObjRevision(obj.getInfo());
    }

    public int getHeaderTrashCount() {
        return this.mHeaderTrashCount;
    }

    public int getTrailerTrashCount() {
        return this.mTrailerTrashCount;
    }

    public int getNumRevisions() {
        return this.mXRef.getNumRevisions();
    }

    public long getFileSize() throws PDFIOException {
        try {
            return this.mBuf.length();
        }
        catch (IOException e) {
            throw new PDFIOException("Error with stream underlying document.", e);
        }
    }

    public CosList getChangedObjects(long eof) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        CosList dirtyObjectInfos = this.buildObjectList(true);
        CosList modList = new CosList();
        Iterator iter = dirtyObjectInfos.iterator();
        while (iter.hasNext()) {
            CosObjectInfo info = (CosObjectInfo)iter.next();
            int objNum = info.getObjNum();
            int objGen = info.getObjGen();
            if (info.isFree()) {
                objGen = -1;
            }
            modList.add(objNum, new CosObjectID(objNum, objGen));
        }
        try {
            this.mXRef.getChangedObjects(eof, modList);
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
        modList.delete(0);
        return modList;
    }

    long getObjPos(CosObject obj) {
        CosObjectInfo info = obj.getInfo();
        if (info == null) {
            return 0;
        }
        if (info.isCompressed()) {
            return info.getStreamInfo().getPos();
        }
        return info.getPos();
    }

    private void copyTrailerFields(CosDictionary trailer, int newSize) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        CosDictionary oldTrailer = this.getTrailer();
        if (oldTrailer.containsKey(ASName.k_Root)) {
            trailer.put(ASName.k_Root, oldTrailer.get(ASName.k_Root));
        }
        if (oldTrailer.containsKey(ASName.k_Info)) {
            CosDictionary dict = (CosDictionary)oldTrailer.get(ASName.k_Info);
            if (!dict.isIndirect()) {
                CosCloneMgr cloneMgr = new CosCloneMgr(this);
                dict = (CosDictionary)cloneMgr.clone(dict);
            }
            trailer.put(ASName.k_Info, dict);
        }
        if (oldTrailer.containsKey(ASName.k_Encrypt)) {
            trailer.put(ASName.k_Encrypt, oldTrailer.get(ASName.k_Encrypt));
        }
        if (!this.mIsFDF) {
            if (oldTrailer.containsKey(ASName.k_ID)) {
                trailer.put(ASName.k_ID, oldTrailer.get(ASName.k_ID));
            }
            trailer.put(ASName.k_Size, newSize);
        }
    }

    CosArray createUpdateDocID(boolean both) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        CosObject idArray = null;
        if (!(both || (idArray = this.getTrailer().get(ASName.k_ID)) instanceof CosArray && ((CosArray)idArray).size() == 2)) {
            idArray = null;
            both = true;
        }
        IDProducer idproc = new IDProducer();
        DataOutputStream uidOut = new DataOutputStream(idproc);
        UID newUID = new UID();
        try {
            newUID.write(uidOut);
            if (idArray != null) {
                ASString oldID = ((CosArray)idArray).getString(1);
                idproc.write(oldID.getBytes());
            }
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
        byte[] newID = idproc.getDigest();
        if (idArray == null) {
            idArray = this.createCosArray(0);
            ((CosArray)idArray).addString(new ASString(newID));
            ((CosArray)idArray).add(this.createCosNull());
        }
        ((CosArray)idArray).setString(1, new ASString(newID));
        if (both) {
            ((CosArray)idArray).setString(0, ((CosArray)idArray).getString(1));
        }
        for (int i = 0; i < 2; ++i) {
            CosString elem = ((CosArray)idArray).getCosString(i);
            elem.setWriteHex(true);
            elem.setToEncrypt(false);
        }
        return (CosArray)idArray;
    }

    public void markDirty() {
        this.mDocIsDirty = true;
    }

    public boolean isDirty() {
        return this.mDocIsDirty;
    }

    public boolean markNotDirty() {
        boolean isDirty = this.mDocIsDirty;
        this.mDocIsDirty = false;
        return isDirty;
    }

    public long getEOF() throws PDFIOException {
        if (this.mBuf == null) {
            return 0;
        }
        try {
            return this.mBuf.length();
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
    }

    public int getXRefType() {
        if (this.mXRef != null) {
            int xrefType = this.mXRef.getType();
            if (xrefType == 1) {
                return 2;
            }
            if (xrefType == 2) {
                return 3;
            }
        }
        return 1;
    }

    CosList buildObjectList(boolean dirtyOnly) {
        CosList objectList = new CosList();
        Iterator iter = this.mObjectInfos.iterator();
        while (iter.hasNext()) {
            CosObjectInfo info = (CosObjectInfo)iter.next();
            if ((!dirtyOnly || !info.isDirty()) && (dirtyOnly || info.isFree())) continue;
            objectList.add(info.getObjNum(), info);
        }
        return objectList;
    }

    CosList buildCompObjList(int xrefStyle) throws PDFCosParseException, PDFIOException, PDFSecurityException, IOException {
        CosList stmObjList;
        CosList stmList = new CosList();
        Iterator iter = this.mObjectInfos.iterator();
        CosDictionary catalog = this.getRoot();
        CosDictionary encrypt = this.getEncryptionDictionary();
        while (iter.hasNext()) {
            CosObject type;
            CosObject obj;
            CosObjectInfo info = (CosObjectInfo)iter.next();
            if (!info.isDirty()) continue;
            if (info.isCompressed()) {
                CosObjectInfo stmInfo = info.getStreamInfo();
                stmObjList = (CosList)stmList.get(stmInfo.getObjNum());
                if (stmObjList == null) {
                    stmObjList = new CosList();
                    stmList.add(stmInfo.getObjNum(), stmObjList);
                }
                stmObjList.add(info.getObjNum(), info);
                continue;
            }
            if (xrefStyle != 2 || (obj = info.getObject()) == null || obj instanceof CosStream || obj == catalog || obj == encrypt || obj instanceof CosDictionary && (type = ((CosDictionary)obj).get(ASName.k_Type)) instanceof CosName && dictionariesNotToBeCompressed.contains(type.nameValue())) continue;
            this.mCompObjInfos.add(info.getObjNum(), info);
        }
        Iterator compIter = this.mCompObjInfos.iterator();
        CosContainer curObjStm = null;
        stmObjList = null;
        int curIndex = 200;
        while (compIter.hasNext()) {
            CosObjectInfo info = (CosObjectInfo)compIter.next();
            CosObject obj = info.getObject();
            if (curIndex == 200) {
                curIndex = 0;
                if (curObjStm != null) {
                    curObjStm.markNotDirty();
                }
                curObjStm = this.createCosObjectStream();
                stmObjList = new CosList();
                stmList.add(curObjStm.getInfo().getObjNum(), stmObjList);
            }
            curObjStm.addObjectToStream(obj);
            stmObjList.add(info.getObjNum(), info);
            ++curIndex;
        }
        if (curObjStm != null) {
            curObjStm.markNotDirty();
        }
        return stmList;
    }

    protected void postSaveCleanup(OutputByteStream outputByteStream, ByteWriter byteWriter) throws PDFCosParseException, IOException, PDFIOException, PDFSecurityException {
        if (this.mBuf != null) {
            this.mBuf.close();
        }
        this.releaseAllCosObjects();
        if (this.mByteReader != byteWriter) {
            this.mStreamManager.resetMasterByteReader((ByteReader)byteWriter);
            this.mByteReader = byteWriter;
        }
        this.mBuf = outputByteStream.closeAndConvert();
        this.mXRef.resetXRef(this.mBuf.slice());
        this.mOrigNumObjects = this.mNumObjects;
        this.mCosLin = null;
        this.mDocIsDirty = false;
        if (this.cosRepairList != null) {
            this.cosRepairList.clear();
        }
        this.repairTypes.clear();
        this.documentCosLevelRepaired = false;
        this.nextIncrementalSectionOffset = -1;
    }

    private void closeAllCosObjects() throws PDFIOException, PDFCosParseException, PDFSecurityException, IOException {
        Exception saveEx = null;
        Iterator iter = this.mObjectInfos.iterator();
        while (iter.hasNext()) {
            CosObjectInfo info = (CosObjectInfo)iter.next();
            try {
                CosObject obj = info.getObject(false);
                if (obj == null) continue;
                obj.close();
            }
            catch (Exception e) {
                saveEx = e;
            }
        }
        if (saveEx != null) {
            if (saveEx instanceof PDFIOException) {
                throw (PDFIOException)saveEx;
            }
            if (saveEx instanceof PDFCosParseException) {
                throw (PDFCosParseException)saveEx;
            }
            if (saveEx instanceof PDFSecurityException) {
                throw (PDFSecurityException)saveEx;
            }
            if (saveEx instanceof IOException) {
                throw (IOException)saveEx;
            }
            throw new PDFIOException(saveEx);
        }
    }

    private void releaseAllCosObjects() throws PDFIOException, PDFCosParseException, PDFSecurityException, IOException {
        Iterator iter = this.mObjectInfos.iterator();
        while (iter.hasNext()) {
            CosObjectInfo info = (CosObjectInfo)iter.next();
            CosObject obj = info.getObject(false);
            if (obj == null) continue;
            obj.release();
        }
    }

    public CosArray createCosArray(ArrayList array, int directStatus) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        CosArray newArray = null;
        if (directStatus == 1) {
            CosObjectInfo info = this.newObjectInfo();
            newArray = new CosArray(this, array, info);
            try {
                info.markDirty();
            }
            catch (IOException e) {
                throw new PDFIOException(e);
            }
        } else {
            newArray = new CosArray(this, array, null);
        }
        return newArray;
    }

    public CosArray createIndirectCosArray(ArrayList array) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        return this.createCosArray(array, 1);
    }

    public CosArray createCosArray(ArrayList array) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        return this.createCosArray(array, 0);
    }

    public CosArray createCosArrayFromNonCosData(ArrayList array, int directStatus) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        CosArray newArray = this.createCosArray(directStatus);
        Iterator arrayIter = array.iterator();
        CosObject obj = null;
        while (arrayIter.hasNext()) {
            obj = this.convertToCosObject(arrayIter.next());
            if (obj == null) continue;
            newArray.add(obj);
        }
        return newArray;
    }

    public CosArray createIndirectCosArrayFromNonCosData(ArrayList array) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        return this.createCosArrayFromNonCosData(array, 1);
    }

    public CosArray createCosArrayFromNonCosData(ArrayList array) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        return this.createCosArrayFromNonCosData(array, 0);
    }

    public CosArray createCosArray(int directStatus) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        return this.createCosArray(new ArrayList(), directStatus);
    }

    public CosArray createIndirectCosArray() throws PDFCosParseException, PDFIOException, PDFSecurityException {
        return this.createCosArray(1);
    }

    public CosArray createCosArray() throws PDFCosParseException, PDFIOException, PDFSecurityException {
        return this.createCosArray(0);
    }

    public CosBoolean createCosBoolean(boolean value) {
        return new CosBoolean(this, value, null);
    }

    public CosBoolean createCosBoolean(Boolean value) {
        return new CosBoolean(this, value, null);
    }

    public CosDictionary createCosDictionary(int directStatus) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        CosDictionary newDict = null;
        if (directStatus == 1) {
            CosObjectInfo info = this.newObjectInfo();
            newDict = new CosDictionary(this, new LinkedHashMap<ASName, CosObject>(), info);
            try {
                info.markDirty();
            }
            catch (IOException e) {
                throw new PDFIOException(e);
            }
        } else {
            newDict = new CosDictionary(this, new LinkedHashMap<ASName, CosObject>(), null);
        }
        return newDict;
    }

    public CosDictionary createCosDictionary() throws PDFCosParseException, PDFIOException, PDFSecurityException {
        return this.createCosDictionary(1);
    }

    public CosDictionary createDirectCosDictionary() throws PDFCosParseException, PDFIOException, PDFSecurityException {
        return this.createCosDictionary(0);
    }

    public CosDictionary createCosDictionary(Map cosData, int directStatus) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        CosDictionary newDict = null;
        if (directStatus == 1) {
            CosObjectInfo info = this.newObjectInfo();
            newDict = new CosDictionary(this, cosData, info);
            try {
                info.markDirty();
            }
            catch (IOException e) {
                throw new PDFIOException(e);
            }
        } else {
            newDict = new CosDictionary(this, cosData, null);
        }
        return newDict;
    }

    public CosDictionary createCosDictionary(Map cosData) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        return this.createCosDictionary(cosData, 1);
    }

    public CosDictionary createDirectCosDictionary(Map cosData) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        return this.createCosDictionary(cosData, 0);
    }

    public CosDictionary createCosDictionaryFromNonCosData(Map data, int directStatus) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        CosDictionary newDict = this.createCosDictionary(directStatus);
        for (Map.Entry entry : data.entrySet()) {
            CosObject cosObj;
            if (entry == null || entry.getKey() == null || (cosObj = this.convertToCosObject(entry.getValue())) == null) continue;
            newDict.put(ASName.create((String)entry.getKey()), cosObj);
        }
        return newDict;
    }

    public CosDictionary createCosDictionaryFromNonCosData(Map javaMap) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        return this.createCosDictionaryFromNonCosData(javaMap, 1);
    }

    public CosDictionary createDirectCosDictionaryFromNonCosData(Map javaMap) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        return this.createCosDictionaryFromNonCosData(javaMap, 0);
    }

    public CosName createCosName(ASName value) {
        return new CosName(this, value, null);
    }

    public CosNull createCosNull() {
        return new CosNull(this);
    }

    public CosNumeric createCosNumeric(Number value) {
        return new CosNumeric(this, value, null);
    }

    public CosNumeric createCosNumeric(int value) {
        return new CosNumeric(this, value, null);
    }

    public CosNumeric createCosNumeric(long value) {
        return new CosNumeric(this, value, null);
    }

    public CosNumeric createCosNumeric(double value) {
        return new CosNumeric(this, new Double(value), null);
    }

    public CosNumeric createCosNumeric(byte[] inputRep) throws PDFCosParseException {
        return new CosNumeric(this, inputRep, null);
    }

    public CosNumeric createCosNumeric(CosNumeric source) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        try {
            return new CosNumeric(this, source);
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
    }

    public CosObjectStream createCosObjectStream() throws PDFCosParseException, PDFIOException, PDFSecurityException {
        try {
            return new CosObjectStream(this);
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
    }

    public CosStream createCosStream() throws PDFCosParseException, PDFIOException, PDFSecurityException {
        try {
            CosObjectInfo info = this.newObjectInfo();
            info.markDirty();
            CosStream cosObj = new CosStream(this, info);
            cosObj.setIsEncrypted(false);
            cosObj.setToEncrypt(true);
            return cosObj;
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
    }

    public CosStream createCosStream(InputByteStream data) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        try {
            CosObjectInfo info = this.newObjectInfo();
            info.markDirty();
            CosStream cosObj = new CosStream(this, info, data);
            cosObj.setIsEncrypted(false);
            cosObj.setToEncrypt(true);
            return cosObj;
        }
        catch (IOException e) {
            throw new PDFIOException(e);
        }
    }

    public CosString createCosString(ASString value) {
        return this.createCosString(value.getBytes());
    }

    public CosString createCosString(byte[] value) {
        return new CosString(this, value, 0, value.length, false, null);
    }

    public CosString createCosString(String value) {
        byte[] bytes = PDFDocEncoding.fromUnicodeString(value);
        return new CosString(this, bytes, 0, bytes.length, false, null);
    }

    public CosString createHexCosString(ASString value) {
        return this.createHexCosString(value.getBytes());
    }

    public CosString createHexCosString(byte[] value) {
        return new CosString(this, value, 0, value.length, false, null, true);
    }

    public CosString createHexCosString(String value) {
        byte[] bytes = PDFDocEncoding.fromUnicodeString(value);
        return new CosString(this, bytes, 0, bytes.length, false, null, true);
    }

    protected CosObject convertToCosObject(Object val) throws PDFCosParseException, PDFIOException, PDFSecurityException {
        if (val instanceof CosObject) {
            return (CosObject)val;
        }
        CosObject newObj = null;
        if (val instanceof Boolean) {
            newObj = this.createCosBoolean((Boolean)val);
        } else if (val instanceof Number) {
            newObj = this.createCosNumeric((Number)val);
        } else if (val instanceof byte[]) {
            newObj = this.createCosString((byte[])val);
        } else if (val instanceof String) {
            newObj = this.createCosName(ASName.create((String)val));
        } else if (val instanceof ASName) {
            newObj = this.createCosName((ASName)val);
        } else if (val instanceof HashMap) {
            newObj = this.createCosDictionaryFromNonCosData((HashMap)val, 0);
        } else if (val instanceof ArrayList) {
            newObj = this.createCosArrayFromNonCosData((ArrayList)val, 0);
        }
        return newObj;
    }

    void setRepairedValue(CosDictionary obj, ASName key, CosObject value) {
        if (!this.documentCosLevelRepaired) {
            this.cosRepairList = new CosRepairList(this);
            this.documentCosLevelRepaired = true;
        }
        this.cosRepairList.setRepairedValue(obj, key, value);
    }

    void setRepairedValue(Integer objNum, CosObject obj) {
        if (obj == null) {
            return;
        }
        if (!this.documentCosLevelRepaired) {
            this.cosRepairList = new CosRepairList(this);
            this.documentCosLevelRepaired = true;
        }
        this.cosRepairList.setRepairedValue(objNum, obj);
    }

    CosObject getRepairedValue(Integer objNum, ASName key) {
        return this.documentCosLevelRepaired ? this.cosRepairList.getRepairedValue(objNum, key) : null;
    }

    CosObject getRepairedValue(Integer objNum) {
        return this.documentCosLevelRepaired && this.cosRepairList != null ? this.cosRepairList.getRepairedValue(objNum) : null;
    }

    boolean isDocumentCosLevelRepaired() {
        return this.documentCosLevelRepaired;
    }

    void setDocumentCosLevelRepaired() {
        this.documentCosLevelRepaired = true;
    }

    CosRepairList getRepairList() {
        return this.cosRepairList;
    }

    public void setUseRepairList(boolean useRepairList) {
        this.useRepairList = useRepairList;
    }

    boolean getUseRepairList() {
        return this.useRepairList;
    }

    boolean isFDF() {
        return this.mIsFDF;
    }

    static {
        dictionariesNotToBeCompressed.add(ASName.k_Sig);
        dictionariesNotToBeCompressed.add(ASName.k_DocTimeStamp);
        mLoggingPath = null;
    }

    private static class IDProducer
    extends OutputStream {
        MessageDigest mDigest;

        IDProducer() {
            try {
                this.mDigest = MessageDigest.getInstance("MD5");
            }
            catch (NoSuchAlgorithmException e) {
                throw new RuntimeException("MD5 is not available.", e);
            }
        }

        public void write(int b) {
            this.mDigest.update((byte)b);
        }

        byte[] getDigest() {
            return this.mDigest.digest();
        }
    }

}