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.enonic.cms.business.portal.rendering.tracing.TraceMarkerHelper.java

/**
 * This method modifies the markup with extra trace code.
 *///from   w w  w  . j a va 2s  . c o  m
public static String writePageMarker(RenderTraceInfo traceInfo, String markup, String outputMethod) {
    outputMethod = outputMethod.toLowerCase();
    boolean usePageMarker = outputMethod.contains("html");

    if ((traceInfo != null) && usePageMarker) {
        StringBuffer buffer = new StringBuffer(markup);
        int pos = buffer.indexOf("</head>");
        if (pos > -1) {
            String href = "__info__?type=css&key=" + traceInfo.getKey();
            href = makeXmlCompliantIfNeeded(href, outputMethod);
            buffer.insert(pos, writeCssInclude(href));
        }

        pos = buffer.indexOf("</body>");
        if (pos > -1) {
            String href = "__info__?type=javascript&key=" + traceInfo.getKey();
            href = makeXmlCompliantIfNeeded(href, outputMethod);
            buffer.insert(pos, writeJavaScriptInclude(href));
        }

        return buffer.toString();
    } else {
        return markup;
    }
}

From source file:com.enonic.cms.core.portal.rendering.tracing.TraceMarkerHelper.java

/**
 * This method modifies the markup with extra trace code.
 *//*from www .  ja  v  a  2 s  . com*/
public static String writePageMarker(RenderTraceInfo traceInfo, String markup, String outputMethod) {
    if (outputMethod == null) {
        return markup;
    }

    outputMethod = outputMethod.toLowerCase();
    boolean usePageMarker = outputMethod.contains("html");

    if ((traceInfo != null) && usePageMarker) {
        StringBuffer buffer = new StringBuffer(markup);
        int pos = buffer.indexOf("</head>");
        if (pos > -1) {
            String href = "__info__?type=css&key=" + traceInfo.getKey();
            href = makeXmlCompliantIfNeeded(href, outputMethod);
            buffer.insert(pos, writeCssInclude(href));
        }

        pos = buffer.indexOf("</body>");
        if (pos > -1) {
            String href = "__info__?type=javascript&key=" + traceInfo.getKey();
            href = makeXmlCompliantIfNeeded(href, outputMethod);
            buffer.insert(pos, writeJavaScriptInclude(href));
        }

        return buffer.toString();
    } else {
        return markup;
    }
}

From source file:XMLWriteTest.java

/**
 * Converts a color to a hex value.//from w ww  . j a v  a 2  s.com
 * @param c a color
 * @return a string of the form #rrggbb
 */
private static String colorToString(Color c) {
    StringBuffer buffer = new StringBuffer();
    buffer.append(Integer.toHexString(c.getRGB() & 0xFFFFFF));
    while (buffer.length() < 6)
        buffer.insert(0, '0');
    buffer.insert(0, '#');
    return buffer.toString();
}

From source file:com.spaceprogram.simplejpa.util.AmazonSimpleDBUtil.java

public static String encodeRealNumberRange(BigDecimal number, int maxNumDigits, BigDecimal offsetValue) {
    BigDecimal offsetNumber = number.add(offsetValue);
    String longString = offsetNumber.toString();
    int numZeroes = maxNumDigits - longString.length();
    StringBuffer strBuffer = new StringBuffer(numZeroes + longString.length());
    for (int i = 0; i < numZeroes; i++) {
        strBuffer.insert(i, '0');
    }/*w w w  .j a v  a  2  s  . co m*/
    strBuffer.append(longString);
    return strBuffer.toString();
}

From source file:com.spaceprogram.simplejpa.util.AmazonSimpleDBUtil.java

/**
 * Encodes real integer value into a string by offsetting and zero-padding
 * number up to the specified number of digits.  Use this encoding method if the data
 * range set includes both positive and negative values.
 *
 * @param number integer to be encoded/*from   ww w  . java2s .c o  m*/
 * @param maxNumDigits maximum number of digits in the largest absolute value in the data set
 * @param offsetValue offset value, has to be greater than absolute value of any negative number in the data set.
 * @return string representation of the integer
 */
public static String encodeRealNumberRange(int number, int maxNumDigits, int offsetValue) {
    long offsetNumber = number + offsetValue;
    String longString = Long.toString(offsetNumber);
    int numZeroes = maxNumDigits - longString.length();
    StringBuffer strBuffer = new StringBuffer(numZeroes + longString.length());
    for (int i = 0; i < numZeroes; i++) {
        strBuffer.insert(i, '0');
    }
    strBuffer.append(longString);
    return strBuffer.toString();
}

From source file:com.spaceprogram.simplejpa.util.AmazonSimpleDBUtil.java

/**
 * Encodes positive integer value into a string by zero-padding number up to the specified number of digits.
 *
 * @param   number positive integer to be encoded
 * @param   maxNumDigits maximum number of digits in the largest value in the data set
 * @return string representation of the zero-padded integer
 *///ww  w .  j a  va2 s  .  c  o  m
public static String encodeZeroPadding(int number, int maxNumDigits) {
    String integerString = Integer.toString(number);
    int numZeroes = maxNumDigits - integerString.length();
    StringBuffer strBuffer = new StringBuffer(numZeroes + integerString.length());
    for (int i = 0; i < numZeroes; i++) {
        strBuffer.insert(i, '0');
    }
    strBuffer.append(integerString);
    return strBuffer.toString();
}

From source file:com.spaceprogram.simplejpa.util.AmazonSimpleDBUtil.java

/**
 * Encodes positive float value into a string by zero-padding number up to the specified number of digits
 *
 * @param   number positive float value to be encoded
 * @param   maxNumDigits   maximum number of digits preceding the decimal point in the largest value in the data set
 * @return string representation of the zero-padded float value
 *//*from w  ww .ja va 2  s  . c o  m*/
public static String encodeZeroPadding(float number, int maxNumDigits) {
    String floatString = Float.toString(number);
    int numBeforeDecimal = floatString.indexOf('.');
    numBeforeDecimal = (numBeforeDecimal >= 0 ? numBeforeDecimal : floatString.length());
    int numZeroes = maxNumDigits - numBeforeDecimal;
    StringBuffer strBuffer = new StringBuffer(numZeroes + floatString.length());
    for (int i = 0; i < numZeroes; i++) {
        strBuffer.insert(i, '0');
    }
    strBuffer.append(floatString);
    return strBuffer.toString();
}

From source file:cn.edu.bit.whitesail.utils.MD5Signature.java

public static String calculate(byte[] byteArray) {
    StringBuffer result = null;
    if (byteArray == null)
        return null;
    try {//  w ww .jav  a2  s . co  m
        MessageDigest m = MessageDigest.getInstance("MD5");
        m.update(byteArray);
        result = new StringBuffer(new BigInteger(1, m.digest()).toString(16));
        for (int i = 0; i < 32 - result.length(); i++)
            result.insert(0, '0');
    } catch (NoSuchAlgorithmException ex) {
        LOG.fatal("MD5 Hashing Failed,System is going down");
        System.exit(1);
    }
    return result.toString();
}

From source file:eu.leads.processor.planner.ClassUtil.java

private static String createClassName(File root, File file) {
    StringBuffer sb = new StringBuffer();
    String fileName = file.getName();
    sb.append(fileName.substring(0, fileName.lastIndexOf(".class")));
    file = file.getParentFile();// ww w. j  av a 2  s  .  c om
    while (file != null && !file.equals(root)) {
        sb.insert(0, '.').insert(0, file.getName());
        file = file.getParentFile();
    }
    return sb.toString();
}

From source file:com.spaceprogram.simplejpa.util.AmazonSimpleDBUtil.java

/**
 * Encodes real float value into a string by offsetting and zero-padding
 * number up to the specified number of digits.  Use this encoding method if the data
 * range set includes both positive and negative values.
 *
 * @param number float to be encoded/*from  w w  w  .  j  a  v  a2s . co m*/
 * @param maxDigitsLeft maximum number of digits left of the decimal point in the largest absolute value in the data set
 * @param maxDigitsRight maximum number of digits right of the decimal point in the largest absolute value in the data set, i.e. precision
 * @param offsetValue offset value, has to be greater than absolute value of any negative number in the data set.
 * @return string representation of the integer
 */
public static String encodeRealNumberRange(float number, int maxDigitsLeft, int maxDigitsRight,
        int offsetValue) {
    int shiftMultiplier = (int) Math.pow(10, maxDigitsRight);
    long shiftedNumber = (long) Math.round(number * shiftMultiplier);
    long shiftedOffset = offsetValue * shiftMultiplier;
    long offsetNumber = shiftedNumber + shiftedOffset;
    String longString = Long.toString(offsetNumber);
    int numBeforeDecimal = longString.length();
    int numZeroes = maxDigitsLeft + maxDigitsRight - numBeforeDecimal;
    StringBuffer strBuffer = new StringBuffer(numZeroes + longString.length());
    for (int i = 0; i < numZeroes; i++) {
        strBuffer.insert(i, '0');
    }
    strBuffer.append(longString);
    return strBuffer.toString();
}