pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1816169 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
Date Thu, 23 Nov 2017 16:56:15 GMT
Author: lehmi
Date: Thu Nov 23 16:56:15 2017
New Revision: 1816169

URL: http://svn.apache.org/viewvc?rev=1816169&view=rev
Log:
PDFBOX-4018: optimized checkObjectKey method

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java?rev=1816169&r1=1816168&r2=1816169&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/COSParser.java Thu
Nov 23 16:56:15 2017
@@ -1398,7 +1398,7 @@ public class COSParser extends BaseParse
             // a negative offset number represents a object number itself
             // see type 2 entry in xref stream
             if (objectOffset != null && objectOffset >= 0
-                    && !checkObjectKeys(objectKey, objectOffset))
+                    && !checkObjectKey(objectKey, objectOffset))
             {
                 LOG.debug("Stop checking xref offsets as at least one (" + objectKey
                         + ") couldn't be dereferenced");
@@ -1441,25 +1441,25 @@ public class COSParser extends BaseParse
      * @return returns true if the given object can be dereferenced at the given offset
      * @throws IOException if something went wrong
      */
-    private boolean checkObjectKeys(COSObjectKey objectKey, long offset) throws IOException
+    private boolean checkObjectKey(COSObjectKey objectKey, long offset) throws IOException
     {
         // there can't be any object at the very beginning of a pdf
         if (offset < MINIMUM_SEARCH_OFFSET)
         {
             return false;
         }
-        long objectNr = objectKey.getNumber();
-        int objectGen = objectKey.getGeneration();
+        boolean objectKeyFound = false;
         long originOffset = source.getPosition();
-        String objectString = createObjectString(objectNr, objectGen);
         try 
         {
             source.seek(offset);
-            if (isString(objectString.getBytes(ISO_8859_1)))
+            // try to read the given object/generation number
+            if (objectKey.getNumber() == readObjectNumber()
+                    && objectKey.getGeneration() == readGenerationNumber())
             {
-                // everything is ok, return origin object key
-                source.seek(originOffset);
-                return true;
+                // finally tro to read the object marker
+                readExpectedString(OBJ_MARKER, true);
+                objectKeyFound = true;
             }
         }
         catch (IOException exception)
@@ -1470,19 +1470,8 @@ public class COSParser extends BaseParse
         {
             source.seek(originOffset);
         }
-        // no valid object number found
-        return false;
-    }
-    /**
-     * Create a string for the given object id.
-     * 
-     * @param objectID the object id
-     * @param genID the generation id
-     * @return the generated string
-     */
-    private String createObjectString(long objectID, int genID)
-    {
-        return Long.toString(objectID) + " " + Integer.toString(genID) + " obj";
+        // return resulting value
+        return objectKeyFound;
     }
 
     /**



Mime
View raw message