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/09/10 12:11:23 UTC

svn commit: r1866741 - in /pdfbox/branches/issue4569: ./ preflight/src/main/java/org/apache/pdfbox/preflight/ preflight/src/main/java/org/apache/pdfbox/preflight/parser/ preflight/src/main/java/org/apache/pdfbox/preflight/utils/

Author: lehmi
Date: Tue Sep 10 12:11:22 2019
New Revision: 1866741

URL: http://svn.apache.org/viewvc?rev=1866741&view=rev
Log:
PDFBOX-4340: remove usage of DataSource interface

Removed:
    pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/utils/ByteArrayDataSource.java
    pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/utils/DataSource.java
    pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/utils/FileDataSource.java
Modified:
    pdfbox/branches/issue4569/   (props changed)
    pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java
    pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java
    pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java

Propchange: pdfbox/branches/issue4569/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Sep 10 12:11:22 2019
@@ -1,4 +1,4 @@
 /pdfbox/branches/2.0:1760418,1761484,1762133,1763609,1779822,1780783,1780789,1782684,1784450,1792784,1795704,1795712,1799081-1799082,1814046,1814285,1814459,1824914,1825811,1825820,1825912,1844477,1844516,1844519,1844567,1850577,1857953,1858696,1858698,1860825
 /pdfbox/branches/no-awt:1618517-1621410
 /pdfbox/no-awt:1618514-1618516
-/pdfbox/trunk:1861927,1861933,1862347,1862350
+/pdfbox/trunk:1861927,1861933,1862347,1862350,1866739

Modified: pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java?rev=1866741&r1=1866740&r2=1866741&view=diff
==============================================================================
--- pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java (original)
+++ pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/Validator_A1b.java Tue Sep 10 12:11:22 2019
@@ -43,7 +43,6 @@ import org.apache.pdfbox.preflight.Valid
 import org.apache.pdfbox.preflight.exception.SyntaxValidationException;
 import org.apache.pdfbox.preflight.parser.PreflightParser;
 import org.apache.pdfbox.preflight.parser.XmlResultParser;
-import org.apache.pdfbox.preflight.utils.FileDataSource;
 import org.apache.pdfbox.util.Version;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -107,7 +106,7 @@ public class Validator_A1b
                     root.setAttribute("count", String.format("%d", ftp.size()));
                     for (File file : ftp)
                     {
-                        Element result = xrp.validate(document,new FileDataSource(file));
+                        Element result = xrp.validate(document, file);
                         root.appendChild(result);
                     }
                     transformer.transform(new DOMSource(document), 
@@ -118,7 +117,7 @@ public class Validator_A1b
                     // isBatch
                     for (File file : ftp)
                     {
-                        Element result = xrp.validate(new FileDataSource(file));
+                        Element result = xrp.validate(file);
                         Document document = result.getOwnerDocument();
                         document.appendChild(result);
                         transformer.transform(new DOMSource(document), 
@@ -138,7 +137,7 @@ public class Validator_A1b
             {
                 // generate xml output
                 XmlResultParser xrp = new XmlResultParser();
-                Element result = xrp.validate(new FileDataSource(new File(args[posFile])));
+                Element result = xrp.validate(new File(args[posFile]));
                 Document document = result.getOwnerDocument();
                 document.appendChild(result);
                 Transformer transformer = TransformerFactory.newInstance().newTransformer();

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=1866741&r1=1866740&r2=1866741&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 Tue Sep 10 12:11:22 2019
@@ -44,6 +44,7 @@ import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.cos.COSString;
 import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream;
+import org.apache.pdfbox.io.RandomAccessRead;
 import org.apache.pdfbox.io.ScratchFile;
 import org.apache.pdfbox.pdfparser.PDFObjectStreamParser;
 import org.apache.pdfbox.pdfparser.PDFParser;
@@ -79,8 +80,6 @@ import static org.apache.pdfbox.prefligh
 import static org.apache.pdfbox.preflight.PreflightConstants.MAX_NEGATIVE_FLOAT;
 import static org.apache.pdfbox.preflight.PreflightConstants.MAX_POSITIVE_FLOAT;
 import static org.apache.pdfbox.preflight.PreflightConstants.MAX_STRING_LENGTH;
-import org.apache.pdfbox.preflight.utils.DataSource;
-import org.apache.pdfbox.preflight.utils.FileDataSource;
 
 public class PreflightParser extends PDFParser
 {
@@ -90,8 +89,6 @@ public class PreflightParser extends PDF
      */
     public static final Charset encoding = Charset.forName("ISO-8859-1");
 
-    protected DataSource dataSource;
-
     protected ValidationResult validationResult;
 
     protected PreflightDocument preflightDocument;
@@ -109,7 +106,6 @@ public class PreflightParser extends PDF
         // TODO move file handling outside of the parser
         super(new RandomAccessBufferedFileInputStream(file));
         this.setLenient(false);
-        this.dataSource = new FileDataSource(file);
     }
 
     /**
@@ -124,7 +120,6 @@ public class PreflightParser extends PDF
         // TODO move file handling outside of the parser
         super(new RandomAccessBufferedFileInputStream(file), scratch);
         this.setLenient(false);
-        this.dataSource = new FileDataSource(file);
     }
 
     /**
@@ -159,12 +154,11 @@ public class PreflightParser extends PDF
      * @param dataSource the datasource
      * @throws IOException if there is a reading error.
      */
-    public PreflightParser(DataSource dataSource) throws IOException
+    public PreflightParser(RandomAccessRead source) throws IOException
     {
         // TODO move file handling outside of the parser
-        super(new RandomAccessBufferedFileInputStream(dataSource.getInputStream()));
+        super(source);
         this.setLenient(false);
-        this.dataSource = dataSource;
     }
 
     /**
@@ -175,12 +169,11 @@ public class PreflightParser extends PDF
      * @param scratch
      * @throws IOException if there is a reading error.
      */
-    public PreflightParser(DataSource dataSource, ScratchFile scratch) throws IOException
+    public PreflightParser(RandomAccessRead source, ScratchFile scratch) throws IOException
     {
         // TODO move file handling outside of the parser
-        super(new RandomAccessBufferedFileInputStream(dataSource.getInputStream()), scratch);
+        super(source, scratch);
         this.setLenient(false);
-        this.dataSource = dataSource;
     }
 
     /**

Modified: pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java?rev=1866741&r1=1866740&r2=1866741&view=diff
==============================================================================
--- pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java (original)
+++ pdfbox/branches/issue4569/preflight/src/main/java/org/apache/pdfbox/preflight/parser/XmlResultParser.java Tue Sep 10 12:11:22 2019
@@ -21,6 +21,7 @@
 
 package org.apache.pdfbox.preflight.parser;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
@@ -31,11 +32,12 @@ import java.util.Map;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
+import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream;
+import org.apache.pdfbox.io.RandomAccessRead;
 import org.apache.pdfbox.preflight.PreflightDocument;
 import org.apache.pdfbox.preflight.ValidationResult;
 import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
 import org.apache.pdfbox.preflight.exception.SyntaxValidationException;
-import org.apache.pdfbox.preflight.utils.DataSource;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -43,12 +45,22 @@ public class XmlResultParser
 {
 
 
-    public Element validate(DataSource dataSource) throws IOException
+    public Element validate(File file) throws IOException
+    {
+        return validate(new RandomAccessBufferedFileInputStream(file), file.getName());
+    }
+
+    public Element validate(Document rdocument, File file) throws IOException
+    {
+        return validate(rdocument, new RandomAccessBufferedFileInputStream(file), file.getName());
+    }
+
+    private Element validate(RandomAccessRead source, String name) throws IOException
     {
         try
         {
             Document rdocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
-            return validate(rdocument,dataSource);
+            return validate(rdocument, source, name);
         }
         catch (ParserConfigurationException e)
         {
@@ -57,14 +69,15 @@ public class XmlResultParser
     }
 
 
-    public Element validate(Document rdocument, DataSource dataSource) throws IOException
+    private Element validate(Document rdocument, RandomAccessRead source, String name)
+            throws IOException
     {
         String pdfType = null;
         ValidationResult result;
         long before = System.currentTimeMillis();
         try
         {
-            PreflightParser parser = new PreflightParser(dataSource);
+            PreflightParser parser = new PreflightParser(source);
             try
             {
                 parser.parse();
@@ -83,13 +96,13 @@ public class XmlResultParser
         catch(Exception e) 
         {
             long after = System.currentTimeMillis();
-            return generateFailureResponse(rdocument, dataSource.getName(), after-before, pdfType, e);
+            return generateFailureResponse(rdocument, name, after - before, pdfType, e);
         }
 
         long after = System.currentTimeMillis();
         if (result.isValid())
         {
-            Element preflight = generateResponseSkeleton(rdocument, dataSource.getName(), after-before);
+            Element preflight = generateResponseSkeleton(rdocument, name, after - before);
             // valid ?
             Element valid = rdocument.createElement("isValid");
             valid.setAttribute("type", pdfType);
@@ -99,7 +112,7 @@ public class XmlResultParser
         }
         else
         {
-            Element preflight = generateResponseSkeleton(rdocument, dataSource.getName(), after-before);
+            Element preflight = generateResponseSkeleton(rdocument, name, after - before);
             // valid ?
             createResponseWithError(rdocument, pdfType, result, preflight);
             return preflight;