Example usage for java.lang StringBuffer append

List of usage examples for java.lang StringBuffer append

Introduction

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

Prototype

@Override
    public synchronized StringBuffer append(double d) 

Source Link

Usage

From source file:Main.java

public static String percent(double value1, double value2, int decimalPointAfterLength, boolean replaceWithZero,
        boolean removePercent) {
    StringBuffer buffString = new StringBuffer();
    buffString.append("#");
    if (decimalPointAfterLength > 0) {
        buffString.append(".");
    }/*w w w . j av a2s. c om*/
    for (int w = 0; w < decimalPointAfterLength; w++) {
        buffString.append(replaceWithZero ? "0" : "#");
    }
    buffString.append("%");
    if (buffString.length() > 0) {
        String result = new DecimalFormat(buffString.toString()).format(value1 / value2);
        if (removePercent && result.length() > 0) {
            result = result.substring(0, result.length() - 1);
        }
        return result;
    } else {
        return null;
    }
}

From source file:Main.java

public static StringBuffer getInvoiceSummaryXMLChunk() {

    StringBuffer summary = new StringBuffer();

    summary.append("<InvoiceDetailSummary>");
    summary.append("<SubtotalAmount><Money currency=\"USD\">10</Money></SubtotalAmount>");
    summary.append("<Tax>");
    summary.append("<Money currency=\"USD\">0</Money>");
    summary.append("<Description xml:lang=\"en\">TOTAL TAX</Description>");
    summary.append("<TaxDetail category=\"sales\" percentageRate=\"0\" purpose=\"tax\">");
    summary.append("<TaxAmount><Money currency=\"USD\">0.0</Money></TaxAmount>");
    summary.append("<Description xml:lang=\"en\">Item State and Local Tax</Description>");
    summary.append("</TaxDetail></Tax>");
    summary.append("<SpecialHandlingAmount><Money currency=\"USD\">0.00</Money></SpecialHandlingAmount>\n");
    summary.append("<ShippingAmount><Money currency=\"USD\">0.00</Money></ShippingAmount>");
    summary.append("<InvoiceDetailDiscount><Money currency=\"USD\">0.00</Money></InvoiceDetailDiscount>");

    summary.append("<NetAmount><Money currency=\"USD\">10.00</Money></NetAmount>");
    summary.append("<DepositAmount><Money currency=\"USD\">2.00</Money></DepositAmount>");
    summary.append("<DueAmount><Money currency=\"USD\">10.00</Money></DueAmount>");
    summary.append("</InvoiceDetailSummary>");

    return summary;
}

From source file:Main.java

public static String encodeBytes(byte[] bytes) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < bytes.length; i++) {
        sb.append((char) (((bytes[i] >> 4) & 0xF) + ((int) 'a')));
        sb.append((char) (((bytes[i]) & 0xF) + ((int) 'a')));
    }//w w  w . j  av  a2 s  . c o m
    return sb.toString();
}

From source file:Main.java

public static final String arrayToString(byte[] bytes) {
    StringBuffer buff = new StringBuffer();
    for (int i = 0; i < bytes.length; i++) {
        buff.append(bytes[i] + " ");
    }/*  w  ww.  ja  va2  s.  com*/
    return buff.toString();
}

From source file:Main.java

/**
 * Create a simple XML tag with attributes. For example
 * xmlTag("foo", "bar", new String[]{"foo", "bar}) creates
 * &lt;foo foo="bar"&gt;bar&lt;/foo&gt;
 * //from w ww .  j a  v a  2 s .com
 * @param tagName
 *            The name of the tag
 * @param content
 *            The content of the tag
 * @param attributes
 *            The attributes of the element
 * @return The created XML tag
 */
public static String xmlTag(String tagName, String content, String[] attributes) {
    StringBuffer sb = new StringBuffer();
    sb.append("<").append(tagName);
    if (attributes != null) {
        for (int i = 0; i < attributes.length; i += 2) {
            sb.append(" ").append(attributes[i]).append("=\"").append(attributes[i + 1]).append("\"");
        }
    }
    if (content == null || content.length() == 0) {
        sb.append(" />");
    } else {
        sb.append(">");
        sb.append(content);
        sb.append("</").append(tagName).append(">");
    }
    return sb.toString();
}

From source file:Main.java

/**
 * Used to print out a string for error messages, 
 * chops is off at 60 chars for historical reasons.
 *//*from   w ww.  jav a  2s  .c  o  m*/
public final static String formatForPrint(String input) {
    if (input.length() > 60) {
        StringBuffer tmp = new StringBuffer(input.substring(0, 60));
        tmp.append("&");
        input = tmp.toString();
    }
    return input;
}

From source file:Main.java

public static String getASCII(int begin, int end) {
    StringBuffer sb = new StringBuffer();
    for (int i = begin; i < end; i++) {
        sb.append(i).append(":").append((char) i).append("/t");
        // sb.append((char) i).append("/t");  
        if (i % 10 == 0) {
            sb.append("/n");
        }/*ww  w .j ava  2s. co  m*/
    }
    return sb.toString();
}

From source file:Main.java

private static String genRandomString(int pLength) {
    Random r = new Random();
    String letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < pLength; i++) {
        sb.append(letter.charAt(r.nextInt(1000000) % (letter.length())));
    }/*from  www. j ava  2 s  .  co m*/
    return sb.toString();
}

From source file:Main.java

public static String generateRandomUTDID() {
    StringBuffer stringBuffer = new StringBuffer();
    for (int i = 0; i < 24; i++) {
        stringBuffer.append((char) (random.nextInt(25) + 65));
    }//ww w.j a v a  2  s. com
    return stringBuffer.toString();
}

From source file:Main.java

/**
 * The Internal helper method converts a byte[] to a String
 * /*from ww  w. ja va2s. c  o m*/
 * @param byte[] to transform in a String 
 * @return String of the byte[]
 */
public static String bytesToString(byte[] bytes) {
    StringBuffer sb = new StringBuffer();
    for (byte b : bytes) {
        sb.append(String.format("%02x ", b & 0xFF));
    }
    return sb.toString();
}