You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2019/12/08 18:16:38 UTC
svn commit: r1871057 - in /pdfbox/branches/issue4569:
pdfbox/src/main/java/org/apache/pdfbox/pdfparser/
preflight/src/main/java/org/apache/pdfbox/preflight/parser/
tools/src/main/java/org/apache/pdfbox/tools/
Author: lehmi
Date: Sun Dec 8 18:16:38 2019
New Revision: 1871057
URL: http://svn.apache.org/viewvc?rev=1871057&view=rev
Log:
PDFBOX-3888: return read stream objects right after parsing, remove getter
Modified:
pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFObjectStreamParser.java
pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java
pdfbox/branches/issue4569/tools/src/main/java/org/apache/pdfbox/tools/DecompressObjectstreams.java
Modified: pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java?rev=1871057&r1=1871056&r2=1871057&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java (original)
+++ pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java Sun Dec 8 18:16:38 2019
@@ -766,7 +766,16 @@ public class COSParser extends BaseParse
try
{
parser = new PDFObjectStreamParser((COSStream) objstmBaseObj, document);
- parser.parse();
+ // register all objects which are referenced to be contained in object stream
+ parser.parse().stream().forEach(next -> {
+ COSObjectKey stmObjKey = new COSObjectKey(next);
+ Long offset = xrefTrailerResolver.getXrefTable().get(stmObjKey);
+ if (offset != null && offset == -objstmObjNr)
+ {
+ COSObject stmObj = document.getObjectFromPool(stmObjKey);
+ stmObj.setObject(next.getObject());
+ }
+ });
}
catch (IOException ex)
{
@@ -790,17 +799,6 @@ public class COSParser extends BaseParse
throw ex;
}
}
- // register all objects which are referenced to be contained in object stream
- parser.getObjects().stream().forEach(next ->
- {
- COSObjectKey stmObjKey = new COSObjectKey(next);
- Long offset = xrefTrailerResolver.getXrefTable().get(stmObjKey);
- if (offset != null && offset == -objstmObjNr)
- {
- COSObject stmObj = document.getObjectFromPool(stmObjKey);
- stmObj.setObject(next.getObject());
- }
- });
}
}
Modified: pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFObjectStreamParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFObjectStreamParser.java?rev=1871057&r1=1871056&r2=1871057&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFObjectStreamParser.java (original)
+++ pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFObjectStreamParser.java Sun Dec 8 18:16:38 2019
@@ -24,6 +24,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDocument;
+import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSObject;
import org.apache.pdfbox.cos.COSStream;
@@ -40,7 +41,6 @@ public class PDFObjectStreamParser exten
*/
private static final Log LOG = LogFactory.getLog(PDFObjectStreamParser.class);
- private List<COSObject> streamObjects = null;
private final COSStream stream;
/**
@@ -58,23 +58,23 @@ public class PDFObjectStreamParser exten
}
/**
- * This will parse the tokens in the stream. This will close the
- * stream when it is finished parsing.
+ * This will parse the tokens in the stream. This will close the stream when it is finished parsing.
*
+ * @return All of the objects in the stream.
* @throws IOException If there is an error while parsing the stream.
*/
- public void parse() throws IOException
+ public List<COSObject> parse() throws IOException
{
+ List<COSObject> streamObjects = new ArrayList<>();
try
{
//need to first parse the header.
- int numberOfObjects = stream.getInt( "N" );
+ int numberOfObjects = stream.getInt(COSName.N);
if (numberOfObjects == -1)
{
throw new IOException("/N entry missing in object stream");
}
List<Long> objectNumbers = new ArrayList<>( numberOfObjects );
- streamObjects = new ArrayList<>( numberOfObjects );
for( int i=0; i<numberOfObjects; i++ )
{
long objectNumber = readObjectNumber();
@@ -87,19 +87,15 @@ public class PDFObjectStreamParser exten
int objectCounter = 0;
while( (cosObject = parseDirObject()) != null )
{
- object = new COSObject(cosObject);
- object.setGenerationNumber(0);
if (objectCounter >= objectNumbers.size())
{
LOG.error("/ObjStm (object stream) has more objects than /N " + numberOfObjects);
break;
}
+ object = new COSObject(cosObject);
+ object.setGenerationNumber(0);
object.setObjectNumber( objectNumbers.get( objectCounter) );
streamObjects.add( object );
- if(LOG.isDebugEnabled())
- {
- LOG.debug( "parsed=" + object );
- }
// According to the spec objects within an object stream shall not be enclosed
// by obj/endobj tags, but there are some pdfs in the wild using those tags
// skip endobject marker if present
@@ -114,33 +110,7 @@ public class PDFObjectStreamParser exten
{
seqSource.close();
}
- }
-
- /**
- * This will get the objects that were parsed from the stream.
- *
- * @return All of the objects in the stream.
- */
- public List<COSObject> getObjects()
- {
return streamObjects;
}
- public boolean dereferenceCOSObject(COSObject obj)
- {
- if (streamObjects != null)
- {
- long objectNumber = obj.getObjectNumber();
- for (COSObject cosObject : streamObjects)
- {
- if (cosObject.getObjectNumber() == objectNumber)
- {
- obj.setObject(cosObject);
- return true;
- }
- }
- }
- return false;
- }
-
}
Modified: pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java?rev=1871057&r1=1871056&r2=1871057&view=diff
==============================================================================
--- pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java (original)
+++ pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java Sun Dec 8 18:16:38 2019
@@ -869,10 +869,8 @@ public class PreflightParser extends PDF
{
// parse object stream
PDFObjectStreamParser parser = new PDFObjectStreamParser((COSStream) objstmBaseObj, document);
- parser.parse();
-
// register all objects which are referenced to be contained in object stream
- parser.getObjects().forEach(next ->
+ parser.parse().forEach(next ->
{
COSObjectKey stmObjKey = new COSObjectKey(next);
Long offset = document.getXrefTable().get(stmObjKey);
Modified: pdfbox/branches/issue4569/tools/src/main/java/org/apache/pdfbox/tools/DecompressObjectstreams.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/tools/src/main/java/org/apache/pdfbox/tools/DecompressObjectstreams.java?rev=1871057&r1=1871056&r2=1871057&view=diff
==============================================================================
--- pdfbox/branches/issue4569/tools/src/main/java/org/apache/pdfbox/tools/DecompressObjectstreams.java (original)
+++ pdfbox/branches/issue4569/tools/src/main/java/org/apache/pdfbox/tools/DecompressObjectstreams.java Sun Dec 8 18:16:38 2019
@@ -85,8 +85,7 @@ public final class DecompressObjectstrea
{
COSStream stream = (COSStream)objStream.getObject();
PDFObjectStreamParser sp = new PDFObjectStreamParser(stream, doc.getDocument());
- sp.parse();
- for(COSObject next : sp.getObjects())
+ for (COSObject next : sp.parse())
{
COSObjectKey key = new COSObjectKey(next);
COSObject obj = doc.getDocument().getObjectFromPool(key);