[8149] | 1 | From f44a63833a45ee8f67589334f56549a5d7b72fa4 Mon Sep 17 00:00:00 2001
|
---|
| 2 | From: =?UTF-8?q?Florian=20Sch=C3=A4fer?= <florian@schaeferban.de>
|
---|
| 3 | Date: Sun, 22 Mar 2015 17:39:38 +0100
|
---|
| 4 | Subject: [PATCH] Use Base64-decoder from JAXB instead of Apache/Sun
|
---|
| 5 |
|
---|
| 6 | This removes the dependeny on Apache Commons Codec, which was solely used for Base64 decoding.
|
---|
| 7 | 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.
|
---|
| 8 | ---
|
---|
| 9 | src/com/kitfox/svg/SVGUniverse.java | 7 ++++---
|
---|
| 10 | src/com/kitfox/svg/app/data/Handler.java | 7 ++++---
|
---|
| 11 | src/oauth/signpost/signature/OAuthMessageSigner.java | 13 +++----------
|
---|
| 12 | src/org/openstreetmap/josm/tools/ImageProvider.java | 4 ++--
|
---|
| 13 | 4 files changed, 13 insertions(+), 18 deletions(-)
|
---|
| 14 |
|
---|
| 15 | diff --git a/src/com/kitfox/svg/SVGUniverse.java b/src/com/kitfox/svg/SVGUniverse.java
|
---|
| 16 | index 9c244dd..1fe4a3d 100644
|
---|
| 17 | --- a/src/com/kitfox/svg/SVGUniverse.java
|
---|
| 18 | +++ b/src/com/kitfox/svg/SVGUniverse.java
|
---|
| 19 | @@ -61,6 +61,7 @@
|
---|
| 20 | import java.util.logging.Logger;
|
---|
| 21 | import java.util.zip.GZIPInputStream;
|
---|
| 22 | import javax.imageio.ImageIO;
|
---|
| 23 | +import javax.xml.bind.DatatypeConverter;
|
---|
| 24 | import org.xml.sax.EntityResolver;
|
---|
| 25 | import org.xml.sax.InputSource;
|
---|
| 26 | import org.xml.sax.SAXException;
|
---|
| 27 | @@ -190,10 +191,9 @@ URL registerImage(URI imageURI)
|
---|
| 28 |
|
---|
| 29 | if (content.startsWith("base64"))
|
---|
| 30 | {
|
---|
| 31 | - content = content.substring(6);
|
---|
| 32 | try
|
---|
| 33 | {
|
---|
| 34 | - byte[] buf = new sun.misc.BASE64Decoder().decodeBuffer(content);
|
---|
| 35 | + byte[] buf = DatatypeConverter.parseBase64Binary(content.substring(6));
|
---|
| 36 | ByteArrayInputStream bais = new ByteArrayInputStream(buf);
|
---|
| 37 | BufferedImage img = ImageIO.read(bais);
|
---|
| 38 |
|
---|
| 39 | @@ -213,7 +213,8 @@ URL registerImage(URI imageURI)
|
---|
| 40 | loadedImages.put(url, ref);
|
---|
| 41 |
|
---|
| 42 | return url;
|
---|
| 43 | - } catch (IOException ex)
|
---|
| 44 | + }
|
---|
| 45 | + catch (IOException | IllegalArgumentException ex)
|
---|
| 46 | {
|
---|
| 47 | Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
|
---|
| 48 | "Could not decode inline image", ex);
|
---|
| 49 | diff --git a/src/com/kitfox/svg/app/data/Handler.java b/src/com/kitfox/svg/app/data/Handler.java
|
---|
| 50 | index 806dcd9..e35c260 100644
|
---|
| 51 | --- a/src/com/kitfox/svg/app/data/Handler.java
|
---|
| 52 | +++ b/src/com/kitfox/svg/app/data/Handler.java
|
---|
| 53 | @@ -44,6 +44,8 @@
|
---|
| 54 | import java.util.logging.Level;
|
---|
| 55 | import java.util.logging.Logger;
|
---|
| 56 |
|
---|
| 57 | +import javax.xml.bind.DatatypeConverter;
|
---|
| 58 | +
|
---|
| 59 | /**
|
---|
| 60 | *
|
---|
| 61 | * @author kitfox
|
---|
| 62 | @@ -66,12 +68,11 @@ public Connection(URL url)
|
---|
| 63 |
|
---|
| 64 | if (content.startsWith("base64,"))
|
---|
| 65 | {
|
---|
| 66 | - content = content.substring(7);
|
---|
| 67 | try
|
---|
| 68 | {
|
---|
| 69 | - buf = new sun.misc.BASE64Decoder().decodeBuffer(content);
|
---|
| 70 | + buf = DatatypeConverter.parseBase64Binary(content.substring(7));
|
---|
| 71 | }
|
---|
| 72 | - catch (IOException e)
|
---|
| 73 | + catch (IllegalArgumentException e)
|
---|
| 74 | {
|
---|
| 75 | Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e);
|
---|
| 76 | }
|
---|
| 77 | diff --git a/src/oauth/signpost/signature/OAuthMessageSigner.java b/src/oauth/signpost/signature/OAuthMessageSigner.java
|
---|
| 78 | index 8d878ae..e24092d 100644
|
---|
| 79 | --- a/src/oauth/signpost/signature/OAuthMessageSigner.java
|
---|
| 80 | +++ b/src/oauth/signpost/signature/OAuthMessageSigner.java
|
---|
| 81 | @@ -16,26 +16,20 @@
|
---|
| 82 |
|
---|
| 83 | import java.io.IOException;
|
---|
| 84 | import java.io.Serializable;
|
---|
| 85 | +import javax.xml.bind.DatatypeConverter;
|
---|
| 86 |
|
---|
| 87 | import oauth.signpost.exception.OAuthMessageSignerException;
|
---|
| 88 | import oauth.signpost.http.HttpRequest;
|
---|
| 89 | import oauth.signpost.http.HttpParameters;
|
---|
| 90 |
|
---|
| 91 | -import org.apache.commons.codec.binary.Base64;
|
---|
| 92 | -
|
---|
| 93 | public abstract class OAuthMessageSigner implements Serializable {
|
---|
| 94 |
|
---|
| 95 | private static final long serialVersionUID = 4445779788786131202L;
|
---|
| 96 |
|
---|
| 97 | - private transient Base64 base64;
|
---|
| 98 | -
|
---|
| 99 | private String consumerSecret;
|
---|
| 100 |
|
---|
| 101 | private String tokenSecret;
|
---|
| 102 |
|
---|
| 103 | - public OAuthMessageSigner() {
|
---|
| 104 | - this.base64 = new Base64();
|
---|
| 105 | - }
|
---|
| 106 |
|
---|
| 107 | public abstract String sign(HttpRequest request, HttpParameters requestParameters)
|
---|
| 108 | throws OAuthMessageSignerException;
|
---|
| 109 | @@ -59,16 +53,15 @@ public void setTokenSecret(String tokenSecret) {
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | protected byte[] decodeBase64(String s) {
|
---|
| 113 | - return base64.decode(s.getBytes());
|
---|
| 114 | + return DatatypeConverter.parseBase64Binary(s);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | protected String base64Encode(byte[] b) {
|
---|
| 118 | - return new String(base64.encode(b));
|
---|
| 119 | + return DatatypeConverter.printBase64Binary(b);
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | private void readObject(java.io.ObjectInputStream stream)
|
---|
| 123 | throws IOException, ClassNotFoundException {
|
---|
| 124 | stream.defaultReadObject();
|
---|
| 125 | - this.base64 = new Base64();
|
---|
| 126 | }
|
---|
| 127 | }
|
---|