You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2019/07/20 09:34:18 UTC

svn commit: r1863460 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSString.java

Author: tilman
Date: Sat Jul 20 09:34:18 2019
New Revision: 1863460

URL: http://svn.apache.org/viewvc?rev=1863460&view=rev
Log:
PDFBOX-4071: SonarQube fix: move constructors to comply with Java Code Conventions

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSString.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSString.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSString.java?rev=1863460&r1=1863459&r2=1863460&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSString.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSString.java Sat Jul 20 09:34:18 2019
@@ -47,56 +47,14 @@ public final class COSString extends COS
 {
     private static final Log LOG = LogFactory.getLog(COSString.class);
 
+    private byte[] bytes;
+    private boolean forceHexForm;
+
     // legacy behaviour for old PDFParser
     public static final boolean FORCE_PARSING =
             Boolean.getBoolean("org.apache.pdfbox.forceParsing");
 
     /**
-     * This will create a COS string from a string of hex characters.
-     *
-     * @param hex A hex string.
-     * @return A cos string with the hex characters converted to their actual bytes.
-     * @throws IOException If there is an error with the hex string.
-     */
-    public static COSString parseHex(String hex) throws IOException
-    {
-        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
-        StringBuilder hexBuffer = new StringBuilder(hex.trim());
-
-        // if odd number then the last hex digit is assumed to be 0
-        if (hexBuffer.length() % 2 != 0)
-        {
-            hexBuffer.append('0');
-        }
-
-        int length = hexBuffer.length();
-        for (int i = 0; i < length; i += 2)
-        {
-            try
-            {
-                bytes.write(Integer.parseInt(hexBuffer.substring(i, i + 2), 16));
-            }
-            catch (NumberFormatException e)
-            {
-                if (FORCE_PARSING)
-                {
-                    LOG.warn("Encountered a malformed hex string");
-                    bytes.write('?'); // todo: what does Acrobat do? Any example PDFs?
-                }
-                else
-                {
-                    throw new IOException("Invalid hex string: " + hex, e);
-                }
-            }
-        }
-
-        return new COSString(bytes.toByteArray());
-    }
-
-    private byte[] bytes;
-    private boolean forceHexForm;
-
-    /**
      * Creates a new PDF string from a byte array. This method can be used to read a string from
      * an existing PDF file, or to create a new byte string.
      *
@@ -151,6 +109,48 @@ public final class COSString extends COS
     }
 
     /**
+     * This will create a COS string from a string of hex characters.
+     *
+     * @param hex A hex string.
+     * @return A cos string with the hex characters converted to their actual bytes.
+     * @throws IOException If there is an error with the hex string.
+     */
+    public static COSString parseHex(String hex) throws IOException
+    {
+        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+        StringBuilder hexBuffer = new StringBuilder(hex.trim());
+
+        // if odd number then the last hex digit is assumed to be 0
+        if (hexBuffer.length() % 2 != 0)
+        {
+            hexBuffer.append('0');
+        }
+
+        int length = hexBuffer.length();
+        for (int i = 0; i < length; i += 2)
+        {
+            try
+            {
+                bytes.write(Integer.parseInt(hexBuffer.substring(i, i + 2), 16));
+            }
+            catch (NumberFormatException e)
+            {
+                if (FORCE_PARSING)
+                {
+                    LOG.warn("Encountered a malformed hex string");
+                    bytes.write('?'); // todo: what does Acrobat do? Any example PDFs?
+                }
+                else
+                {
+                    throw new IOException("Invalid hex string: " + hex, e);
+                }
+            }
+        }
+
+        return new COSString(bytes.toByteArray());
+    }
+
+    /**
      * Sets the raw value of this string.
      *
      * @param value The raw bytes of the PDF text string or byte string.