Example usage for java.lang StringBuffer length

List of usage examples for java.lang StringBuffer length

Introduction

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

Prototype

@Override
    public synchronized int length() 

Source Link

Usage

From source file:Main.java

public static String convertListToURLParamsString(List<?> values) {
    StringBuffer buff = new StringBuffer();
    for (Object object : values) {
        buff.append(object.toString() + "&");
    }/*from ww w .  ja va 2s.  c  om*/
    buff.replace(buff.length() - 1, buff.length(), "");
    return buff.toString();
}

From source file:Main.java

public static String getSeparatedValuesFromArray(String[] separatedValuesArray) {
    if (separatedValuesArray == null || separatedValuesArray.length == 0) {
        return null;
    }//w  w  w. j ava 2  s.c om

    StringBuffer separatedValuesStringBuffer = new StringBuffer();

    for (String value : separatedValuesArray) {
        if (separatedValuesStringBuffer.length() > 0) {
            separatedValuesStringBuffer.append(";" + value);
        } else {
            separatedValuesStringBuffer.append(value);
        }
    }

    return separatedValuesStringBuffer.toString();
}

From source file:edu.buffalo.fusim.ExtractSeq.java

public static StringBuffer reverseComplement(StringBuffer seq) {
    StringBuffer revc = new StringBuffer();

    seq.reverse();/*from www.  j a  v  a2s  .  co  m*/
    for (int i = 0; i < seq.length(); i++) {
        revc.append(symbolMap.get(seq.charAt(i)));
    }

    return revc;
}

From source file:Main.java

public static String join(final int[] follows) {
    final StringBuffer buf = new StringBuffer(11 * follows.length);
    for (final int follow : follows) {
        if (0 != buf.length()) {
            buf.append(",");
        }//from   www  . j  a v  a  2s  .  c o  m
        buf.append(follow);
    }
    return buf.toString();
}

From source file:Main.java

/**
 * Handles XML encoding of text, e.g. & to &amp;
 * /*from   w w  w . j a v a  2s .  c om*/
 * @param sText Text to XML encode
 * @return XML Encoded text
 */
public static String encodeXMLText(String sText) {
    StringBuffer sBuff2 = new StringBuffer(sText);
    StringBuffer sNewBuff = new StringBuffer();

    for (int i = 0; i < sBuff2.length(); i++) {
        char currChar = sBuff2.charAt(i);
        Character currCharObj = new Character(sBuff2.charAt(i));
        if (currChar == '&') {
            if ((sBuff2.length() - 1 - i) >= 4 && sBuff2.charAt(i + 1) == 'a' && sBuff2.charAt(i + 2) == 'm'
                    && sBuff2.charAt(i + 3) == 'p' && sBuff2.charAt(i + 4) == ';') {
                i = i + 4;
                sNewBuff.append("&amp;");
            } else {
                sNewBuff.append("&amp;");
            }
        } else if (currChar == '>') {
            sNewBuff.append("&gt;");
        } else if (currChar == '<') {
            sNewBuff.append("&lt;");
        } else {
            sNewBuff.append(currChar);
        }
    }

    return sNewBuff.toString();

}

From source file:Main.java

public static String numberCheck(String num) {
    if (num == null || num.length() == 0) {
        return "";
    }//  w ww.  j a v  a2s  . c om
    Pattern pattern = Pattern.compile("(?<!\\d)(?:(?:1[34578]\\d{9})|(?:861[34578]\\d{9}))(?!\\d)");
    Matcher matcher = pattern.matcher(num);
    StringBuffer bf = new StringBuffer(64);
    while (matcher.find()) {
        bf.append(matcher.group()).append(",");
    }
    int len = bf.length();
    if (len > 0) {
        bf.deleteCharAt(len - 1);
    }
    return bf.toString();
}

From source file:Main.java

/** 
 * Erases the mIRC colorcodes from a String. 
 * The documentation of the evil color codes is available on 
 * <a href="http://www.mirc.co.uk/help/color.txt" 
 * target="_blank">http://www.mirc.co.uk/help/color.txt</a>. 
 * @param buf The line which should be parsed. 
 * @return A line as <code>StringBuffer</code> object which is cleaned from 
 *         any mIRC colorcodes.// www.j  a  va  2  s.c om
 * @see #parseColors(String)
 */
public static StringBuffer parseColors(StringBuffer buf) {
    int len = buf.length();

    for (int i = 0, j = 0, c; i < len; i++, j = i) {
        c = buf.charAt(i);
        try {
            // COLORS Beginning 
            // (format: <colorIndicator><int>[<int>][[,<int>[<int>]]
            if (c == colorIndicator) {
                c = buf.charAt(++j);
                if ('0' <= c && c <= '9') { // first int
                    c = buf.charAt(++j);
                    if ('0' <= c && c <= '9')
                        c = buf.charAt(++j); // second int
                }
                if (c == ',')
                    c = buf.charAt(++j); // comma 
                if ('0' <= c && c <= '9') { // first int
                    c = buf.charAt(++j);
                    if ('0' <= c && c <= '9')
                        c = buf.charAt(++j); // second int
                }
                // ACTION / BOLD / UNDERLINE / COLOR END 
                // (format: <actionIndicator> / <boldIndicator> etc.)
            } else if (c == actionIndicator || c == boldIndicator || c == underlinedIndicator
                    || c == colorEndIndicator || c == colorReverseIndicator) {
                j++;
            }
        } catch (StringIndexOutOfBoundsException exc) {
            // we got the end of the string with a call to charAt(++iIndexEnd)
            // nothing
        }

        if (j > i) {
            buf = buf.delete(i, j); // remove the cars
            len -= (j - i);
            i -= (j - i);
        }
    }
    return buf;
}

From source file:Main.java

public static String getByteArray(byte[] data) {
    final StringBuffer sb = new StringBuffer();
    for (int i = 0; i < data.length; i++) {
        sb.append(data[i] + ",");
    }/*from  www.  j  a v a2 s .  c  om*/

    return sb.toString().substring(0, sb.length() - 1);
}

From source file:Main.java

public static String[] stringtoArray(String s) {
    s = s.substring(1, s.length() - 1);/*www  .j ava  2s .co m*/
    // convert a String s to an Array, the elements
    // are delimited by sep
    // NOTE : for old JDK only (<1.4).
    //        for JDK 1.4 +, use String.split() instead
    StringBuffer buf = new StringBuffer(s);
    String sep = ",";
    int arraysize = 1;
    for (int i = 0; i < buf.length(); i++) {
        if (sep.indexOf(buf.charAt(i)) != -1)
            arraysize++;
    }
    String[] elements = new String[arraysize];
    int y, z = 0;
    if (buf.toString().indexOf(sep) != -1) {
        while (buf.length() > 0) {
            if (buf.toString().indexOf(sep) != -1) {
                y = buf.toString().indexOf(sep);
                if (y != buf.toString().lastIndexOf(sep)) {
                    elements[z] = buf.toString().substring(0, y);
                    z++;
                    buf.delete(0, y + 1);
                } else if (buf.toString().lastIndexOf(sep) == y) {
                    elements[z] = buf.toString().substring(0, buf.toString().indexOf(sep));
                    z++;
                    buf.delete(0, buf.toString().indexOf(sep) + 1);
                    elements[z] = buf.toString();
                    z++;
                    buf.delete(0, buf.length());
                }
            }
        }
    } else {
        elements[0] = buf.toString();
    }
    buf = null;
    return elements;
}

From source file:Main.java

public static String getStackTrace(StackTraceElement[] se, int skip) {
    if (se == null || se.length <= skip)
        return "";
    String CRLF = System.getProperty("line.separator");
    StringBuffer sb = new StringBuffer();
    for (int i = skip; i < se.length; i++) {
        if (sb.length() > 0) {
            sb.append(CRLF);//from   w w  w.jav  a2  s.c om
        }
        sb.append(se[i]);
    }
    return sb.toString();
}