Example usage for java.lang StringBuffer insert

List of usage examples for java.lang StringBuffer insert

Introduction

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

Prototype

@Override
public StringBuffer insert(int offset, double d) 

Source Link

Usage

From source file:Main.java

public static String pathUp(Node node, int level) {
    StringBuffer buf = new StringBuffer();
    int current = level;
    while (node != null && current > 0) {
        if (node instanceof Element) {
            if (buf.length() > 0) {
                buf.insert(0, "/");
            }/*from   w ww . j a  v  a2 s  .  c  om*/
            buf.insert(0, node.getNodeName());
            current = current - 1;
        }
        node = node.getParentNode();
    }
    return buf.toString();
}

From source file:org.usapi.common.DataInjector.java

private static String substitute(String string, String pattern, String replacement) {
    int start = string.indexOf(pattern);
    while (start != -1) {
        StringBuffer buffer = new StringBuffer(string);
        buffer.delete(start, start + pattern.length());
        buffer.insert(start, replacement);
        string = new String(buffer);
        start = string.indexOf(pattern, start + replacement.length());
    }//w  ww.j a v  a 2  s.co  m
    return string;
}

From source file:org.gluu.oxtrust.util.PropertyUtil.java

/**
 * Inserts a backslash before every comma
 *///from  ww  w .  j a v  a 2  s .co  m
private static String escapeComma(String s) {
    StringBuffer buf = new StringBuffer(s);
    for (int i = 0; i < buf.length(); i++) {
        char c = buf.charAt(i);
        if (c == ',') {
            buf.insert(i, '\\');
            i++;
        }
    }
    return buf.toString();
}

From source file:org.lexevs.dao.indexer.utility.Utility.java

public static String padStringBuffer(StringBuffer input, char padChar, int desiredLength, boolean prepend) {
    if (prepend) {

        while (input.length() < desiredLength) {
            input.insert(0, padChar);
        }/*  w w w  .  j  a v a2s .  c om*/
    } else {
        while (input.length() < desiredLength) {
            input.append(padChar);
        }
    }
    return input.toString();

}

From source file:Main.java

/**
 * calculates the path of the node up in the hierarchy, example of result is
 * project/build/plugins/plugin level parameter designates the number of
 * parents to climb eg. for level 2 the result would be plugins/plugin level
 * -1 means all the way to the top./*ww  w .j  a  va 2  s  .  c o  m*/
 */
public static String pathUp(Node node, int level) {
    StringBuffer buf = new StringBuffer();

    int current = level;

    while ((node != null) && (current > 0)) {
        if (node instanceof Element) {
            if (buf.length() > 0) {
                buf.insert(0, "/");
            }

            buf.insert(0, node.getNodeName());
            current = current - 1;
        }

        node = node.getParentNode();
    }

    return buf.toString();
}

From source file:Main.java

/**
 * Convert a integer to string./* w w  w  . java  2s  .co  m*/
 * @param num a number.
 * @param cols the number of columns.  The result string may be longer than it.
 * @param padding a padding character to fulfil columns with.
 * @return the result string.
 */
public static String itoa(long num, int cols, char padding) {
    StringBuffer sb = new StringBuffer(cols);
    boolean minus = false;
    if (num < 0) {
        num *= -1;
        cols--;
        minus = true;
    }
    int i = 0;
    while (num > 0) {
        sb.insert(0, num % 10);
        num /= 10;
        i++;
    }
    while (i < cols) {
        sb.insert(0, padding);
        i++;
    }
    if (minus)
        sb.insert(0, '-');
    return sb.toString();
}

From source file:baldrickv.s3streamingtool.Hash.java

public static String hash(String algo, int output_bits, byte b[], int offset, int size) {
    try {/*from  www .  ja v  a 2s  .c  o  m*/
        int output_bytes = output_bits / 4; //hex = 4 bits per byte
        MessageDigest sig = MessageDigest.getInstance(algo);
        sig.update(b, offset, size);
        byte d[] = sig.digest();

        StringBuffer s = new StringBuffer(output_bytes);
        BigInteger bi = new BigInteger(1, d);
        s.append(bi.toString(16));
        while (s.length() < output_bytes) {
            s.insert(0, '0');
        }
        return s.toString();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
        return null;
    }

}

From source file:net.sf.keystore_explorer.crypto.digest.DigestUtil.java

/**
 * Get the digest of a message as a formatted String. Returned in base-16
 * with ':' separators every two characters padded with a leading 0 if
 * necessary to make for an even number of hex characters.
 *
 * @param message/*w ww . j  ava  2s. c om*/
 *            The message to digest
 * @param digestType
 *            The message digest algorithm
 * @return The message digest
 * @throws CryptoException
 *             If message digester could not be created
 */
public static String getFriendlyMessageDigest(byte[] message, DigestType digestType) throws CryptoException {
    byte[] messageDigest = getMessageDigest(message, digestType);

    StringBuffer strBuff = new StringBuffer(new BigInteger(1, messageDigest).toString(16).toUpperCase());

    if ((strBuff.length() % 2) == 1) {
        strBuff.insert(0, '0');
    }

    if (strBuff.length() > 2) {
        for (int i = 2; i < strBuff.length(); i += 3) {
            strBuff.insert(i, ':');
        }
    }

    return strBuff.toString();
}

From source file:com.maddyhome.idea.vim.helper.StringHelper.java

@NotNull
public static String pad(@NotNull String text, int len, char ch) {
    int l = text.length();
    StringBuffer res = new StringBuffer(text);
    for (int i = l; i < len; i++) {
        res.insert(0, ch);
    }/*from  ww  w. j  ava2 s . c  o  m*/

    return res.toString();
}

From source file:net.sf.keystore_explorer.utilities.io.HexUtil.java

/**
 * Get hex string for the supplied big integer: "0x<hex string>" where hex
 * string is outputted in groups of exactly four characters sub-divided by
 * spaces./*from  w w  w.j  av a  2s.c  o m*/
 *
 * @param bigInt
 *            Big integer
 * @return Hex string
 */
public static String getHexString(BigInteger bigInt) {
    // Convert number to hex string
    String hex = bigInt.toString(16).toUpperCase();

    // Get number padding bytes
    int padding = (4 - (hex.length() % 4));

    // Insert any required padding to get groups of exactly 4 characters
    if ((padding > 0) && (padding < 4)) {
        StringBuffer sb = new StringBuffer(hex);

        for (int i = 0; i < padding; i++) {
            sb.insert(0, '0');
        }

        hex = sb.toString();
    }

    // Output with leading "0x" and spaces to form groups
    StringBuffer strBuff = new StringBuffer();

    strBuff.append("0x");

    for (int i = 0; i < hex.length(); i++) {
        strBuff.append(hex.charAt(i));

        if ((((i + 1) % 4) == 0) && ((i + 1) != hex.length())) {
            strBuff.append(' ');
        }
    }

    return strBuff.toString();
}