Java Base64 base64(String string)

Here you can find the source of base64(String string)

Description

base

License

Open Source License

Declaration

static String base64(String string) 

Method Source Code


//package com.java2s;
/*/*from   w w w . ja  v  a 2  s. com*/
 *  Copyright (c) 2011-2015 The original author or authors
 *
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  and Apache License v2.0 which accompanies this distribution.
 *
 *       The Eclipse Public License is available at
 *       http://www.eclipse.org/legal/epl-v10.html
 *
 *       The Apache License v2.0 is available at
 *       http://www.opensource.org/licenses/apache2.0.php
 *
 *  You may elect to redistribute this code under either of these licenses.
 */

import java.io.UnsupportedEncodingException;

import java.util.Base64;

public class Main {
    static String base64(String string) {
        try {
            return Base64.getMimeEncoder().encodeToString(string.getBytes("ISO-8859-1"));
        } catch (UnsupportedEncodingException e) {
            // doesn't happen
            return "";
        }
    }

    public static String base64(byte[] bytes) {
        return Base64.getMimeEncoder().encodeToString(bytes);
    }
}

Related

  1. base64(byte[] buff)
  2. base64(byte[] data)
  3. base64(byte[] raw)
  4. base64(final byte[] stringArray)
  5. Base64(String msg)
  6. base64(String value)
  7. base64Append(StringBuilder sb, int digit, boolean haveNonZero)
  8. base64Append(StringBuilder sb, int digit, boolean haveNonZero)
  9. base64Character(int number)