PDFObjectStreamParser.java (pdfbox-2.0.23-src) | : | PDFObjectStreamParser.java (pdfbox-2.0.24-src) | ||
---|---|---|---|---|
skipping to change at line 95 | skipping to change at line 95 | |||
* This will parse the tokens in the stream. This will close the | * This will parse the tokens in the stream. This will close the | |||
* stream when it is finished parsing. | * stream when it is finished parsing. | |||
* | * | |||
* @throws IOException If there is an error while parsing the stream. | * @throws IOException If there is an error while parsing the stream. | |||
*/ | */ | |||
public void parse() throws IOException | public void parse() throws IOException | |||
{ | { | |||
try | try | |||
{ | { | |||
Map<Integer, Long> offsets = readOffsets(); | Map<Integer, Long> offsets = readOffsets(); | |||
streamObjects = new ArrayList<COSObject>( numberOfObjects ); | streamObjects = new ArrayList<COSObject>(offsets.size()); | |||
for (Entry<Integer, Long> offset : offsets.entrySet()) | for (Entry<Integer, Long> offset : offsets.entrySet()) | |||
{ | { | |||
COSBase cosObject = parseObject(offset.getKey()); | COSBase cosObject = parseObject(offset.getKey()); | |||
COSObject object = new COSObject(cosObject); | COSObject object = new COSObject(cosObject); | |||
object.setGenerationNumber(0); | object.setGenerationNumber(0); | |||
object.setObjectNumber(offset.getValue()); | object.setObjectNumber(offset.getValue()); | |||
streamObjects.add(object); | streamObjects.add(object); | |||
if (LOG.isDebugEnabled()) | if (LOG.isDebugEnabled()) | |||
{ | { | |||
LOG.debug("parsed=" + object); | LOG.debug("parsed=" + object); | |||
skipping to change at line 131 | skipping to change at line 131 | |||
{ | { | |||
return streamObjects; | return streamObjects; | |||
} | } | |||
private Map<Integer, Long> readOffsets() throws IOException | private Map<Integer, Long> readOffsets() throws IOException | |||
{ | { | |||
// according to the pdf spec the offsets shall be sorted ascending | // according to the pdf spec the offsets shall be sorted ascending | |||
// but we can't rely on that, so that we have to sort the offsets | // but we can't rely on that, so that we have to sort the offsets | |||
// as the sequential parsers relies on it, see PDFBOX-4927 | // as the sequential parsers relies on it, see PDFBOX-4927 | |||
Map<Integer, Long> objectNumbers = new TreeMap<Integer, Long>(); | Map<Integer, Long> objectNumbers = new TreeMap<Integer, Long>(); | |||
long firstObjectPosition = seqSource.getPosition() + firstObject - 1; | ||||
for (int i = 0; i < numberOfObjects; i++) | for (int i = 0; i < numberOfObjects; i++) | |||
{ | { | |||
// don't read beyond the part of the stream reserved for the object | ||||
numbers | ||||
if (seqSource.getPosition() >= firstObjectPosition) | ||||
{ | ||||
break; | ||||
} | ||||
long objectNumber = readObjectNumber(); | long objectNumber = readObjectNumber(); | |||
int offset = (int) readLong(); | int offset = (int) readLong(); | |||
objectNumbers.put(offset, objectNumber); | objectNumbers.put(offset, objectNumber); | |||
} | } | |||
return objectNumbers; | return objectNumbers; | |||
} | } | |||
private COSBase parseObject(int offset) throws IOException | private COSBase parseObject(int offset) throws IOException | |||
{ | { | |||
long currentPosition = seqSource.getPosition(); | long currentPosition = seqSource.getPosition(); | |||
End of changes. 3 change blocks. | ||||
1 lines changed or deleted | 8 lines changed or added |