Example usage for java.lang StringBuilder deleteCharAt

List of usage examples for java.lang StringBuilder deleteCharAt

Introduction

In this page you can find the example usage for java.lang StringBuilder deleteCharAt.

Prototype

@Override
public StringBuilder deleteCharAt(int index) 

Source Link

Usage

From source file:com.omertron.themoviedbapi.tools.WebBrowser.java

private static String createCookieHeader(URLConnection cnx) {
    String host = cnx.getURL().getHost();
    StringBuilder cookiesHeader = new StringBuilder();
    for (Map.Entry<String, Map<String, String>> domainCookies : COOKIES.entrySet()) {
        if (host.endsWith(domainCookies.getKey())) {
            for (Map.Entry<String, String> cookie : domainCookies.getValue().entrySet()) {
                cookiesHeader.append(cookie.getKey());
                cookiesHeader.append("=");
                cookiesHeader.append(cookie.getValue());
                cookiesHeader.append(";");
            }//from   ww w. j  a v  a  2 s. c  o m
        }
    }
    if (cookiesHeader.length() > 0) {
        // remove last ; char
        cookiesHeader.deleteCharAt(cookiesHeader.length() - 1);
    }
    return cookiesHeader.toString();
}

From source file:com.streamsets.pipeline.kafka.common.KafkaTestUtil.java

public static void startKafkaBrokers(int numberOfBrokers) {
    kafkaServers = new ArrayList<>(numberOfBrokers);
    kafkaProps = new HashMap<>();
    // setup Broker
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < numberOfBrokers; i++) {
        int port = TestUtils.choosePort();
        Properties props = TestUtils.createBrokerConfig(i, port);
        props.put("auto.create.topics.enable", "false");
        kafkaServers.add(TestUtils.createServer(new KafkaConfig(props), new MockTime()));
        sb.append("localhost:" + port).append(",");
    }/*from   w  w w .ja  va  2s  .c om*/
    metadataBrokerURI = sb.deleteCharAt(sb.length() - 1).toString();
    LOG.info("Setting metadataBrokerList and auto.offset.reset for test case");
    kafkaProps.put("auto.offset.reset", "smallest");
}

From source file:com.omertron.thetvdbapi.tools.WebBrowser.java

/**
 * Create the cookies for the header/*from  ww  w .j a  v  a2s . c o m*/
 *
 * @param cnx
 */
private static String createCookieHeader(URLConnection cnx) {
    String host = cnx.getURL().getHost();
    StringBuilder cookiesHeader = new StringBuilder();
    for (Map.Entry<String, Map<String, String>> domainCookies : cookies.entrySet()) {
        if (host.endsWith(domainCookies.getKey())) {
            for (Map.Entry<String, String> cookie : domainCookies.getValue().entrySet()) {
                cookiesHeader.append(cookie.getKey());
                cookiesHeader.append("=");
                cookiesHeader.append(cookie.getValue());
                cookiesHeader.append(";");
            }
        }
    }
    if (cookiesHeader.length() > 0) {
        // remove last ; char
        cookiesHeader.deleteCharAt(cookiesHeader.length() - 1);
    }
    return cookiesHeader.toString();
}

From source file:com.caocao.util.StringUtils.java

/**
 * Trim all occurences of the supplied leading character from the given String.
 * @param str the String to check/*  w w  w .jav  a  2  s .c  o m*/
 * @param leadingCharacter the leading character to be trimmed
 * @return the trimmed String
 */
public static String trimLeadingCharacter(String str, char leadingCharacter) {
    if (isEmpty(str)) {
        return str;
    }
    StringBuilder sb = new StringBuilder(str);
    while (sb.length() > 0 && sb.charAt(0) == leadingCharacter) {
        sb.deleteCharAt(0);
    }
    return sb.toString();
}

From source file:edu.yale.cs.hadoopdb.sms.SQLQueryGenerator.java

/**
 * Builds actual SQL query to execute against DBMS
 *//*from   ww w  . j  av a 2s .  c  o m*/
private static String buildSQLQuery(SQLQuery sqlStructure, String alias, Table tbl, StringBuilder sqlWhere,
        StringBuilder sqlGroupBy) {
    // final SQL query
    StringBuilder sqlSelect = new StringBuilder();
    StringBuilder sqlFrom = new StringBuilder();

    for (String name : sqlStructure.columnList) {
        String columnAlias = sqlStructure.columnAliasMap.get(name);
        sqlSelect.append(", ").append(name);
        if (columnAlias != null) {
            sqlSelect.append(" AS ").append(columnAlias);
        }
    }

    sqlSelect.deleteCharAt(0);

    sqlFrom.append(tbl.getName()).append(" AS ").append(alias);

    StringBuilder sqlQuery = new StringBuilder();
    sqlQuery.append("SELECT ").append(sqlSelect).append(" ");
    sqlQuery.append("FROM ").append(sqlFrom).append(" ");
    if (sqlWhere.length() > 0) {
        sqlQuery.append(" WHERE ").append(sqlWhere).append(" ");
    }
    if (sqlGroupBy.length() > 0) {
        sqlGroupBy.deleteCharAt(0);
        sqlQuery.append(" GROUP BY ").append(sqlGroupBy).append(" ");
    }

    sqlQuery.append(";");

    return sqlQuery.toString();
}

From source file:org.apache.taverna.databundle.DataBundles.java

public static ErrorDocument getError(Path path) throws IOException {
    if (path == null)
        return null;

    Path errorPath = withExtension(path, DOT_ERR);
    List<String> errorList = readAllLines(errorPath, UTF8);
    int split = errorList.indexOf("");
    if (split == -1 || errorList.size() <= split)
        throw new IOException("Invalid error document: " + errorPath);

    ErrorDocument errorDoc = new ErrorDocument();

    for (String cause : errorList.subList(0, split))
        errorDoc.getCausedBy().add(path.resolveSibling(cause));

    errorDoc.setMessage(errorList.get(split + 1));

    StringBuilder errorTrace = new StringBuilder();
    for (String line : errorList.subList(split + 2, errorList.size())) {
        errorTrace.append(line);//from   www . j a v a 2  s .  c om
        errorTrace.append("\n");
    }
    if (errorTrace.length() > 0)
        // Delete last \n
        errorTrace.deleteCharAt(errorTrace.length() - 1);
    errorDoc.setTrace(errorTrace.toString());
    return errorDoc;
}

From source file:Haze.CHazeManager.java

public static void loadHazeInfo() {

    String strOutput = "";

    try {/*from   w  w  w.ja v  a  2 s .c  o m*/
        strOutput = CNetworkFactory.createHazeRequest().sendRequest();
    } catch (IOException ex) {
    }

    if (strOutput.isEmpty()) {
        return;
    }

    JSONArray aryRegions = XML.toJSONObject(strOutput).getJSONObject("channel").getJSONObject("item")
            .getJSONArray("region");

    StringBuilder objSB = new StringBuilder();
    objSB.append("[");

    for (int i = 0; i < aryRegions.length(); i++) {

        objSB.append("{\"region\" : ");

        JSONObject objRegion = (JSONObject) aryRegions.get(i);

        objSB.append("\"");
        objSB.append(objRegion.getString("id"));
        objSB.append("\",");

        JSONArray aryReadings = objRegion.getJSONObject("record").getJSONArray("reading");

        for (int x = 0; x < aryReadings.length(); x++) {

            JSONObject objReading = (JSONObject) aryReadings.get(x);

            if (objReading.getString("type").equalsIgnoreCase("NPSI")) {

                objSB.append("\"psi\" : ");
                objSB.append(objReading.getInt("value"));
                objSB.append("},");
            }

        }
    }

    objSB.deleteCharAt(objSB.lastIndexOf(","));

    objSB.append("]");

    sendInfoToCPU(objSB.toString(), 33010);

}

From source file:com.magic.util.StringUtil.java

/** Make sure the string starts with a forward slash but does not end with one; converts back-slashes to forward-slashes; if in String is null or empty, returns zero length string. */
public static String cleanUpPathPrefix(String prefix) {
    if (prefix == null || prefix.length() == 0)
        return "";

    StringBuilder cppBuff = new StringBuilder(prefix.replace('\\', '/'));

    if (cppBuff.charAt(0) != '/') {
        cppBuff.insert(0, '/');
    }/*from   w ww .  j ava 2 s.c o m*/
    if (cppBuff.charAt(cppBuff.length() - 1) == '/') {
        cppBuff.deleteCharAt(cppBuff.length() - 1);
    }
    return cppBuff.toString();
}

From source file:com.proctorcam.proctorserv.HashedAuthenticator.java

public static HashMap<String, Object> applyReverseGuidAndSign(HashMap<String, Object> params,
        String customer_identifier, String shared_secret) {
    //Create random GUID
    SecureRandom secRandom = null;
    try {//from   w w w.j a v a  2  s .  com
        secRandom = SecureRandom.getInstance("SHA1PRNG");
    } catch (NoSuchAlgorithmException ex) {
        System.err.println(ex.getMessage());
    }
    String guid = new Integer(secRandom.nextInt()).toString();
    params.put("customer_id", customer_identifier);
    params.put("guid", guid);
    params.put("signature", "");

    //Create query string using key-value pairs in params and
    //appending shared_secret
    StringBuilder query = new StringBuilder();

    for (String key : params.keySet()) {
        if (key != "signature") {
            Object data = params.get(key);

            if (is_hashmap(data)) {
                HashMap<String, Object> map = (HashMap<String, Object>) data;
                String hashMapQuery = hashQuery(key, map);
                query.append(hashMapQuery);

            } else if (is_array(data)) {
                Object[] array = getArray(data);
                String arrayString = arrayQuery(key, array);
                query.append(arrayString);

            } else {
                query.append(key).append("=").append(data).append("&");
            }
        }
    }

    //Deletes trailing & from query and append shared_secret
    query.deleteCharAt(query.length() - 1);
    query.append(shared_secret);
    String signature = buildSig(query);

    //Add signature to params
    params.put("signature", signature);

    //Reverse guid in params
    String reverseGUID = new StringBuilder(guid).reverse().toString();
    params.put("guid", reverseGUID);

    return params;
}

From source file:com.flexive.shared.content.FxPermissionUtils.java

/**
 * Get a human readable form of bit coded permissions
 *
 * @param bitCodedPermissions permissions
 * @return human readable form// w ww .j av  a 2 s  .c  o  m
 */
public static String toString(byte bitCodedPermissions) {
    StringBuilder res = new StringBuilder(30);
    if ((bitCodedPermissions & PERM_MASK_TYPE) == PERM_MASK_TYPE)
        res.append(",Type");
    if ((bitCodedPermissions & PERM_MASK_STEP) == PERM_MASK_STEP)
        res.append(",Step");
    if ((bitCodedPermissions & PERM_MASK_PROPERTY) == PERM_MASK_PROPERTY)
        res.append(",Property");
    if ((bitCodedPermissions & PERM_MASK_INSTANCE) == PERM_MASK_INSTANCE)
        res.append(",Instance");
    if (res.length() > 0)
        res.deleteCharAt(0);
    return res.toString();
}