Example usage for java.lang StringBuilder toString

List of usage examples for java.lang StringBuilder toString

Introduction

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

Prototype

@Override
    @HotSpotIntrinsicCandidate
    public String toString() 

Source Link

Usage

From source file:cn.ctyun.amazonaws.util.StringUtils.java

public static Integer toInteger(StringBuilder value) {
    return Integer.parseInt(value.toString());
}

From source file:co.runrightfast.metrics.MetricType.java

public static String metricName(@NonNull final MetricType metricType, final String... names) {
    notEmpty(names);//  w w w .  j  ava  2 s  .  c o m
    checkArgument(!Arrays.stream(names).filter(StringUtils::isBlank).findFirst().isPresent(),
            "any of the names cannot be blank");
    final StringBuilder sb = new StringBuilder(64);
    sb.append(metricType.name());
    Arrays.stream(names).forEach(n -> sb.append('.').append(n));
    return sb.toString();
}

From source file:com.googlecode.jmxtrans.model.ResultAttribute.java

/**
 * Get the {@link ResultAttribute} value from the attribute name
 * /*from w w w . j  a va  2 s  . c o m*/
 * @param attributeName
 *            <p>The attribute name for the {@link ResultAttribute} allowed values are:</p>
 *            <ul>
 *               <li>typeName</li>
 *              <li>objDomain</li>
 *              <li>className</li>
 *              <li>attributeName</li>
 *            </ul>
 * @return the {@link ResultAttribute}
 */
public static ResultAttribute fromAttribute(@Nonnull String attributeName) {
    String[] split = StringUtils.splitByCharacterTypeCamelCase(attributeName);
    StringBuilder sb = new StringBuilder(split[0].toUpperCase()).append("_").append(split[1].toUpperCase());
    return valueOf(sb.toString());
}

From source file:io.parallec.core.util.PcStringUtils.java

/**
 * Str map to str./*from  w  w w . j  a  v a 2s  .  co m*/
 *
 * @param map
 *            the map
 * @return the string
 */
public static String strMapToStr(Map<String, String> map) {

    StringBuilder sb = new StringBuilder();

    if (map == null || map.isEmpty())
        return sb.toString();

    for (Entry<String, String> entry : map.entrySet()) {

        sb.append("< " + entry.getKey() + ", " + entry.getValue() + "> ");
    }
    return sb.toString();

}

From source file:Main.java

/**
 * @param str the string to right-side pad
 * @param num the minimum number of characters to return
 * @return 'str' with enough right padding to make it num characters long.
 *//*ww w.  j  av  a2 s.  c o m*/
private static String padRight(String str, int num) {
    StringBuilder sb = new StringBuilder();
    sb.append(str);
    for (int count = str.length(); count < num; count++) {
        sb.append(" ");
    }

    return sb.toString();
}

From source file:Main.java

static String separator(final String pattern) {
    final StringBuilder dashedSeparator = new StringBuilder(72);
    for (int i = 0; i < 72 / pattern.length(); i++) {
        dashedSeparator.append(pattern);
    }//from w ww  .  ja v  a 2  s.c  o m
    return dashedSeparator.toString();
}

From source file:Main.java

public static String getSysDateTimeMillis() {
    String str = new Timestamp(System.currentTimeMillis()).toString();
    if (str.length() >= 23) {
        return str.substring(0, 23);
    } else {/* w  w w.ja  v  a2 s.c  om*/
        StringBuilder sb = new StringBuilder();
        sb.append(str);
        for (int i = 0; i < 23 - str.length(); i++) {
            sb.append("0");
        }
        return sb.toString();
    }
}

From source file:Main.java

public static String getStringFromUrl(List<NameValuePair> nameValuePairs)
        throws ClientProtocolException, IOException {
    String url = "http://www.fsurugby.org/serve/request.php";
    DefaultHttpClient client = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url);
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = client.execute(httppost);
    HttpEntity entity = response.getEntity();
    BufferedHttpEntity buffer = new BufferedHttpEntity(entity);
    InputStream is = buffer.getContent();
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();
    String line;//  w  w w .j  a v  a2  s.c o  m
    while ((line = reader.readLine()) != null) {
        sb.append(line);
    }

    return sb.toString();
}

From source file:Main.java

public static String pairsToString(List<NameValuePair> pairs) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < pairs.size(); i++) {
        sb.append(pairs.get(i).toString());
        sb.append("&");
    }/*from w  w  w.j a  va2 s.co  m*/
    return sb.toString();
}

From source file:Main.java

/**
 * Read a file and return as a String/*from   w  w w  . jav  a  2  s.  c  o  m*/
 *
 * @param file the file to read
 * @return the string representing the contents of the file
 * @throws IOException when reading the file fails
 * @since 0.11.0
 */
public static String readFile(File file) throws IOException {
    Reader reader = new FileReader(file);
    BufferedReader br = new BufferedReader(reader);
    try {
        StringBuilder sb = new StringBuilder();
        for (;;) {
            String line = br.readLine();
            if (line == null) {
                return sb.toString();
            } else {
                sb.append(line);
            }
            sb.append(System.getProperty("line.separator"));
        }
    } finally {
        br.close();
    }
}