| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package org.tukaani.xz.index; |
| 6 |
|
| 7 |
import org.tukaani.xz.common.Util; |
| 8 |
import org.tukaani.xz.XZIOException; |
| 9 |
|
| 10 |
abstract class IndexBase { |
| 11 |
private final XZIOException invalidIndexException; |
| 12 |
long blocksSum = 0; |
| 13 |
long uncompressedSum = 0; |
| 14 |
long indexListSize = 0; |
| 15 |
long recordCount = 0; |
| 16 |
|
| 17 |
IndexBase(XZIOException invalidIndexException) { |
| 18 |
this.invalidIndexException = invalidIndexException; |
| 19 |
} |
| 20 |
|
| 21 |
private long getUnpaddedIndexSize() { |
| 22 |
|
| 23 |
return 1 + Util.getVLISize(recordCount) + indexListSize + 4; |
| 24 |
} |
| 25 |
|
| 26 |
public long getIndexSize() { |
| 27 |
return (getUnpaddedIndexSize() + 3) & ~3; |
| 28 |
} |
| 29 |
|
| 30 |
public long getStreamSize() { |
| 31 |
return Util.STREAM_HEADER_SIZE + blocksSum + getIndexSize() |
| 32 |
+ Util.STREAM_HEADER_SIZE; |
| 33 |
} |
| 34 |
|
| 35 |
int getIndexPaddingSize() { |
| 36 |
return (int)((4 - getUnpaddedIndexSize()) & 3); |
| 37 |
} |
| 38 |
|
| 39 |
void add(long unpaddedSize, long uncompressedSize) throws XZIOException { |
| 40 |
blocksSum += (unpaddedSize + 3) & ~3; |
| 41 |
uncompressedSum += uncompressedSize; |
| 42 |
indexListSize += Util.getVLISize(unpaddedSize) |
| 43 |
+ Util.getVLISize(uncompressedSize); |
| 44 |
++recordCount; |
| 45 |
|
| 46 |
if (blocksSum < 0 || uncompressedSum < 0 |
| 47 |
|| getIndexSize() > Util.BACKWARD_SIZE_MAX |
| 48 |
|| getStreamSize() < 0) |
| 49 |
throw invalidIndexException; |
| 50 |
} |
| 51 |
} |