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.smartitengineering.version.api.factory.VersionAPI.java

/**
 * Throw away all the '/' from beginning and end of the resourceId.
 * @param resourceId Id to trim/*w  w  w  .j a  v a2  s  .  c o  m*/
 * @return Trimmed version of the resourceId
 */
public static String trimToProperResourceId(String resourceId) {
    if (StringUtils.isBlank(resourceId)) {
        return "";
    }
    StringBuilder result = new StringBuilder(resourceId.trim());
    while (result.charAt(0) == '/') {
        result.deleteCharAt(0);
    }
    while (result.charAt(result.length() - 1) == '/') {
        result.deleteCharAt(result.length() - 1);
    }
    return result.toString();
}

From source file:com.smartqa.utils.WebDriverUtils.java

/**
 * analysis page performance by w3c web performance API<br/>
 * inject javascript to get the performance time
 * /*from  w  w  w . ja v  a 2s  . co  m*/
 * @param driver - web driver instance
 * @return map stored performance data
 */
public static Map<String, Long> analysis(WebDriver driver) {
    Map<String, Long> dataMap = buildMap();

    try {
        StringBuilder timeData = new StringBuilder()
                .append(((RemoteWebDriver) driver).executeScript(w3cPerfScript).toString());
        timeData.deleteCharAt(0);
        timeData.deleteCharAt(timeData.length() - 1);
        Map<String, String> timeMap = CommonUtils.buildMap(timeData.toString().split(","));

        dataMap.put(DNS_TIME, getTime(DNS_START, DNS_END, timeMap));
        dataMap.put(TCP_TIME, getTime(TCP_START, TCP_END, timeMap));
        dataMap.put(SERVER_TIME, getTime(SERVER_START, SERVER_END, timeMap));
        dataMap.put(PAGE_TIME, getTime(PAGE_START, PAGE_END, timeMap));
    } catch (Exception ex) {
        LOG.warn("failed to resolve performance data, caused by " + ex.getMessage());
    }

    return dataMap;
}

From source file:ch.digitalfondue.jfiveparse.TreeConstructionTest.java

static String renderNodes(List<Node> nodes) {
    StringBuilder sb = new StringBuilder();
    for (Node node : nodes) {
        renderNode(node, 0, sb);// w w  w  .  j a v a  2s.  co  m
    }
    return sb.deleteCharAt(sb.length() - 1).toString();
}

From source file:it.geosolutions.geostore.services.rest.auditing.AuditInfoExtractor.java

private static String groupsToString(Set<UserGroup> groups) {
    if (groups.isEmpty()) {
        return null;
    }/*from w w  w  .j  ava 2  s  . c o  m*/
    StringBuilder groupsString = new StringBuilder();
    for (UserGroup userGroup : groups) {
        groupsString.append(userGroup.getGroupName()).append(",");
    }
    groupsString.deleteCharAt(groupsString.length() - 1);
    return groupsString.toString();
}

From source file:Main.java

/**
 * Reads text from given {@link BufferedReader} line-by-line.
 *
 * @return text from given {@link BufferedReader}.
 * @throws IOException//from   www . j av  a2  s.c om
 */
@NonNull
public static String readTextFromBufferedReader(@NonNull BufferedReader bufferedReader) throws IOException {

    // Store all lines to string builder to
    // reduce memory using.
    final StringBuilder body = new StringBuilder();
    String nextLine;
    try {
        while ((nextLine = bufferedReader.readLine()) != null) {
            body.append(nextLine);
            body.append('\n');
        }
        int pos = body.length() - 1;
        if (pos >= 0) {
            body.deleteCharAt(pos);
        }
    } finally {
        bufferedReader.close();
    }

    return body.toString();
}

From source file:ch.digitalfondue.jfiveparse.TreeConstructionTest.java

static String renderDocument(Document document) {
    StringBuilder sb = new StringBuilder();

    for (Node node : document.getChildNodes()) {
        renderNode(node, 0, sb);//from  w  ww  . j a va 2  s  .c om
    }

    return sb.deleteCharAt(sb.length() - 1).toString();
}

From source file:com.sic.bb.jenkins.plugins.sicci_for_xcode.util.PluginUtils.java

public static Pattern createPattern(List<String> stringList) {
    StringBuilder regex = new StringBuilder();

    if (stringList != null) {
        regex.append('(');

        for (String item : stringList) {
            if (StringUtils.isBlank(item))
                continue;

            regex.append(stringToPattern(item));
            regex.append('|');
        }//w w w .  j  a va  2  s .c o m

        regex.deleteCharAt(regex.length() - 1);
        regex.append(')');
    }

    return Pattern.compile(regex.toString());
}

From source file:Main.java

public static String getRequestParamValue(Object obj, String charset) {
    if (obj == null) {
        return "";
    }/*from  w  w  w .j  av a2 s .c om*/
    String value;

    if (obj instanceof List) {
        StringBuilder sb = new StringBuilder();
        if (obj != null) {
            for (Object o : (List<?>) obj) {
                if (o != null) {
                    sb.append(o.toString());
                    sb.append(',');
                }
            }
        }
        if (sb.length() > 0) {
            sb.deleteCharAt(sb.length() - 1);
        }
        value = sb.toString();
    }

    else {
        value = obj.toString();
    }

    try {
        return URLEncoder.encode(value, charset);
    } catch (UnsupportedEncodingException e) {
        return value;
    }
}

From source file:com.example.youtubevideoupload.Util.java

public static CharSequence readFile(Activity activity, int id) {
    BufferedReader in = null;//w w  w.  j a va 2 s  .c o  m
    try {
        in = new BufferedReader(new InputStreamReader(activity.getResources().openRawResource(id)));
        String line;
        StringBuilder buffer = new StringBuilder();
        while ((line = in.readLine()) != null) {
            buffer.append(line).append('\n');
        }
        // Chop the last newline
        buffer.deleteCharAt(buffer.length() - 1);
        return buffer;
    } catch (IOException e) {
        return "";
    } finally {
        closeStream(in);
    }
}

From source file:com.arthackday.killerapp.util.Util.java

public static CharSequence readFile(YouTubeService youTubeService, int id) {
    BufferedReader in = null;/*from w ww .j  ava2s  .com*/
    try {
        in = new BufferedReader(new InputStreamReader(youTubeService.getResources().openRawResource(id)));
        String line;
        StringBuilder buffer = new StringBuilder();
        while ((line = in.readLine()) != null) {
            buffer.append(line).append('\n');
        }
        // Chomp the last newline
        buffer.deleteCharAt(buffer.length() - 1);
        return buffer;
    } catch (IOException e) {
        return "";
    } finally {
        closeStream(in);
    }
}