pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1867715 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: rendering/PDFRenderer.java util/Hex.java
Date Sun, 29 Sep 2019 09:41:26 GMT
Author: tilman
Date: Sun Sep 29 09:41:26 2019
New Revision: 1867715

URL: http://svn.apache.org/viewvc?rev=1867715&view=rev
Log:
PDFBOX-4071: remove pre-jdk8 assumptions because we're on jdk8

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Hex.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java?rev=1867715&r1=1867714&r2=1867715&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java Sun Sep
29 09:41:26 2019
@@ -24,7 +24,6 @@ import java.awt.GraphicsDevice;
 import java.awt.RenderingHints;
 import java.awt.image.BufferedImage;
 import java.io.IOException;
-import java.util.StringTokenizer;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import org.apache.commons.logging.Log;
@@ -549,7 +548,7 @@ public class PDFRenderer
     private static void suggestKCMS()
     {
         String cmmProperty = System.getProperty("sun.java2d.cmm");
-        if (isMinJdk8() && !"sun.java2d.cmm.kcms.KcmsServiceProvider".equals(cmmProperty))
+        if (!"sun.java2d.cmm.kcms.KcmsServiceProvider".equals(cmmProperty))
         {
             try
             {
@@ -598,26 +597,4 @@ public class PDFRenderer
         }
         return false;
     }
-
-    private static boolean isMinJdk8()
-    {
-        // strategy from lucene-solr/lucene/core/src/java/org/apache/lucene/util/Constants.java
-        String version = System.getProperty("java.specification.version");
-        final StringTokenizer st = new StringTokenizer(version, ".");
-        try
-        {
-            int major = Integer.parseInt(st.nextToken());
-            int minor = 0;
-            if (st.hasMoreTokens())
-            {
-                minor = Integer.parseInt(st.nextToken());
-            }
-            return major > 1 || (major == 1 && minor >= 8);
-        }
-        catch (NumberFormatException nfe)
-        {
-            // maybe some new numbering scheme in the 22nd century
-            return true;
-        }
-    }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Hex.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Hex.java?rev=1867715&r1=1867714&r2=1867715&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Hex.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Hex.java Sun Sep 29 09:41:26
2019
@@ -20,7 +20,7 @@ package org.apache.pdfbox.util;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.lang.reflect.Method;
+import java.util.Base64;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -191,33 +191,7 @@ public final class Hex
      */
     public static byte[] decodeBase64(String base64Value)
     {
-        // https://stackoverflow.com/questions/469695/decode-base64-data-in-java
-        try
-        {
-            // jdk8 and higher? java.util.Base64.getDecoder().decode()
-            Class<?> b64Class = Class.forName("java.util.Base64");
-            Method getDecoderMethod = b64Class.getMethod("getDecoder");
-            Object base64Decoder = getDecoderMethod.invoke(b64Class);
-            Method decodeMethod = base64Decoder.getClass().getMethod("decode", String.class);
-            return (byte[]) decodeMethod.invoke(base64Decoder, base64Value.replaceAll("\\s",
""));
-        }
-        catch (ReflectiveOperationException | SecurityException ex)
-        {
-            LOG.debug(ex);
-        }
-        try
-        {
-            // up to java7? javax.xml.bind.DatatypeConverter.parseBase64Binary()
-            Class<?> datatypeConverterClass = Class.forName("javax.xml.bind.DatatypeConverter");
-            Method parseBase64BinaryMethod = datatypeConverterClass.getMethod("parseBase64Binary",
String.class);
-            return (byte[]) parseBase64BinaryMethod.invoke(null, base64Value);
-        }
-        catch (ReflectiveOperationException | SecurityException ex)
-        {
-            LOG.debug(ex);
-        }
-        LOG.error("Can't decode base64 value, try adding javax.xml.bind:jaxb-api to your
build");
-        return new byte[0];
+        return Base64.getDecoder().decode(base64Value.replaceAll("\\s", ""));
     }
 
     /**



Mime
View raw message