From f44a63833a45ee8f67589334f56549a5d7b72fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Sch=C3=A4fer?= Date: Sun, 22 Mar 2015 17:39:38 +0100 Subject: [PATCH] Use Base64-decoder from JAXB instead of Apache/Sun This removes the dependeny on Apache Commons Codec, which was solely used for Base64 decoding. Uses of both org.apache.commons.codec.binary.Base64 and sun.misc.BASE64Decoder are replaced by javax.xml.bind.DatatypeConverter which is part of Java since 1.6. --- src/com/kitfox/svg/SVGUniverse.java | 7 ++++--- src/com/kitfox/svg/app/data/Handler.java | 7 ++++--- src/oauth/signpost/signature/OAuthMessageSigner.java | 13 +++---------- src/org/openstreetmap/josm/tools/ImageProvider.java | 4 ++-- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/com/kitfox/svg/SVGUniverse.java b/src/com/kitfox/svg/SVGUniverse.java index 9c244dd..1fe4a3d 100644 --- a/src/com/kitfox/svg/SVGUniverse.java +++ b/src/com/kitfox/svg/SVGUniverse.java @@ -61,6 +61,7 @@ import java.util.logging.Logger; import java.util.zip.GZIPInputStream; import javax.imageio.ImageIO; +import javax.xml.bind.DatatypeConverter; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -190,10 +191,9 @@ URL registerImage(URI imageURI) if (content.startsWith("base64")) { - content = content.substring(6); try { - byte[] buf = new sun.misc.BASE64Decoder().decodeBuffer(content); + byte[] buf = DatatypeConverter.parseBase64Binary(content.substring(6)); ByteArrayInputStream bais = new ByteArrayInputStream(buf); BufferedImage img = ImageIO.read(bais); @@ -213,7 +213,8 @@ URL registerImage(URI imageURI) loadedImages.put(url, ref); return url; - } catch (IOException ex) + } + catch (IOException | IllegalArgumentException ex) { Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, "Could not decode inline image", ex); diff --git a/src/com/kitfox/svg/app/data/Handler.java b/src/com/kitfox/svg/app/data/Handler.java index 806dcd9..e35c260 100644 --- a/src/com/kitfox/svg/app/data/Handler.java +++ b/src/com/kitfox/svg/app/data/Handler.java @@ -44,6 +44,8 @@ import java.util.logging.Level; import java.util.logging.Logger; +import javax.xml.bind.DatatypeConverter; + /** * * @author kitfox @@ -66,12 +68,11 @@ public Connection(URL url) if (content.startsWith("base64,")) { - content = content.substring(7); try { - buf = new sun.misc.BASE64Decoder().decodeBuffer(content); + buf = DatatypeConverter.parseBase64Binary(content.substring(7)); } - catch (IOException e) + catch (IllegalArgumentException e) { Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e); } diff --git a/src/oauth/signpost/signature/OAuthMessageSigner.java b/src/oauth/signpost/signature/OAuthMessageSigner.java index 8d878ae..e24092d 100644 --- a/src/oauth/signpost/signature/OAuthMessageSigner.java +++ b/src/oauth/signpost/signature/OAuthMessageSigner.java @@ -16,26 +16,20 @@ import java.io.IOException; import java.io.Serializable; +import javax.xml.bind.DatatypeConverter; import oauth.signpost.exception.OAuthMessageSignerException; import oauth.signpost.http.HttpRequest; import oauth.signpost.http.HttpParameters; -import org.apache.commons.codec.binary.Base64; - public abstract class OAuthMessageSigner implements Serializable { private static final long serialVersionUID = 4445779788786131202L; - private transient Base64 base64; - private String consumerSecret; private String tokenSecret; - public OAuthMessageSigner() { - this.base64 = new Base64(); - } public abstract String sign(HttpRequest request, HttpParameters requestParameters) throws OAuthMessageSignerException; @@ -59,16 +53,15 @@ public void setTokenSecret(String tokenSecret) { } protected byte[] decodeBase64(String s) { - return base64.decode(s.getBytes()); + return DatatypeConverter.parseBase64Binary(s); } protected String base64Encode(byte[] b) { - return new String(base64.encode(b)); + return DatatypeConverter.printBase64Binary(b); } private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); - this.base64 = new Base64(); } }