Java XML Base64 Encode Decode decodeBase64(String b64data)

Here you can find the source of decodeBase64(String b64data)

Description

Convert a Base64-encoded String into an array of bytes.

License

Open Source License

Parameter

Parameter Description
b64data Base64-encoded String

Return

Data bytes

Declaration

private static byte[] decodeBase64(String b64data) 

Method Source Code

//package com.java2s;
/**************************************************************************
 OmegaT - Computer Assisted Translation (CAT) tool 
  with fuzzy matching, translation memory, keyword search, 
  glossaries, and translation leveraging into updated projects.
    /*from w  w  w  . j  a va  2  s . com*/
 Copyright (C) 2000-2006 Keith Godfrey and Maxym Mykhalchuk
       2007 Didier Briel and Tiago Saboga
       2007 Zoltan Bartko - bartkozoltan@bartkozoltan.com
       2008 Andrzej Sawula
       2010-2013 Alex Buloichik
       2015 Zoltan Bartko, Aaron Madlon-Kay
       2016 Aaron Madlon-Kay
       Home page: http://www.omegat.org/
       Support center: http://groups.yahoo.com/group/OmegaT/
    
 This file is part of OmegaT.
    
 OmegaT is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
    
 OmegaT is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
    
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 **************************************************************************/

import java.nio.charset.Charset;

import javax.xml.bind.DatatypeConverter;

public class Main {
    /**
     * Convert a Base64-encoded String into an array of bytes. Convenience
     * method for {@link DatatypeConverter#parseBase64Binary(String)} (available
     * since Java 1.6) because it's so well hidden.
     * 
     * @param b64data
     *            Base64-encoded String
     * @return Data bytes
     */
    private static byte[] decodeBase64(String b64data) {
        return DatatypeConverter.parseBase64Binary(b64data);
    }

    /**
     * Decode the Base64-encoded <code>charset</code> bytes back to a String.
     * 
     * @param b64data
     *            Base64-encoded String
     * @param charset
     *            charset of decoded bytes
     * @return String
     */
    public static String decodeBase64(String b64data, Charset charset) {
        return new String(decodeBase64(b64data), charset);
    }
}

Related

  1. byteToBase64(byte[] data)
  2. compressToBase64(byte[] message)
  3. createBase64EncodedStringFromURL(URL url)
  4. decode(String base64)
  5. decodeBase64(File file)
  6. decodeBase64(String base64)
  7. decodeBase64(String s)
  8. decodeBase64(String value)
  9. decompressFromBase64(String message)