source: josm/trunk/patches/base64.patch@ 11711

Last change on this file since 11711 was 8149, checked in by stoecker, 10 years ago

fix #11257 - Remove apache.commons.codecs - patch by Florian Schaefer

File size: 4.8 KB
  • src/com/kitfox/svg/SVGUniverse.java

    From f44a63833a45ee8f67589334f56549a5d7b72fa4 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Florian=20Sch=C3=A4fer?= <florian@schaeferban.de>
    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 b  
    6161import java.util.logging.Logger;
    6262import java.util.zip.GZIPInputStream;
    6363import javax.imageio.ImageIO;
     64import javax.xml.bind.DatatypeConverter;
    6465import org.xml.sax.EntityResolver;
    6566import org.xml.sax.InputSource;
    6667import org.xml.sax.SAXException;
    URL registerImage(URI imageURI)  
    190191
    191192            if (content.startsWith("base64"))
    192193            {
    193                 content = content.substring(6);
    194194                try
    195195                {
    196                     byte[] buf = new sun.misc.BASE64Decoder().decodeBuffer(content);
     196                    byte[] buf = DatatypeConverter.parseBase64Binary(content.substring(6));
    197197                    ByteArrayInputStream bais = new ByteArrayInputStream(buf);
    198198                    BufferedImage img = ImageIO.read(bais);
    199199
    URL registerImage(URI imageURI)  
    213213                    loadedImages.put(url, ref);
    214214
    215215                    return url;
    216                 } catch (IOException ex)
     216                }
     217                catch (IOException | IllegalArgumentException ex)
    217218                {
    218219                    Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
    219220                        "Could not decode inline image", ex);
  • src/com/kitfox/svg/app/data/Handler.java

    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 b  
    4444import java.util.logging.Level;
    4545import java.util.logging.Logger;
    4646
     47import javax.xml.bind.DatatypeConverter;
     48
    4749/**
    4850 *
    4951 * @author kitfox
    public Connection(URL url)  
    6668
    6769            if (content.startsWith("base64,"))
    6870            {
    69                 content = content.substring(7);
    7071                try
    7172                {
    72                     buf = new sun.misc.BASE64Decoder().decodeBuffer(content);
     73                    buf = DatatypeConverter.parseBase64Binary(content.substring(7));
    7374                }
    74                 catch (IOException e)
     75                catch (IllegalArgumentException e)
    7576                {
    7677                    Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e);
    7778                }
  • src/oauth/signpost/signature/OAuthMessageSigner.java

    diff --git a/src/oauth/signpost/signature/OAuthMessageSigner.java b/src/oauth/signpost/signature/OAuthMessageSigner.java
    index 8d878ae..e24092d 100644
    a b  
    1616
    1717import java.io.IOException;
    1818import java.io.Serializable;
     19import javax.xml.bind.DatatypeConverter;
    1920
    2021import oauth.signpost.exception.OAuthMessageSignerException;
    2122import oauth.signpost.http.HttpRequest;
    2223import oauth.signpost.http.HttpParameters;
    2324
    24 import org.apache.commons.codec.binary.Base64;
    25 
    2625public abstract class OAuthMessageSigner implements Serializable {
    2726
    2827    private static final long serialVersionUID = 4445779788786131202L;
    2928
    30     private transient Base64 base64;
    31 
    3229    private String consumerSecret;
    3330
    3431    private String tokenSecret;
    3532
    36     public OAuthMessageSigner() {
    37         this.base64 = new Base64();
    38     }
    3933
    4034    public abstract String sign(HttpRequest request, HttpParameters requestParameters)
    4135            throws OAuthMessageSignerException;
    public void setTokenSecret(String tokenSecret) {  
    5953    }
    6054
    6155    protected byte[] decodeBase64(String s) {
    62         return base64.decode(s.getBytes());
     56        return DatatypeConverter.parseBase64Binary(s);
    6357    }
    6458
    6559    protected String base64Encode(byte[] b) {
    66         return new String(base64.encode(b));
     60        return DatatypeConverter.printBase64Binary(b);
    6761    }
    6862
    6963    private void readObject(java.io.ObjectInputStream stream)
    7064            throws IOException, ClassNotFoundException {
    7165        stream.defaultReadObject();
    72         this.base64 = new Base64();
    7366    }
    7467}
Note: See TracBrowser for help on using the repository browser.