All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jelastic.api.core.utils.CommandLineUtils Maven / Gradle / Ivy

The newest version!
/*Server class MD5: 1df0f2ba5819a73e1f46b4ff397ab09f*/
package com.jelastic.api.core.utils;

import org.json.JSONException;
import org.json.JSONObject;
import java.util.Base64;
import java.util.Iterator;

/**
 * @name Jelastic API Client
 * @version 8.11.2
 * @copyright Jelastic, Inc.
 */
public class CommandLineUtils {

    public static final String KEY_VALUE_SEPARATOR = "=";

    public static final String KEY_VALUE_PAIR_SEPARATOR = " ";

    public static String buildParam(JSONObject jsonObject, boolean encodeValueToBase64) {
        StringBuilder envArgsStringBuilder = new StringBuilder();
        Iterator iterator = jsonObject.keys();
        while (iterator.hasNext()) {
            String key = (String) iterator.next();
            String value;
            try {
                value = jsonObject.get(key) != null ? jsonObject.get(key).toString() : "";
            } catch (JSONException e) {
                e.printStackTrace();
                continue;
            }
            if (encodeValueToBase64) {
                value = new String(Base64.getEncoder().encode(value.getBytes()));
            }
            if (envArgsStringBuilder.length() != 0) {
                envArgsStringBuilder.append(KEY_VALUE_PAIR_SEPARATOR);
            }
            envArgsStringBuilder.append(key + KEY_VALUE_SEPARATOR + value);
        }
        return envArgsStringBuilder.toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy