{
if(entries == null)
{
entries = new TreeMap<Integer,XRefEntry>();
final IBuffer body = getBody();
if(body.getLength() > 0)
{
final PdfDictionary header = getHeader();
final int size = ((PdfInteger)header.get(PdfName.Size)).getValue();
final int[] entryFieldSizes;
{
final PdfArray entryFieldSizesObject = (PdfArray)header.get(PdfName.W);
entryFieldSizes = new int[entryFieldSizesObject.size()];
for(int index = 0, length = entryFieldSizes.length; index < length; index++)
{entryFieldSizes[index] = ((PdfInteger)entryFieldSizesObject.get(index)).getValue();}
}
final PdfArray subsectionBounds;
if(header.containsKey(PdfName.Index))
{subsectionBounds = (PdfArray)header.get(PdfName.Index);}
else
{
subsectionBounds = new PdfArray();
subsectionBounds.add(new PdfInteger(0));
subsectionBounds.add(new PdfInteger(size));
}
body.setByteOrder(ByteOrder.BIG_ENDIAN);
body.seek(0);
final Iterator<PdfDirectObject> subsectionBoundIterator = subsectionBounds.iterator();
while(subsectionBoundIterator.hasNext())
{
try
{
final int start = ((PdfInteger)subsectionBoundIterator.next()).getValue();
final int count = ((PdfInteger)subsectionBoundIterator.next()).getValue();
for(
int entryIndex = start,
length = start + count;
entryIndex < length;
entryIndex++
)
{
final int entryFieldType = (entryFieldSizes[0] == 0 ? 1 : body.readInt(entryFieldSizes[0]));
switch(entryFieldType)
{
case FreeEntryType:
{
final int nextFreeObjectNumber = body.readInt(entryFieldSizes[1]);
final int generation = body.readInt(entryFieldSizes[2]);
entries.put(
entryIndex,
new XRefEntry(
entryIndex,
generation,
nextFreeObjectNumber,
XRefEntry.UsageEnum.Free
)
);
break;
}
case InUseEntryType:
{
final int offset = body.readInt(entryFieldSizes[1]);
final int generation = body.readInt(entryFieldSizes[2]);
entries.put(
entryIndex,
new XRefEntry(
entryIndex,
generation,
offset,
XRefEntry.UsageEnum.InUse
)
);
break;
}
case InUseCompressedEntryType:
{
final int streamNumber = body.readInt(entryFieldSizes[1]);
final int innerNumber = body.readInt(entryFieldSizes[2]);
entries.put(
entryIndex,
new XRefEntry(
entryIndex,
innerNumber,