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 List<Node> getNodes(Node node, String path) {
    ArrayList nodeList = new ArrayList();

    ArrayList pathList = new ArrayList();
    String[] pathArray = path.split("/");
    for (int i = 0; i < pathArray.length; i++) {
        if (pathArray[i].equals(""))
            continue;
        pathList.add(pathArray[i]);/*from  w ww.  j a va 2s  . c  o m*/
    }

    for (int i = 0; i < pathList.size(); i++) {
        StringBuffer restPath = new StringBuffer();
        for (int k = i + 1; k < pathList.size(); k++) {
            restPath.append("/").append((String) pathList.get(k));
        }

        for (int j = 0; j < node.getChildNodes().getLength(); j++) {
            if (!node.getChildNodes().item(j).getNodeName().equals(pathList.get(i)))
                continue;
            if (restPath.length() == 0) {
                nodeList.add(node.getChildNodes().item(j));
            } else {
                nodeList.addAll(getNodes(node.getChildNodes().item(j), restPath.toString()));
            }
        }

    }

    return nodeList;
}

From source file:com.concursive.connect.web.portal.PortalURLParserImpl.java

private static void appendParameter(StringBuffer url, String parameter) {
    if (url.length() == 0 || !url.toString().contains("?")) {
        url.append("?");
    } else {/*from   w ww .  j av  a 2s.  com*/
        url.append("&");
    }
    LOG.debug("appendParameter: " + parameter);
    url.append(parameter);
}

From source file:Main.java

private static String removeUnecessaryIndent(String docs) {
    int count = 0;
    String[] lines = docs.split("\n");
    if (lines == null || lines.length == 0)
        return docs;
    String tmp = lines[0];//from ww w.  ja  v a  2  s  .  c  o  m
    if (tmp != null && tmp.length() > 0) {
        while (tmp.charAt(0) == ' ') {
            count++;
            if (tmp.length() == 1)
                break;
            tmp = tmp.substring(1);
        }
    }
    StringBuffer modified = new StringBuffer();
    for (int i = 0; i < lines.length; i++) {
        String line = lines[i];
        if (line.length() > count) {
            if (line.substring(0, count).trim().length() == 0) {
                line = line.substring(count);
            }
        }
        modified.append(line);
        modified.append("\n");
    }
    modified.deleteCharAt(modified.length() - 1); // remove last newline
    return modified.toString();
}

From source file:com.apkits.android.network.HttpConnection.java

/**
 * </br><b>title : </b>      ????GET??
 * </br><b>description :</b>????GET??
 * </br><b>time :</b>      2012-7-8 ?4:35:23
 * @param url            GETURL//  w  ww.j a  v a2  s .co  m
 * @param params         ????
 * @return               ???
 * @throws MalformedURLException
 * @throws IOException
 */
public static InputStream get(String url, Map<String, String> params)
        throws MalformedURLException, IOException {
    if (null != params) {
        StringBuffer sb = new StringBuffer();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            sb.append(entry.getKey()).append("=").append(entry.getValue());
            sb.append("&");
        }
        String param = sb.deleteCharAt(sb.length() - 1).toString();
        return connect("GET", new URL(url), param.getBytes());
    }
    return connect("GET", new URL(url), new byte[] {});
}

From source file:com.apkits.android.network.HttpConnection.java

/**
 * </br><b>title : </b>      ????POST??
 * </br><b>description :</b>????POST??
 * </br><b>time :</b>      2012-7-8 ?4:33:20
 * @param url            POSTURL//from w w  w  . j a  va 2s. c om
 * @param params         POST?
 * @param data            ????
 * @return               ???
 * @throws MalformedURLException
 * @throws IOException
 */
public static InputStream post(String url, Map<String, String> params, byte[] data)
        throws MalformedURLException, IOException {
    if (null != params) {
        StringBuffer sb = new StringBuffer();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            sb.append(entry.getKey()).append("=").append(entry.getValue());
            sb.append("&");
        }
        String param = sb.deleteCharAt(sb.length() - 1).toString();
        return connect("POST", new URL(url), param.getBytes(), data);
    } else {
        return connect("POST", new URL(url), null, data);
    }
}

From source file:Main.java

public static StringBuffer manualRTL(StringBuffer text, boolean forWebView) {

    if (forWebView) {
        if (patternBreakingWebView.matcher(text).find()) {
            // handle BiDi manually
            // global direction is LTR because of HTML markup
            StringBuffer ltr = new StringBuffer(""), rtl = new StringBuffer("");
            int i = 0;
            while (i < text.length()) {
                char c = text.charAt(i);
                if (isStrongLeftToRight(c) || !isStrongRightToLeft(c)) {
                    while (i < text.length() && !isStrongRightToLeft(text.charAt(i))) {
                        ltr.append(text.charAt(i));
                        i++;/*from ww  w . j  a  va2s .c  o m*/
                    }
                    if (i == text.length()) {
                        break;
                    }
                }
                if (isStrongRightToLeft(text.charAt(i))) {
                    while (i < text.length() && !isStrongLeftToRight(text.charAt(i))) {
                        // additional end condition: start of an HTML tag
                        if (text.charAt(i) == '<') {
                            break;
                        }
                        rtl.append(text.charAt(i));
                        i++;
                    }
                    // reverse only words that Android will not display correctly by itself
                    if (patternBreakingWebView.matcher(rtl).find()) {
                        ltr.append(rtl.reverse());
                    } else {
                        ltr.append(rtl);
                    }
                    rtl = new StringBuffer("");
                }
            }
            return ltr;
        }
    }
    return text;
}

From source file:FileUtil.java

/**
 *  Runs a simple command in given directory.
 *  The environment is inherited from the parent process (e.g. the
 *  one in which this Java VM runs)./* w  ww .j  a  va  2s.  c o  m*/
 *
 *  @return Standard output from the command.
 *  @param  command The command to run
 *  @param  directory The working directory to run the command in
 *  @throws IOException If the command failed
 *  @throws InterruptedException If the command was halted
 */
public static String runSimpleCommand(String command, String directory)
        throws IOException, InterruptedException {
    StringBuffer result = new StringBuffer();

    System.out.println("Running simple command " + command + " in " + directory);

    Process process = Runtime.getRuntime().exec(command, null, new File(directory));

    BufferedReader stdout = null;
    BufferedReader stderr = null;

    try {
        stdout = new BufferedReader(new InputStreamReader(process.getInputStream()));
        stderr = new BufferedReader(new InputStreamReader(process.getErrorStream()));

        String line;

        while ((line = stdout.readLine()) != null) {
            result.append(line + "\n");
        }

        StringBuffer error = new StringBuffer();
        while ((line = stderr.readLine()) != null) {
            error.append(line + "\n");
        }

        if (error.length() > 0) {
            System.out.println("Command failed, error stream is: " + error);
        }

        process.waitFor();

    } finally {
        // we must close all by exec(..) opened streams: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4784692
        process.getInputStream().close();
        if (stdout != null)
            stdout.close();
        if (stderr != null)
            stderr.close();
    }

    return result.toString();
}

From source file:com.iisigroup.cap.mvc.i18n.MessageBundleScriptCreator.java

/**
 *  filter ??//from w  w w .  ja  v  a 2 s  .  co m
 *
 * @param filterList
 *            filter list
 * @return String
 */
private static String generateFilterReg(Set<String> filterList) {
    if (filterList == null) {
        filterList = defaultFilter;
    }
    if (!filterList.isEmpty()) {
        StringBuffer regSb = new StringBuffer("^(");
        for (Iterator<String> it = filterList.iterator(); it.hasNext();) {
            regSb.append(it.next()).append(Constants.VALUES_SEPARATOR);
        }
        regSb.deleteCharAt(regSb.length() - 1).append(")");
        return regSb.toString();
    } else {
        return null;
    }

}

From source file:Utilities.java

/**
 * Converts the specified array into a string by appending all its elements
 * separated by a semicolon.//  ww w  . j ava 2s  .  c  o m
 */

public static String arrayToString(Object[] arr) {
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < arr.length; i++) {
        buf.append(arr[i]);
        buf.append("; ");
    }
    if (arr.length > 0)
        buf.setLength(buf.length() - 2); // get rid of the extra "; "

    return buf.toString();
}

From source file:org.ednovo.kafka.producer.KafkaEventHandler.java

private static String buildEndPoint(String ip, String portNo) {

    StringBuffer stringBuffer = new StringBuffer();
    String[] ips = ip.split(",");
    String[] ports = portNo.split(",");
    for (int count = 0; count < ips.length; count++) {

        if (stringBuffer.length() > 0) {
            stringBuffer.append(",");
        }//from   w w w  . ja v  a  2 s  .  co  m

        if (count < ports.length) {
            stringBuffer.append(ips[count] + ":" + ports[count]);
        } else {
            stringBuffer.append(ips[count] + ":" + ports[0]);
        }
    }
    return stringBuffer.toString();
}