71 |
71 |
72 // Various heuristic options. |
72 // Various heuristic options. |
73 boolean optVaryCodings = !p200.getBoolean(Utils.COM_PREFIX+"no.vary.codings"); |
73 boolean optVaryCodings = !p200.getBoolean(Utils.COM_PREFIX+"no.vary.codings"); |
74 boolean optBigStrings = !p200.getBoolean(Utils.COM_PREFIX+"no.big.strings"); |
74 boolean optBigStrings = !p200.getBoolean(Utils.COM_PREFIX+"no.big.strings"); |
75 |
75 |
76 abstract protected Index getCPIndex(byte tag); |
76 protected abstract Index getCPIndex(byte tag); |
77 |
77 |
78 // Local copy of highest class version. |
78 // Local copy of highest class version. |
79 private Package.Version highestClassVersion = null; |
79 private Package.Version highestClassVersion = null; |
80 |
80 |
81 /** Call this exactly once, early, to specify the archive major version. */ |
81 /** Call this exactly once, early, to specify the archive major version. */ |
95 |
95 |
96 private final boolean isReader = this instanceof PackageReader; |
96 private final boolean isReader = this instanceof PackageReader; |
97 |
97 |
98 protected BandStructure() {} |
98 protected BandStructure() {} |
99 |
99 |
100 final static Coding BYTE1 = Coding.of(1,256); |
100 static final Coding BYTE1 = Coding.of(1,256); |
101 |
101 |
102 final static Coding CHAR3 = Coding.of(3,128); |
102 static final Coding CHAR3 = Coding.of(3,128); |
103 // Note: Tried sharper (3,16) with no post-zip benefit. |
103 // Note: Tried sharper (3,16) with no post-zip benefit. |
104 |
104 |
105 // This is best used with BCI values: |
105 // This is best used with BCI values: |
106 final static Coding BCI5 = Coding.of(5,4); // mostly 1-byte offsets |
106 static final Coding BCI5 = Coding.of(5,4); // mostly 1-byte offsets |
107 final static Coding BRANCH5 = Coding.of(5,4,2); // mostly forward branches |
107 static final Coding BRANCH5 = Coding.of(5,4,2); // mostly forward branches |
108 |
108 |
109 final static Coding UNSIGNED5 = Coding.of(5,64); |
109 static final Coding UNSIGNED5 = Coding.of(5,64); |
110 final static Coding UDELTA5 = UNSIGNED5.getDeltaCoding(); |
110 static final Coding UDELTA5 = UNSIGNED5.getDeltaCoding(); |
111 // "sharp" (5,64) zips 0.4% better than "medium" (5,128) |
111 // "sharp" (5,64) zips 0.4% better than "medium" (5,128) |
112 // It zips 1.1% better than "flat" (5,192) |
112 // It zips 1.1% better than "flat" (5,192) |
113 |
113 |
114 final static Coding SIGNED5 = Coding.of(5,64,1); //sharp |
114 static final Coding SIGNED5 = Coding.of(5,64,1); //sharp |
115 final static Coding DELTA5 = SIGNED5.getDeltaCoding(); |
115 static final Coding DELTA5 = SIGNED5.getDeltaCoding(); |
116 // Note: Tried (5,128,2) and (5,192,2) with no benefit. |
116 // Note: Tried (5,128,2) and (5,192,2) with no benefit. |
117 |
117 |
118 final static Coding MDELTA5 = Coding.of(5,64,2).getDeltaCoding(); |
118 static final Coding MDELTA5 = Coding.of(5,64,2).getDeltaCoding(); |
119 |
119 |
120 final private static Coding[] basicCodings = { |
120 private static final Coding[] basicCodings = { |
121 // Table of "Canonical BHSD Codings" from Pack200 spec. |
121 // Table of "Canonical BHSD Codings" from Pack200 spec. |
122 null, // _meta_default |
122 null, // _meta_default |
123 |
123 |
124 // Fixed-length codings: |
124 // Fixed-length codings: |
125 Coding.of(1,256,0), |
125 Coding.of(1,256,0), |
248 Coding.of(4,248,0).getDeltaCoding(), |
248 Coding.of(4,248,0).getDeltaCoding(), |
249 Coding.of(4,248,1).getDeltaCoding(), |
249 Coding.of(4,248,1).getDeltaCoding(), |
250 |
250 |
251 null |
251 null |
252 }; |
252 }; |
253 final private static Map<Coding, Integer> basicCodingIndexes; |
253 private static final Map<Coding, Integer> basicCodingIndexes; |
254 static { |
254 static { |
255 assert(basicCodings[_meta_default] == null); |
255 assert(basicCodings[_meta_default] == null); |
256 assert(basicCodings[_meta_canon_min] != null); |
256 assert(basicCodings[_meta_canon_min] != null); |
257 assert(basicCodings[_meta_canon_max] != null); |
257 assert(basicCodings[_meta_canon_max] != null); |
258 Map<Coding, Integer> map = new HashMap<>(); |
258 Map<Coding, Integer> map = new HashMap<>(); |
360 |
360 |
361 private int valuesExpected; |
361 private int valuesExpected; |
362 |
362 |
363 protected long outputSize = -1; // cache |
363 protected long outputSize = -1; // cache |
364 |
364 |
365 final public Coding regularCoding; |
365 public final Coding regularCoding; |
366 |
366 |
367 final public int seqForDebug; |
367 public final int seqForDebug; |
368 public int elementCountForDebug; |
368 public int elementCountForDebug; |
369 |
369 |
370 |
370 |
371 protected Band(String name, Coding regularCoding) { |
371 protected Band(String name, Coding regularCoding) { |
372 this.name = name; |
372 this.name = name; |
428 return computeOutputSize(); |
428 return computeOutputSize(); |
429 } |
429 } |
430 |
430 |
431 protected abstract long computeOutputSize(); |
431 protected abstract long computeOutputSize(); |
432 |
432 |
433 abstract protected void writeDataTo(OutputStream out) throws IOException; |
433 protected abstract void writeDataTo(OutputStream out) throws IOException; |
434 |
434 |
435 /** Expect a certain number of values. */ |
435 /** Expect a certain number of values. */ |
436 void expectLength(int l) { |
436 void expectLength(int l) { |
437 assert(assertPhase(this, EXPECT_PHASE)); |
437 assert(assertPhase(this, EXPECT_PHASE)); |
438 assert(valuesExpected == 0); // all at once |
438 assert(valuesExpected == 0); // all at once |
466 setPhase(READ_PHASE); |
466 setPhase(READ_PHASE); |
467 // subclasses continue by reading their contents from input: |
467 // subclasses continue by reading their contents from input: |
468 readDataFrom(in); |
468 readDataFrom(in); |
469 readyToDisburse(); |
469 readyToDisburse(); |
470 } |
470 } |
471 abstract protected void readDataFrom(InputStream in) throws IOException; |
471 protected abstract void readDataFrom(InputStream in) throws IOException; |
472 protected void readyToDisburse() { |
472 protected void readyToDisburse() { |
473 if (verbose > 1) Utils.log.fine("readyToDisburse "+this); |
473 if (verbose > 1) Utils.log.fine("readyToDisburse "+this); |
474 setPhase(DISBURSE_PHASE); |
474 setPhase(DISBURSE_PHASE); |
475 } |
475 } |
476 public void doneDisbursing() { |
476 public void doneDisbursing() { |
2537 else |
2537 else |
2538 Utils.log.warning("Unexpected phase "+p0+" -> "+p1); |
2538 Utils.log.warning("Unexpected phase "+p0+" -> "+p1); |
2539 return false; |
2539 return false; |
2540 } |
2540 } |
2541 |
2541 |
2542 static private boolean assertDoneDisbursing(Band b) { |
2542 private static boolean assertDoneDisbursing(Band b) { |
2543 if (b.phase != DISBURSE_PHASE) { |
2543 if (b.phase != DISBURSE_PHASE) { |
2544 Utils.log.warning("assertDoneDisbursing: still in phase "+b.phase+": "+b); |
2544 Utils.log.warning("assertDoneDisbursing: still in phase "+b.phase+": "+b); |
2545 if (verbose() <= 1) return false; // fail now |
2545 if (verbose() <= 1) return false; // fail now |
2546 } |
2546 } |
2547 int left = b.valuesRemainingForDebug(); |
2547 int left = b.valuesRemainingForDebug(); |