pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1852179 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf: FDFAnnotationStamp.java FDFStampAnnotationAppearance.java
Date Fri, 25 Jan 2019 20:38:12 GMT
Author: tilman
Date: Fri Jan 25 20:38:11 2019
New Revision: 1852179

URL: http://svn.apache.org/viewvc?rev=1852179&view=rev
Log:
PDFBOX-4437: simplify code + use jdk7 syntax

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationStamp.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFStampAnnotationAppearance.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationStamp.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationStamp.java?rev=1852179&r1=1852178&r2=1852179&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationStamp.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationStamp.java
Fri Jan 25 20:38:11 2019
@@ -140,12 +140,7 @@ public class FDFAnnotationStamp extends
             // Parse the content to Document object
             return builder.parse(new ByteArrayInputStream(xml));
         }
-        catch (ParserConfigurationException ex)
-        {
-            LOG.error("Error while converting appearance xml to document: " + ex);
-            throw new IOException(ex);
-        }
-        catch (SAXException ex)
+        catch (ParserConfigurationException | SAXException ex)
         {
             LOG.error("Error while converting appearance xml to document: " + ex);
             throw new IOException(ex);

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFStampAnnotationAppearance.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFStampAnnotationAppearance.java?rev=1852179&r1=1852178&r2=1852179&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFStampAnnotationAppearance.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFStampAnnotationAppearance.java
Fri Jan 25 20:38:11 2019
@@ -77,8 +77,6 @@ class FDFStampAnnotationAppearance imple
         LOG.debug("Build dictionary for Appearance based on the appearanceXML");
 
         NodeList nodeList = appearanceXML.getChildNodes();
-        Node node = null;
-        Element child = null;
         String parentAttrKey = appearanceXML.getAttribute("KEY");
         LOG.debug("Appearance Root - tag: " + appearanceXML.getTagName() + ", name: " + 
                 appearanceXML.getNodeName() + ", key: " + parentAttrKey + ", children: "
+ 
@@ -89,10 +87,10 @@ class FDFStampAnnotationAppearance imple
         {
             for (int i = 0; i < nodeList.getLength(); i++)
             {
-                node = nodeList.item(i);
+                Node node = nodeList.item(i);
                 if (node instanceof Element)
                 {
-                    child = (Element) node;
+                    Element child = (Element) node;
                     if ("STREAM".equalsIgnoreCase(child.getTagName()))
                     {
                         LOG.debug(parentAttrKey +
@@ -127,20 +125,16 @@ class FDFStampAnnotationAppearance imple
         COSStream stream = new COSStream();
 
         NodeList nodeList = streamEl.getChildNodes();
-        Node node;
-        Element child;
-        String childAttrKey;
-        String childAttrVal;
         String parentAttrKey = streamEl.getAttribute("KEY");
 
         for (int i = 0; i < nodeList.getLength(); i++)
         {
-            node = nodeList.item(i);
+            Node node = nodeList.item(i);
             if (node instanceof Element)
             {
-                child = (Element) node;
-                childAttrKey = child.getAttribute("KEY");
-                childAttrVal = child.getAttribute("VAL");
+                Element child = (Element) node;
+                String childAttrKey = child.getAttribute("KEY");
+                String childAttrVal = child.getAttribute("VAL");
                 LOG.debug(parentAttrKey + " => reading child: " + child.getTagName() +
                            " with key: " + childAttrKey);
                 if ("INT".equalsIgnoreCase(child.getTagName()))
@@ -179,28 +173,19 @@ class FDFStampAnnotationAppearance imple
                 else if ("DATA".equalsIgnoreCase(child.getTagName()))
                 {
                     LOG.debug(parentAttrKey + " => Handling DATA with encoding: " +
-                            child.getAttribute("ENCODING"));
+                              child.getAttribute("ENCODING"));
                     if ("HEX".equals(child.getAttribute("ENCODING")))
                     {
-                        OutputStream os = null;
-                        try
+                        try (OutputStream os = stream.createRawOutputStream())
                         {
-                            os = stream.createRawOutputStream();
                             os.write(Hex.decodeHex(child.getTextContent()));
                             LOG.debug(parentAttrKey + " => Data was streamed");
                         }
-                        finally
-                        {
-                            if (os != null)
-                            {
-                                os.close();
-                            }
-                        }
                     }
                     else
                     {
                         LOG.warn(parentAttrKey + " => Not handling element DATA encoding:
" +
-                                child.getAttribute("ENCODING"));
+                                 child.getAttribute("ENCODING"));
                     }
                 }
                 else
@@ -218,8 +203,6 @@ class FDFStampAnnotationAppearance imple
         LOG.debug("Parse " + arrayEl.getAttribute("KEY") + " Array");
         COSArray array = new COSArray();
         NodeList nodeList = arrayEl.getElementsByTagName("FIXED");
-        Node node;
-        Element el;
         String elAttrKey = arrayEl.getAttribute("KEY");
 
         if ("BBox".equals(elAttrKey))
@@ -243,10 +226,10 @@ class FDFStampAnnotationAppearance imple
 
         for (int i = 0; i < nodeList.getLength(); i++)
         {
-            node = nodeList.item(i);
+            Node node = nodeList.item(i);
             if (node instanceof Element)
             {
-                el = (Element) node;
+                Element el = (Element) node;
                 LOG.debug(elAttrKey + " value(" + i + "): " + el.getAttribute("VAL"));
                 array.add(new COSFloat(el.getAttribute("VAL")));
             }
@@ -261,20 +244,16 @@ class FDFStampAnnotationAppearance imple
         COSDictionary dict = new COSDictionary();
 
         NodeList nodeList = dictEl.getChildNodes();
-        Node node;
-        Element child;
-        String childAttrKey;
-        String childAttrVal;
         String parentAttrKey = dictEl.getAttribute("KEY");
 
         for (int i = 0; i < nodeList.getLength(); i++)
         {
-            node = nodeList.item(i);
+            Node node = nodeList.item(i);
             if (node instanceof Element)
             {
-                child = (Element) node;
-                childAttrKey = child.getAttribute("KEY");
-                childAttrVal = child.getAttribute("VAL");
+                Element child = (Element) node;
+                String childAttrKey = child.getAttribute("KEY");
+                String childAttrVal = child.getAttribute("VAL");
 
                 if ("DICT".equals(child.getTagName()))
                 {



Mime
View raw message