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:com.tactfactory.harmony.utils.TactFileUtils.java

/**
 * Append String to at the end of a file
 * if it doesn't exists in the file yet.
 * @param content The content to append/*w w w  .  ja v a 2s . c om*/
 * @param file The file to write to
 * @return true if the content has been correctly appended
 */
public static boolean appendToFile(final String content, final File file) {
    boolean success = false;
    final StringBuffer buffer = TactFileUtils.fileToStringBuffer(file);
    //If content doesn't exists in the file yet
    if (buffer.indexOf(content) == -1) {
        final int offset = buffer.length();
        buffer.insert(offset, content);
        TactFileUtils.stringBufferToFile(buffer, file);
        success = true;
    }
    return success;
}

From source file:com.tactfactory.harmony.utils.TactFileUtils.java

/**
 * Add String after a given String in the given file.
 * (Only if it doesn't already exists in the file)
 * @param content The content to append//w w  w  .ja va  2s.  co  m
 * @param after The String after which the content must be added
 * @param file The file to write to
 * @return true if the content has been correctly appended
 */
public static boolean addToFile(final String content, final String after, final File file) {
    boolean success = false;
    final StringBuffer buffer = TactFileUtils.fileToStringBuffer(file);
    //If content doesn't exists in the file yet
    if (buffer.indexOf(content) == -1) {
        final int offset = buffer.indexOf(after) + after.length();
        buffer.insert(offset, content);
        TactFileUtils.stringBufferToFile(buffer, file);
        success = true;
    }
    return success;
}

From source file:eap.util.EDcodeUtil.java

public static byte[] gbk2utf8(String chenese) {
    char c[] = chenese.toCharArray();
    byte[] fullByte = new byte[3 * c.length];
    for (int i = 0; i < c.length; i++) {
        int m = (int) c[i];
        String word = Integer.toBinaryString(m);

        StringBuffer sb = new StringBuffer();
        int len = 16 - word.length();
        for (int j = 0; j < len; j++) {
            sb.append("0");
        }/*from  w w  w  .j  a  v a 2 s .c  o m*/
        sb.append(word);
        sb.insert(0, "1110");
        sb.insert(8, "10");
        sb.insert(16, "10");

        byte[] bf = new byte[3];
        bf[0] = Integer.valueOf(sb.substring(0, 8), 2).byteValue();
        fullByte[i * 3] = bf[0];
        bf[1] = Integer.valueOf(sb.substring(8, 16), 2).byteValue();
        fullByte[i * 3 + 1] = bf[1];
        bf[2] = Integer.valueOf(sb.substring(16), 2).byteValue();
        fullByte[i * 3 + 2] = bf[2];

    }
    return fullByte;
}

From source file:UUIDUtils.java

/**
 * @param secure Boolean indicating whether to create a secure UUID.
 * @see #createUUID()/*from  www  .  j a v a2 s . c  o  m*/
 */
public static String createUUID(boolean secure) {
    Random rand = secure ? _rand : _weakRand;

    StringBuffer s = new StringBuffer(36);

    appendHexString(uniqueTOD(), false, 11, s);

    //  Just use random padding characters, but ensure that the high bit
    //  is set to eliminate chances of collision with an IEEE 802 address.
    s.append(alphaNum.charAt(rand.nextInt(16) | 8));

    //  Add random padding characters.
    appendRandomHexChars(32 - s.length(), rand, s);

    //insert dashes in proper position. so the format matches CF
    s.insert(8, "-");
    s.insert(13, "-");
    s.insert(18, "-");
    s.insert(23, "-");

    return s.toString();
}

From source file:com.icesoft.faces.component.util.CustomComponentUtils.java

public static String getPathToComponent(UIComponent component) {
    StringBuffer buf = new StringBuffer();

    if (component == null) {
        buf.append("{Component-Path : ");
        buf.append("[null]}");
        return buf.toString();
    }/*from   w ww  .j  ava 2s  .  co m*/

    getPathToComponent(component, buf);

    buf.insert(0, "{Component-Path : ");
    buf.append("}");

    return buf.toString();
}

From source file:org.hyperic.hq.product.jmx.MBeanUtil.java

private static String toString(MBeanParameterInfo[] pinfo) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < pinfo.length; i++) {
        if (sb.length() != 0) {
            sb.append(", ");
        }/* w w  w  .  j  a  v  a  2s .  c om*/
        sb.append(pinfo[i].getType());
    }
    sb.insert(0, '(');
    sb.append(')');
    return sb.toString();
}

From source file:org.dhatim.util.ClassUtil.java

public static String toIsGetterName(String property) {
    StringBuffer getterName = new StringBuffer();

    // Add the property string to the buffer...
    getterName.append(property);/*w  ww  .jav  a 2s .  c o  m*/
    // Uppercase the first character...
    getterName.setCharAt(0, Character.toUpperCase(property.charAt(0)));
    // Prefix with "is"...
    getterName.insert(0, "is");

    return getterName.toString();
}

From source file:org.dhatim.util.ClassUtil.java

public static String toSetterName(String property) {
    StringBuffer setterName = new StringBuffer();

    // Add the property string to the buffer...
    setterName.append(property);//w ww.  j a  va2 s .co m
    // Uppercase the first character...
    setterName.setCharAt(0, Character.toUpperCase(property.charAt(0)));
    // Prefix with "set"...
    setterName.insert(0, "set");

    return setterName.toString();
}

From source file:org.dhatim.util.ClassUtil.java

public static String toGetterName(String property) {
    StringBuffer getterName = new StringBuffer();

    // Add the property string to the buffer...
    getterName.append(property);/*from  w  w w.ja v  a2  s.  co  m*/
    // Uppercase the first character...
    getterName.setCharAt(0, Character.toUpperCase(property.charAt(0)));
    // Prefix with "get"...
    getterName.insert(0, "get");

    return getterName.toString();
}

From source file:com.albert.util.StringUtilCommon.java

/**
 * Left pad string with char c.//from   ww w  . j av  a  2 s.  com
 * 
 * @param s
 * @param n
 * @param c
 * @return String
 */
public static String lPad(String s, int n, char c) {
    if (s == null) {
        return s;
    }
    int add = n - s.length();
    if (add <= 0) {
        return s;
    }
    StringBuffer str = new StringBuffer(s);
    char[] ch = new char[add];
    Arrays.fill(ch, c);
    str.insert(0, ch);

    return str.toString();
}