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:jp.co.worksap.message.decoder.HeaderDecoder.java

private String createEncodingRegex() {
    StringBuilder builder = new StringBuilder();
    String[] charSets = Encoding.VALID_CHARSETS;
    builder.append("\\?==\\?(");
    for (int i = 0; i < charSets.length; i++) {
        builder.append("(").append(charSets[i]).append(")");
        builder.append("|");
    }/* w  w w . jav a2s .  co  m*/
    // delete the last "|"
    builder.deleteCharAt(builder.lastIndexOf("|"));
    builder.append(")\\?.?\\?");
    // finally, this regex may look like
    // "\\?==\\?((utf-8)|(iso-2022-jp)|(shift_jis))\\?.?\\?"
    return builder.toString();
}

From source file:edu.indiana.d2i.htrc.dataapi.DataAPIWrapper.java

private String makePagesURL(Map<String, List<String>> pageIDs) {
    StringBuilder builder = new StringBuilder();

    // it's ok the last one has the delimiter
    for (String volId : pageIDs.keySet()) {
        builder.append(volId + "[");

        for (String pageNum : pageIDs.get(volId))
            builder.append(pageNum + ",");

        // delete the last ','
        builder.deleteCharAt(builder.length() - 1);
        builder.append("]" + delimiter);
    }// w  ww . j  av a  2s  . c om

    if (isConcat)
        builder.append("&concat=true");

    return dataAPIEPR + dataAPIPagePrefix + builder.toString();
}

From source file:com.prasanna.android.stacknetwork.service.QuestionServiceHelper.java

private void getCommentsForAnswers(ArrayList<Answer> answers) {
    try {// w  ww  .  j a  va2 s .  c  o  m
        StringBuilder stringBuilder = new StringBuilder();
        HashMap<Long, Answer> idAnswerMap = new HashMap<Long, Answer>();

        for (Answer answer : answers) {
            stringBuilder.append(answer.id).append(";");
            idAnswerMap.put(answer.id, answer);
        }

        stringBuilder.deleteCharAt(stringBuilder.length() - 1);

        getCommensAndUpdateAnswer(stringBuilder.toString(), idAnswerMap);
    } catch (AbstractHttpException e) {
        LogWrapper.e(TAG, e.getMessage());
    }
}

From source file:jetbrains.exodus.sshd.RhinoCommand.java

private String readLine(API api) {
    StringBuilder s = new StringBuilder();

    try {//  w w w .  j  a v a2  s .co  m
        while (true) {
            char c = (char) in.read();

            if (c == -1 || c == 3)
                return null;
            if (c == '\n' || c == '\r') {
                api.newLine();
                break;
            }
            // delete
            if (c == 127 && s.length() > 0) {
                s.deleteCharAt(s.length() - 1);
                api.printChar('\b');
            }

            if (!isPrintableChar(c))
                continue;

            api.printChar(c);
            s.append(c);
        }
        return s.toString();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.taobao.adfs.util.Utilities.java

public static String runCommand(String command, Integer expectedExitCode, String extraPath, String libPath,
        boolean destory) throws IOException {
    BufferedReader stdOutputReader = null;
    StringBuilder output = new StringBuilder();
    Process process = runCommand(command, extraPath, libPath);
    ;//from  w  w  w  . j  a va  2s  . co  m
    try {
        stdOutputReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line;
        while ((line = stdOutputReader.readLine()) != null) {
            output.append(line).append('\n');
        }
        if (output.length() > 0)
            output.deleteCharAt(output.length() - 1);
        if (expectedExitCode != null && process.waitFor() != expectedExitCode)
            throw new IOException(
                    "exit code=" + process.exitValue() + ", expected exit code=" + expectedExitCode);
    } catch (Throwable t) {
        destory = true;
        throw new IOException("fail to exceute " + command + ", output=" + output
                + (extraPath == null ? "" : ", extraPath=" + extraPath)
                + (libPath == null ? "" : ", libPath=" + libPath), t);
    } finally {
        if (stdOutputReader != null)
            stdOutputReader.close();
        process.getOutputStream().close();
        process.getInputStream().close();
        process.getErrorStream().close();
        if (destory)
            process.destroy();
    }
    return output.toString();
}

From source file:com.yanzhenjie.nohttp.BasicRequest.java

/**
 * Split joint non form data.//from   w  w w  . ja  va 2 s . c om
 *
 * @param paramMap      param map.
 * @param encodeCharset charset.
 * @return string parameter combination, each key value on nails with {@code "&"} space.
 */
public static StringBuilder buildCommonParams(MultiValueMap<String, Object> paramMap, String encodeCharset) {
    StringBuilder paramBuilder = new StringBuilder();
    Set<String> keySet = paramMap.keySet();
    for (String key : keySet) {
        List<Object> values = paramMap.getValues(key);
        for (Object value : values) {
            if (value != null && value instanceof CharSequence) {
                paramBuilder.append("&").append(key).append("=");
                try {
                    paramBuilder.append(URLEncoder.encode(value.toString(), encodeCharset));
                } catch (UnsupportedEncodingException e) {
                    Logger.e("Encoding " + encodeCharset + " format is not supported by the system.");
                    paramBuilder.append(value.toString());
                }
            }
        }
    }
    if (paramBuilder.length() > 0)
        paramBuilder.deleteCharAt(0);
    return paramBuilder;
}

From source file:de.schildbach.game.GameRules.java

public final String formatGame(Game game, int fullMoveNumber, int firstPlayerIndex, Locale locale) {
    StringBuilder notation = new StringBuilder();
    FormatGameArrayElement[] notationArray = formatGameArray(game, fullMoveNumber, firstPlayerIndex, locale);

    for (int i = 0; i < notationArray.length; i++) {
        notation.append(notationArray[i].getNotation());
        notation.append(" ");
    }/*from   ww  w  .  j a  va  2 s.  c  om*/

    if (notation.length() > 0)
        notation.deleteCharAt(notation.length() - 1);

    return notation.toString();
}

From source file:baggage.hypertoolkit.html.UrlParamEncoder.java

public String asUrl(Bag<String, String> bag) {
    StringBuilder url = new StringBuilder();
    if (bag.isEmpty()) {
        return "";
    }/*  w  w  w .j  a v  a  2 s  . c om*/

    url.append("?");
    for (String key : bag.keySet()) {
        Collection<String> values = bag.getValues(key);
        for (String value : values) {
            try {
                url.append(URLEncoder.encode(StringUtils.stripToEmpty(key), "UTF-8"));
                url.append("=");
                url.append(URLEncoder.encode(StringUtils.stripToEmpty(value), "UTF-8"));
                url.append("&");
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
            }
        }
    }
    url.deleteCharAt(url.length() - 1);
    return url.toString();
}

From source file:io.mandrel.data.filters.link.SanitizeParamsFilter.java

public boolean isValid(Link link) {
    Uri linkUri = link.getUri();// www .j  a  v  a 2 s . c  o  m
    if (linkUri != null && StringUtils.isNotBlank(linkUri.toString())) {
        String uri = linkUri.toString();
        int pos = uri.indexOf('?');
        if (pos > -1) {
            String uriWithoutParams = uri.substring(0, pos);

            if (CollectionUtils.isNotEmpty(exclusions)) {
                String query = uri.substring(pos + 1, uri.length());

                if (StringUtils.isNotBlank(query)) {
                    String[] paramPairs = QUERY.split(query);

                    MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
                    if (paramPairs != null) {
                        for (String pair : paramPairs) {
                            String[] paramValue = PARAMS.split(pair);
                            if (exclusions.contains(paramValue[0])) {
                                params.add(paramValue[0], paramValue.length > 1 ? paramValue[1] : null);
                            }
                        }
                    }

                    StringBuilder builder = new StringBuilder();
                    params.entrySet().forEach(entry -> {
                        entry.getValue().forEach(value -> {
                            builder.append(entry.getKey());
                            if (StringUtils.isNotBlank(value)) {
                                builder.append("=").append(value);
                            }
                            builder.append("&");
                        });
                    });
                    if (builder.length() > 0 && builder.charAt(builder.length() - 1) == '&') {
                        builder.deleteCharAt(builder.length() - 1);
                    }
                    if (builder.length() > 0) {
                        link.setUri(Uri.create(uriWithoutParams + "?" + builder.toString()));
                    } else {
                        link.setUri(Uri.create(uriWithoutParams));
                    }
                } else {
                    link.setUri(Uri.create(uriWithoutParams));
                }
            } else {
                link.setUri(Uri.create(uriWithoutParams));
            }
        }
    }
    return true;
}

From source file:net.eusashead.hateoas.hal.response.impl.HalPageResponseBuilderImpl.java

/**
 * Build a query string from the supplied parameters
 * @param params/* www  . j a  va  2s  . c  o  m*/
 * @return
 */
private String buildQueryString(Map<String, String[]> params) {

    // Build the query string up from the parameters
    StringBuilder builder = new StringBuilder();
    for (String key : params.keySet()) {
        for (String val : params.get(key)) {
            builder.append(key);
            builder.append("=");
            builder.append(val);
            builder.append("&");
        }
    }

    // Remove the last ampersand if it is the trailing character
    if (builder.length() > 0) {
        if (builder.lastIndexOf("&") == (builder.length() - 1)) {
            builder.deleteCharAt(builder.length() - 1);
        }
    }
    return builder.toString();
}