Example usage for java.lang StringBuffer toString

List of usage examples for java.lang StringBuffer toString

Introduction

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

Prototype

@Override
    @HotSpotIntrinsicCandidate
    public synchronized String toString() 

Source Link

Usage

From source file:Main.java

public static String getNodePath(Node node) {
    StringBuffer sb = new StringBuffer(32);
    while (node != null) {
        sb.append(node.getNodeName());/*  ww  w . j a v a  2s  .  c om*/
        sb.append("/");
        node = node.getParentNode();
    }
    return sb.toString();
}

From source file:Main.java

public static String checkMobileNum(String phoneNum) {
    if (TextUtils.isEmpty(phoneNum))
        return "";

    Pattern p1 = Pattern.compile("^((\\+{0,1}86){0,1})1[0-9]{10}");
    Matcher m1 = p1.matcher(phoneNum);
    if (m1.matches()) {
        Pattern p2 = Pattern.compile("^((\\+{0,1}86){0,1})");
        Matcher m2 = p2.matcher(phoneNum);
        StringBuffer sb = new StringBuffer();
        while (m2.find()) {
            m2.appendReplacement(sb, "");
        }//from w ww.  j  ava2s  . c  o  m
        m2.appendTail(sb);
        return sb.toString();
    } else {
        return phoneNum;
    }
}

From source file:Main.java

public static String toString(InputStream in) throws IOException {
    StringBuffer out = new StringBuffer();
    byte[] buffer = new byte[1024];
    for (int i; (i = in.read(buffer)) != -1;) {
        out.append(new String(buffer, 0, i));
    }//from   w  ww. j  av  a  2s .c  o m
    return out.toString();
}

From source file:Main.java

public static String read(File file) {
    if (!file.exists()) {
        return "";
    }/*from   w ww. ja  va  2s  . c o  m*/
    try {
        FileReader reader = new FileReader(file);
        BufferedReader br = new BufferedReader(reader);
        StringBuffer buffer = new StringBuffer();
        String s;
        while ((s = br.readLine()) != null) {
            buffer.append(s);
        }
        return buffer.toString();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static String md5(String str) throws Exception {
    MessageDigest md = MessageDigest.getInstance("MD5");
    md.update(str.getBytes());//from w w w.j  a v  a  2s.  c  o  m

    byte byteData[] = md.digest();

    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < byteData.length; i++) {
        sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
    }

    return sb.toString();
}

From source file:MainClass.java

public static String toString(byte[] a) {
    StringBuffer result = new StringBuffer("[");
    for (int i = 0; i < a.length; i++) {
        result.append(a[i]);/*  w w w . ja v a2  s  .c  o m*/
        if (i < a.length - 1)
            result.append(", ");
    }
    result.append("]");
    return result.toString();
}

From source file:edu.duke.cabig.c3pr.rules.deploy.SystemRulesDeployer.java

public static String getFileContext(InputStream in) throws Exception {
    BufferedReader ds = new BufferedReader(new InputStreamReader(in));
    String line = null;//from ww w  .j  a va  2 s .  co m
    StringBuffer xml = new StringBuffer();
    while ((line = ds.readLine()) != null) {
        xml.append(line);
    }
    return xml.toString();
}

From source file:Main.java

public static String convertListToURLParamsString(List<?> values) {
    StringBuffer buff = new StringBuffer();
    for (Object object : values) {
        buff.append(object.toString() + "&");
    }//from   www  . jav a2 s . c  o m
    buff.replace(buff.length() - 1, buff.length(), "");
    return buff.toString();
}

From source file:Main.java

/**
 * CDATA sections can not have a "]]>" in them. This method takes the input and wraps it up in one or more CDATA sections, converting any "]]>" strings into
 * "]]&gt;".//from  ww  w.  java 2 s.c om
 */
public static String wrapStringInCDATA(final String input) {
    final StringBuffer retValue = new StringBuffer("<![CDATA[");
    retValue.append(input.replaceAll(END_CDATA_RE, END_CDATA_RE + END_CDATA_REPLACE + START_CDATA));
    retValue.append("]]>");
    return retValue.toString();
}

From source file:com.dss886.nForumSDK.http.ResponseProcessor.java

/**
 * HttpResponse?String/*www .j a va2 s  . c o m*/
 * @throws IllegalStateException, IOException
 * */
public static String getStringFromResponse(HttpResponse response) throws IllegalStateException, IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    StringBuffer sb = new StringBuffer();
    String line;
    while ((line = in.readLine()) != null) {
        sb.append(line);
    }
    in.close();
    return sb.toString();
}