Example usage for java.util Base64 getMimeEncoder

List of usage examples for java.util Base64 getMimeEncoder

Introduction

In this page you can find the example usage for java.util Base64 getMimeEncoder.

Prototype

public static Encoder getMimeEncoder() 

Source Link

Document

Returns a Encoder that encodes using the MIME type base64 encoding scheme.

Usage

From source file:ai.grakn.engine.tasks.TaskStateSerializer.java

public static String serializeToString(TaskState data) {
    return Base64.getMimeEncoder().encodeToString(SerializationUtils.serialize(data));
}

From source file:com.github.pemapmodder.pocketminegui.gui.startup.installer.cards.ServerSetupCard.java

private static void initServerPropertiesMap() {
    SERVER_PROPERTIES_MAP.put("motd", "Minecraft: PE Server");
    SERVER_PROPERTIES_MAP.put("server-port", 19132);
    SERVER_PROPERTIES_MAP.put("white-list", false);
    SERVER_PROPERTIES_MAP.put("announce-player-achievements", true);
    SERVER_PROPERTIES_MAP.put("spawn-protection", 16);
    SERVER_PROPERTIES_MAP.put("max-players", 20);
    SERVER_PROPERTIES_MAP.put("allow-flight", false);
    SERVER_PROPERTIES_MAP.put("spawn-animals", true);
    SERVER_PROPERTIES_MAP.put("spawn-mobs", true);
    SERVER_PROPERTIES_MAP.put("gamemode", 0);
    SERVER_PROPERTIES_MAP.put("force-gamemode", false);
    SERVER_PROPERTIES_MAP.put("hardcore", false);
    SERVER_PROPERTIES_MAP.put("pvp", true);
    SERVER_PROPERTIES_MAP.put("difficulty", 1);
    SERVER_PROPERTIES_MAP.put("generator-settings", "");
    SERVER_PROPERTIES_MAP.put("level-name", "world");
    SERVER_PROPERTIES_MAP.put("level-seed", "");
    SERVER_PROPERTIES_MAP.put("level-type", "DEFAULT");
    SERVER_PROPERTIES_MAP.put("enable-query", true);
    SERVER_PROPERTIES_MAP.put("enable-rcon", true);
    SERVER_PROPERTIES_MAP.put("rcon.password",
            new String(Base64.getMimeEncoder().encode(RandomUtils.nextBytes(20))).substring(3, 13));
    SERVER_PROPERTIES_MAP.put("auto-save", true);
}

From source file:org.codice.ddf.security.idp.client.LogoutRequestService.java

private String decodeBase64(String encoded) {
    return Base64.getMimeEncoder().encodeToString(encoded.getBytes(StandardCharsets.UTF_8));
}

From source file:org.omegat.util.WikiGet.java

private static void addProxyAuthentication(HttpURLConnection conn) {
    // Added to pass through authenticated proxy
    String encodedUser = Preferences.getPreference(Preferences.PROXY_USER_NAME);
    if (!StringUtil.isEmpty(encodedUser)) { // There is a proxy user
        String encodedPassword = Preferences.getPreference(Preferences.PROXY_PASSWORD);
        try {/*from   w  w  w  .j a  v a  2 s . co m*/
            String userPass = StringUtil.decodeBase64(encodedUser, StandardCharsets.ISO_8859_1) + ":"
                    + StringUtil.decodeBase64(encodedPassword, StandardCharsets.ISO_8859_1);
            String encodedUserPass = Base64.getMimeEncoder()
                    .encodeToString(userPass.getBytes(StandardCharsets.ISO_8859_1));
            conn.setRequestProperty("Proxy-Authorization", "Basic " + encodedUserPass);
        } catch (IllegalArgumentException ex) {
            Log.logErrorRB("LOG_DECODING_ERROR");
            Log.log(ex);
        }
    }
}

From source file:org.openhab.binding.km200.internal.KM200Cryption.java

/**
 * This function does the encoding for a new message to the device
 *
 *//*from w  w w . ja  v  a 2s .  c  om*/
public byte[] encodeMessage(String data) {
    try {
        // --- create cipher
        byte[] bdata = data.getBytes(remoteDevice.getCharSet());
        final Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
        cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(remoteDevice.getCryptKeyPriv(), "AES"));
        int bsize = cipher.getBlockSize();
        logger.debug("Add Padding, encrypt AES and B64..");
        byte[] encryptedData = cipher.doFinal(addZeroPadding(bdata, bsize, remoteDevice.getCharSet()));
        try {
            return (Base64.getMimeEncoder().encode(encryptedData));
        } catch (IllegalArgumentException e) {
            logger.info("Base64encoding not possible: {}", e.getMessage());
        }
    } catch (UnsupportedEncodingException | GeneralSecurityException e) {
        logger.error("Exception on encoding: {}", e);
    }
    return null;
}

From source file:utybo.branchingstorytree.swing.impl.HTBClient.java

@Override
public String getAsBase64(String resource) {
    return Base64.getMimeEncoder().encodeToString(map.get(resource));
}

From source file:utybo.branchingstorytree.swing.impl.IMGClient.java

@Override
public void load(final InputStream in, final String name) throws BSTException {
    try {/*from  w  w  w  .  j av  a  2  s  . c o  m*/
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        IOUtils.copy(in, baos);
        images.put(name, ImageIO.read(new ByteArrayInputStream(baos.toByteArray())));
        b64images.put(name,
                Base64.getMimeEncoder().encodeToString(baos.toByteArray()).replaceAll("[\n\r]", ""));
    } catch (final IOException e) {
        throw new BSTException(-1, "Could not load image", e, "<none>");
    }
}

From source file:utybo.branchingstorytree.swing.impl.IMGClient.java

@Experimental
public static void initInternal() {
    if (!internalb64images.isEmpty())
        return;/*w w  w  . j  ava2s .co m*/

    OpenBST.LOG.info("Creating internal images cache, this could take some time...");
    List<BufferedImage> bgs = Icons.getAllBackgrounds();
    for (int i = 0; i < bgs.size(); i++) {
        BufferedImage img = bgs.get(i);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            ImageIO.write(img, "JPG", baos);
        } catch (IOException e) {
            OpenBST.LOG.warn("Failed to create Base64 background", e);
        }
        internalb64images.put(i,
                Base64.getMimeEncoder().encodeToString(baos.toByteArray()).replaceAll("[\n\r]", ""));
    }
}