Example usage for java.lang StringBuilder length

List of usage examples for java.lang StringBuilder length

Introduction

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

Prototype

int length();

Source Link

Document

Returns the length of this character sequence.

Usage

From source file:cn.crawin.msg.gateway.http.SignUtil.java

/**
 * ??Path+Query+BODY//w ww . j  a v a  2  s . c om
 *
 * @param path
 * @param querys
 * @param bodys
 * @return ??
 */
private static String buildResource(String path, Map<String, String> querys, Map<String, String> bodys) {
    StringBuilder sb = new StringBuilder();

    if (!StringUtils.isBlank(path)) {
        sb.append(path);
    }
    Map<String, String> sortMap = new TreeMap<String, String>();
    if (null != querys) {
        for (Map.Entry<String, String> query : querys.entrySet()) {
            if (!StringUtils.isBlank(query.getKey())) {
                sortMap.put(query.getKey(), query.getValue());
            }
        }
    }

    if (null != bodys) {
        for (Map.Entry<String, String> body : bodys.entrySet()) {
            if (!StringUtils.isBlank(body.getKey())) {
                sortMap.put(body.getKey(), body.getValue());
            }
        }
    }

    StringBuilder sbParam = new StringBuilder();
    for (Map.Entry<String, String> item : sortMap.entrySet()) {
        if (!StringUtils.isBlank(item.getKey())) {
            if (0 < sbParam.length()) {
                sbParam.append(Constants.SPE3);
            }
            sbParam.append(item.getKey());
            if (!StringUtils.isBlank(item.getValue())) {
                sbParam.append(Constants.SPE4).append(item.getValue());
            }
        }
    }
    if (0 < sbParam.length()) {
        sb.append(Constants.SPE5);
        sb.append(sbParam);
    }

    return sb.toString();
}

From source file:com.twitter.ambrose.pig.AmbrosePigProgressNotificationListener.java

private static String toString(String[] array) {
    StringBuilder sb = new StringBuilder();
    for (String string : array) {
        if (sb.length() > 0) {
            sb.append(",");
        }/*from  w  w  w  .j  a v  a 2s  . co  m*/
        sb.append(string);
    }
    return sb.toString();
}

From source file:joshelser.LimitAndSumColumnFamilyIterator.java

public static void setColumns(IteratorSetting cfg, Collection<String> columns) {
    Preconditions.checkNotNull(columns);
    final StringBuilder sb = new StringBuilder(64);
    for (String column : columns) {
        if (0 != sb.length()) {
            sb.append(',');
        }// w  w w  .j a  va 2s.  co  m
        sb.append(column);
    }
    cfg.addOption(COLUMNS, sb.toString());
}

From source file:Main.java

/**
 * Read a file into a StringBuilder.//from w w w  .j  a v  a  2s  .  co  m
 * 
 * @param paramFile
 *            The file to read.
 * @param paramWhitespaces
 *            Retrieve file and don't remove any whitespaces.
 * @return StringBuilder instance, which has the string representation of
 *         the document.
 * @throws IOException
 *             throws an IOException if any I/O operation fails.
 */
public static StringBuilder readFile(final File paramFile, final boolean paramWhitespaces) throws IOException {
    final BufferedReader in = new BufferedReader(new FileReader(paramFile));
    final StringBuilder sBuilder = new StringBuilder();
    for (String line = in.readLine(); line != null; line = in.readLine()) {
        if (paramWhitespaces) {
            sBuilder.append(line + "\n");
        } else {
            sBuilder.append(line.trim());
        }
    }

    // Remove last newline.
    if (paramWhitespaces) {
        sBuilder.replace(sBuilder.length() - 1, sBuilder.length(), "");
    }
    in.close();

    return sBuilder;
}

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

public static CharSequence readFile(Activity activity, int id) {
    BufferedReader in = null;//w ww.ja va2  s.c  om
    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.gallatinsystems.survey.dao.SurveyUtils.java

/**
 * Given the path of an object, return a list of the paths of all its parent objects
 *
 * @param objectPath the path of an object
 * @param includeRootPath include the root path in the list of parent paths
 * @return/*from w  w  w.j  ava 2s.  c om*/
 */
public static List<String> listParentPaths(String objectPath, boolean includeRootPath) {
    List<String> parentPaths = new ArrayList<String>();
    StringBuilder path = new StringBuilder(objectPath);
    while (path.length() > 1) {
        path.delete(path.lastIndexOf("/"), path.length());
        if (StringUtils.isNotBlank(path.toString())) {
            parentPaths.add(path.toString().trim());
        }
    }

    if (includeRootPath) {
        parentPaths.add("/");
    }

    return parentPaths;
}

From source file:de.tudarmstadt.ukp.clarin.webanno.brat.curation.AgreementUtils.java

public static void dumpStudy(PrintStream aOut, ICodingAnnotationStudy aStudy) {
    try {// ww  w  .j  a v  a  2  s. co  m
        aOut.printf("Category count: %d%n", aStudy.getCategoryCount());
    } catch (Throwable e) {
        aOut.printf("Category count: %s%n", ExceptionUtils.getRootCauseMessage(e));
    }
    try {
        aOut.printf("Item count: %d%n", aStudy.getItemCount());
    } catch (Throwable e) {
        aOut.printf("Item count: %s%n", ExceptionUtils.getRootCauseMessage(e));
    }

    for (ICodingAnnotationItem item : aStudy.getItems()) {
        StringBuilder sb = new StringBuilder();
        for (IAnnotationUnit unit : item.getUnits()) {
            if (sb.length() > 0) {
                sb.append(" \t");
            }
            sb.append(unit.getCategory());
        }
        aOut.println(sb);
    }
}

From source file:jetbrains.exodus.util.ForkSupportIO.java

@NotNull
public static String join(@NotNull Collection<? extends String> strings, @NotNull final String separator) {
    final StringBuilder result = new StringBuilder();
    for (String string : strings) {
        if (string != null && !string.isEmpty()) {
            if (result.length() != 0)
                result.append(separator);
            result.append(string);// w w w. j  a va2 s.  co  m
        }
    }
    return result.toString();
}

From source file:Dump.java

/**
 *  Converte uma string contendo uma sequncia decimal codificada em BCD
 *  (<em>Binary-Coded Decimal</em> ?). Esta implementao foi obtida a partir da
 *  descrio da codificao BCD encontrada no manual de programao das 
 *  impressoras fiscais Bematech&reg; MP-20 FI II.
 *
 *  <p>Se os valores ASCII dos caracteres de uma string forem <code>0x12, 0x34 e
 *  0x56</code>, ento <code>bcd(s, 2)</code> resultar no valor decimal
 *  <code>1234.56</code>.</p>
 *
 *  @param s a string contendo a sequncia BCD.
 *
 *  @param scale o nmero de casas decimais a serem considerados. Se este
 *         argumento for menor ou igual a zero, ser considerado um valor
 *         inteiro./*from  w w  w.  j  a v a2  s  .  c  om*/
 *
 *  @return um objeto <code>java.math.BigDecimal</code> contendo o valor
 *          decimal decodificado.
 *
 *  @throws NumberFormatException se a string <code>s</code> no representar
 *          uma sequncia BCD vlida.
 */
public static BigDecimal bcd(final String s, final int scale) {

    StringBuilder hexval = new StringBuilder();

    // converte os valores ASCII da string para hexadecimal
    for (int i = 0; i < s.length(); i++) {
        StringBuilder hex = new StringBuilder(Integer.toString(ascval(s, i), 16));
        if (hex.length() != 2)
            hex.insert(0, "0");
        hexval.append(hex);
    }

    if (scale > 0) {
        if (scale > hexval.length()) {
            // completa com zeros antes da posio de insero do ponto decimal
            int count = scale - hexval.length();
            for (int i = 1; i <= count; i++)
                hexval.insert(0, "0");
        }
        // insere um ponto decimal na posio indicada
        hexval.insert(hexval.length() - scale, ".");
    }

    return new BigDecimal(hexval.toString());

}

From source file:net.joinedminds.masserr.Functions.java

public static String constructPath(String... items) {
    StringBuilder str = new StringBuilder();
    for (String it : items) {
        if (!isEmpty(it)) {
            if (str.length() > 0 && str.charAt(str.length() - 1) != '/') {
                str.append('/');
            }/*from  w ww  .ja  va2  s. c om*/
            str.append(it.trim());
        }
    }
    return str.toString();
}