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 Document noPrefixDomObjcet(StringBuffer data)
        throws SAXException, IOException, ParserConfigurationException {
    Document xmlDoc = null;//from  w  w  w  .  ja  v  a2s  .co m
    xmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
            .parse(new ByteArrayInputStream(data.toString().getBytes()));
    return xmlDoc;
}

From source file:RandomUtil.java

/**
 * Generates a secure random word with the given length.
 * //  w  ww .  j  a v  a 2s  .c o m
 * @param len Amount of random characters to generate
 * @param alphabet Alphabet to generate from.
 * @return random Word containing letters and numbers.
 */
public static String createWord(int len, char[] alphabet) {
    SecureRandom random = createSecureRandom();

    if (alphabet == null) {
        alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890".toCharArray();
    }

    StringBuffer out = new StringBuffer(len);
    for (int i = 0; i < len; i++) {
        out.append(alphabet[random.nextInt(alphabet.length)]);
    }

    return out.toString();
}

From source file:HexSupport.java

/**
 * @param bytes/* ww  w .jav a 2 s. c om*/
 * @return
 */
public static String toHexFromBytes(byte[] bytes) {
    StringBuffer rc = new StringBuffer(bytes.length * 2);
    for (int i = 0; i < bytes.length; i++) {
        rc.append(HEX_TABLE[0xFF & bytes[i]]);
    }
    return rc.toString();
}

From source file:Main.java

public static String string2HexString(String str) {

    StringBuffer hexString = new StringBuffer();
    for (int i = 0; i < str.length(); i++) {
        int ch = (int) str.charAt(i);
        String strHex = Integer.toHexString(ch);
        hexString.append(strHex);//w  w  w. ja  v a  2s .co m
    }
    return hexString.toString();

}

From source file:Main.java

public static String sha1(String s) {
    try {/*from  www .  ja  v a 2 s.  c  o  m*/
        MessageDigest digest = MessageDigest.getInstance("SHA-1");
        digest.update(s.getBytes());
        byte messageDigest[] = digest.digest();

        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < messageDigest.length; i++) {
            hexString.append(Integer.toHexString((0xFF & messageDigest[i]) | 0x100).substring(1));
        }
        return hexString.toString();
    } catch (NoSuchAlgorithmException e) {
        return "";
    }
}

From source file:Main.java

public static String getLevel(String xpath, int level) {
    String[] paths = split(xpath);
    StringBuffer b = new StringBuffer();
    for (int i = 0; i < level; i++) {
        b.append(paths[i]);/*  w w  w . j  av  a  2  s  .  co  m*/
        b.append(' '); // compensates the slash
    }
    b.append(paths[level]);
    b.append('/');
    return b.toString();
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static Method getGetMethod(Class objectClass, String fieldName) {

    StringBuffer sb = new StringBuffer();

    sb.append("get");

    sb.append(fieldName.substring(0, 1).toUpperCase());

    sb.append(fieldName.substring(1));//  w  w w.  ja v a  2 s .  c o  m

    try {

        return objectClass.getMethod(sb.toString());

    } catch (Exception e) {

    }

    return null;

}

From source file:Main.java

public static String join(long[] array, String seperator) {
    StringBuffer sb = new StringBuffer();

    for (int i = 0; i < array.length; i++) {
        if (i > 0) {
            sb.append(seperator);//from   w w  w  .ja v  a 2  s.  c  o m
        }

        sb.append(array[i]);
    }

    return sb.toString();
}

From source file:Main.java

private static String getDumpStack(StackTraceElement[] se) {
    String CRLF = System.getProperty("line.separator");
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < se.length; i++) {
        if (sb.length() > 0) {
            sb.append(CRLF);/*from   ww w . j  a  va 2 s  .c om*/
        }
        sb.append("\t" + se[i]);
    }
    return sb.toString();
}

From source file:Main.java

/**
 * Absolutize a relative resource path on the given absolute base path.
 *
 * @param path The absolute base path/*w  ww.  ja  v  a2s  .  co m*/
 * @param resource The relative resource path
 * @return The absolutized resource path
 */
public static String absolutize(String path, String resource) {
    if (path == null || path.isEmpty()) {
        return resource;
    } else if (resource == null || resource.isEmpty()) {
        return path;
    } else if (resource.charAt(0) == '/') {
        // Resource path is already absolute
        return resource;
    }

    boolean slash = (path.charAt(path.length() - 1) == '/');

    StringBuffer b = new StringBuffer(path.length() + 1 + resource.length());
    b.append(path);
    if (!slash) {
        b.append('/');
    }
    b.append(resource);
    return b.toString();
}