pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1868005 - in /pdfbox/branches/issue4569/pdfbox/src: main/java/org/apache/pdfbox/pdfparser/ main/java/org/apache/pdfbox/pdmodel/fdf/ test/java/org/apache/pdfbox/pdmodel/ test/java/org/apache/pdfbox/pdmodel/fdf/
Date Sat, 05 Oct 2019 10:41:27 GMT
Author: lehmi
Date: Sat Oct  5 10:41:27 2019
New Revision: 1868005

URL: http://svn.apache.org/viewvc?rev=1868005&view=rev
Log:
PDFBOX-4569: moved load methods to parser

Modified:
    pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java
    pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java
    pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java
    pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationTest.java

Modified: pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java?rev=1868005&r1=1868004&r2=1868005&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java
(original)
+++ pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/FDFParser.java
Sat Oct  5 10:41:27 2019
@@ -16,7 +16,9 @@
  */
 package org.apache.pdfbox.pdfparser;
 
+import java.io.BufferedInputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -28,6 +30,8 @@ import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.io.RandomAccessBuffer;
 import org.apache.pdfbox.io.RandomAccessFile;
+import org.apache.pdfbox.pdmodel.fdf.FDFDocument;
+import org.apache.pdfbox.util.XMLUtil;
 
 public class FDFParser extends COSParser
 {
@@ -74,6 +78,96 @@ public class FDFParser extends COSParser
     }
 
     /**
+     * This will load a document from a file.
+     *
+     * @param filename The name of the file to load.
+     *
+     * @return The document that was loaded.
+     *
+     * @throws IOException If there is an error reading from the stream.
+     */
+    public static FDFDocument load(String filename) throws IOException
+    {
+        FDFParser parser = new FDFParser(filename);
+        parser.parse();
+        return new FDFDocument(parser.getDocument());
+    }
+
+    /**
+     * This will load a document from a file.
+     *
+     * @param file The name of the file to load.
+     *
+     * @return The document that was loaded.
+     *
+     * @throws IOException If there is an error reading from the stream.
+     */
+    public static FDFDocument load(File file) throws IOException
+    {
+        FDFParser parser = new FDFParser(file);
+        parser.parse();
+        return new FDFDocument(parser.getDocument());
+    }
+
+    /**
+     * This will load a document from an input stream.
+     *
+     * @param input The stream that contains the document.
+     *
+     * @return The document that was loaded.
+     *
+     * @throws IOException If there is an error reading from the stream.
+     */
+    public static FDFDocument load(InputStream input) throws IOException
+    {
+        FDFParser parser = new FDFParser(input);
+        parser.parse();
+        return new FDFDocument(parser.getDocument());
+    }
+
+    /**
+     * This will load a document from a file.
+     *
+     * @param filename The name of the file to load.
+     *
+     * @return The document that was loaded.
+     *
+     * @throws IOException If there is an error reading from the stream.
+     */
+    public static FDFDocument loadXFDF(String filename) throws IOException
+    {
+        return loadXFDF(new BufferedInputStream(new FileInputStream(filename)));
+    }
+
+    /**
+     * This will load a document from a file.
+     *
+     * @param file The name of the file to load.
+     *
+     * @return The document that was loaded.
+     *
+     * @throws IOException If there is an error reading from the stream.
+     */
+    public static FDFDocument loadXFDF(File file) throws IOException
+    {
+        return loadXFDF(new BufferedInputStream(new FileInputStream(file)));
+    }
+
+    /**
+     * This will load a document from an input stream.
+     *
+     * @param input The stream that contains the document.
+     *
+     * @return The document that was loaded.
+     *
+     * @throws IOException If there is an error reading from the stream.
+     */
+    public static FDFDocument loadXFDF(InputStream input) throws IOException
+    {
+        return new FDFDocument(XMLUtil.parse(input));
+    }
+
+    /**
      * Tell if the dictionary is a FDF catalog.
      *
      * @param dictionary
@@ -85,7 +179,7 @@ public class FDFParser extends COSParser
         return dictionary.containsKey(COSName.FDF);
     }
 
-    private void init() throws IOException
+    private void init()
     {
         String eofLookupRangeStr = System.getProperty(SYSPROP_EOFLOOKUPRANGE);
         if (eofLookupRangeStr != null)

Modified: pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java?rev=1868005&r1=1868004&r2=1868005&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java
(original)
+++ pdfbox/branches/issue4569/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDocument.java
Sat Oct  5 10:41:27 2019
@@ -16,24 +16,20 @@
  */
 package org.apache.pdfbox.pdmodel.fdf;
 
-import java.io.BufferedInputStream;
 import java.io.BufferedWriter;
 import java.io.Closeable;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileOutputStream;
-import java.io.InputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
+import java.nio.charset.StandardCharsets;
 
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSDocument;
 import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.pdfparser.FDFParser;
 import org.apache.pdfbox.pdfwriter.COSWriter;
-import org.apache.pdfbox.util.XMLUtil;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -154,96 +150,6 @@ public class FDFDocument implements Clos
     }
 
     /**
-     * This will load a document from a file.
-     *
-     * @param filename The name of the file to load.
-     *
-     * @return The document that was loaded.
-     *
-     * @throws IOException If there is an error reading from the stream.
-     */
-    public static FDFDocument load(String filename) throws IOException
-    {
-        FDFParser parser = new FDFParser(filename);
-        parser.parse();
-        return new FDFDocument(parser.getDocument());
-    }
-
-    /**
-     * This will load a document from a file.
-     *
-     * @param file The name of the file to load.
-     *
-     * @return The document that was loaded.
-     *
-     * @throws IOException If there is an error reading from the stream.
-     */
-    public static FDFDocument load(File file) throws IOException
-    {
-        FDFParser parser = new FDFParser(file);
-        parser.parse();
-        return new FDFDocument(parser.getDocument());
-    }
-
-    /**
-     * This will load a document from an input stream.
-     *
-     * @param input The stream that contains the document.
-     *
-     * @return The document that was loaded.
-     *
-     * @throws IOException If there is an error reading from the stream.
-     */
-    public static FDFDocument load(InputStream input) throws IOException
-    {
-        FDFParser parser = new FDFParser(input);
-        parser.parse();
-        return new FDFDocument(parser.getDocument());
-    }
-
-    /**
-     * This will load a document from a file.
-     *
-     * @param filename The name of the file to load.
-     *
-     * @return The document that was loaded.
-     *
-     * @throws IOException If there is an error reading from the stream.
-     */
-    public static FDFDocument loadXFDF(String filename) throws IOException
-    {
-        return loadXFDF(new BufferedInputStream(new FileInputStream(filename)));
-    }
-
-    /**
-     * This will load a document from a file.
-     *
-     * @param file The name of the file to load.
-     *
-     * @return The document that was loaded.
-     *
-     * @throws IOException If there is an error reading from the stream.
-     */
-    public static FDFDocument loadXFDF(File file) throws IOException
-    {
-        return loadXFDF(new BufferedInputStream(new FileInputStream(file)));
-    }
-
-    /**
-     * This will load a document from an input stream.
-     *
-     * @param input The stream that contains the document.
-     *
-     * @return The document that was loaded.
-     *
-     * @throws IOException If there is an error reading from the stream.
-     */
-    public static FDFDocument loadXFDF(InputStream input) throws IOException
-    {
-        return new FDFDocument(XMLUtil.parse(input));
-    }
-
-    /**
      * This will save this document to the filesystem.
      *
      * @param fileName The file to save as.
@@ -292,7 +198,7 @@ public class FDFDocument implements Clos
     public void saveXFDF(File fileName) throws IOException
     {
         saveXFDF(new BufferedWriter(
-                new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8")));
+                new OutputStreamWriter(new FileOutputStream(fileName), StandardCharsets.UTF_8)));
     }
 
     /**
@@ -305,7 +211,7 @@ public class FDFDocument implements Clos
     public void saveXFDF(String fileName) throws IOException
     {
         saveXFDF(new BufferedWriter(
-                new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8")));
+                new OutputStreamWriter(new FileOutputStream(fileName), StandardCharsets.UTF_8)));
     }
 
     /**

Modified: pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java?rev=1868005&r1=1868004&r2=1868005&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java
(original)
+++ pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java
Sat Oct  5 10:41:27 2019
@@ -23,6 +23,8 @@ import java.io.PrintWriter;
 import java.net.URISyntaxException;
 import java.util.List;
 import junit.framework.TestCase;
+
+import org.apache.pdfbox.pdfparser.FDFParser;
 import org.apache.pdfbox.pdmodel.fdf.FDFDocument;
 import org.apache.pdfbox.pdmodel.fdf.FDFField;
 import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
@@ -51,7 +53,7 @@ public class TestFDF extends TestCase
 
     private void checkFields(String name) throws IOException, URISyntaxException
     {
-        try (FDFDocument fdf = FDFDocument.load(new File(TestFDF.class.getResource(name).toURI())))
+        try (FDFDocument fdf = FDFParser.load(new File(TestFDF.class.getResource(name).toURI())))
         {
             fdf.saveXFDF(new PrintWriter(new ByteArrayOutputStream()));
             

Modified: pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationTest.java?rev=1868005&r1=1868004&r2=1868005&view=diff
==============================================================================
--- pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationTest.java
(original)
+++ pdfbox/branches/issue4569/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationTest.java
Sat Oct  5 10:41:27 2019
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertEqu
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.util.List;
+
+import org.apache.pdfbox.pdfparser.FDFParser;
 import org.junit.Assert;
 
 import org.junit.Test;
@@ -38,7 +40,7 @@ public class FDFAnnotationTest
     public void loadXFDFAnnotations() throws IOException, URISyntaxException
     {
         File f = new File(FDFAnnotationTest.class.getResource("xfdf-test-document-annotations.xml").toURI());
-        try (FDFDocument fdfDoc = FDFDocument.loadXFDF(f))
+        try (FDFDocument fdfDoc = FDFParser.loadXFDF(f))
         {
             List<FDFAnnotation> fdfAnnots = fdfDoc.getCatalog().getFDF().getAnnotations();
             assertEquals(18, fdfAnnots.size());



Mime
View raw message