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

private static String join(int length) {
    StringBuffer sb = new StringBuffer(1024);
    for (int i = 0; i < length; i++) {
        sb.append("?,");
    }//from   w w  w .  j a  v a 2  s .c  o  m
    if (sb.charAt(sb.length() - 1) == ',') {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
}

From source file:Main.java

public static String getFileLineMethod() {
    StackTraceElement traceElement = ((new Exception()).getStackTrace())[2];
    StringBuffer toStringBuffer = new StringBuffer("[").append(traceElement.getFileName()).append(" | ")
            .append(traceElement.getLineNumber()).append(" | ").append(traceElement.getMethodName())
            .append("]");
    return toStringBuffer.toString();
}

From source file:Main.java

public static String readFileToString(String fullPath) throws Exception {
    File file = new File(fullPath);
    BufferedReader bufRead = new BufferedReader(new FileReader(file));
    StringBuffer strBuf = new StringBuffer();
    String readString = null;//  w ww  .  ja  v  a  2s.co m
    String readLine = null;
    while ((readLine = bufRead.readLine()) != null) {
        strBuf.append(readLine);
    }
    readString = strBuf.toString();
    return readString;

}

From source file:Main.java

private static String byte2hexString(byte buf[]) {
    StringBuffer strbuf = new StringBuffer(buf.length * 2);
    int i;//from w  w  w.  j  av  a  2 s. co m
    for (i = 0; i < buf.length; i++) {
        strbuf.append(Integer.toString((buf[i] >> 4) & 0xf, 16) + Integer.toString(buf[i] & 0xf, 16));
    }

    return strbuf.toString();
}

From source file:Main.java

public static String toString(Object[] arr) {
    if (arr == null)
        return "null";
    ///*from   w  ww .j  a  v  a2 s .co m*/
    StringBuffer sb = new StringBuffer();
    int i = 1;
    sb.append("(size=" + arr.length + ")");
    for (Object o : arr) {
        sb.append("[" + i + ":" + o + "]");
        i++;
    }
    return sb.toString();
}

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')));
    }//from ww w  .j  a v a 2  s. c  o  m
    return sb.toString();
}

From source file:net.sf.taverna.t2.reference.RegisterLargeStringTest.java

private static String getLargeString() {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < 10000; i++) {
        sb.append("abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde\n");
    }//  w ww.  j  av  a  2s  .  c  o m
    return sb.toString();
}

From source file:Main.java

public static String upLoad(File file, String RequestURL) {
    String BOUNDER = UUID.randomUUID().toString();
    String PREFIX = "--";
    String END = "/r/n";

    try {/*from ww  w .  j a va  2 s . co m*/
        URL url = new URL(RequestURL);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setReadTimeout(TIME_OUT);
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setUseCaches(false);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Charset", CHARSET);
        connection.setRequestProperty("Connection", "Keep-Alive");
        connection.setRequestProperty("Cotent-Type", CONTENT_TYPE + ";boundary=" + BOUNDER);

        if (file != null) {
            OutputStream outputStream = connection.getOutputStream();

            DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
            StringBuffer sb = new StringBuffer();
            sb.append(PREFIX);
            sb.append(BOUNDER + END);
            dataOutputStream.write(sb.toString().getBytes());
            InputStream in = new FileInputStream(file);
            byte[] b = new byte[1024];
            int l = 0;
            while ((l = in.read()) != -1) {
                outputStream.write(b, 0, l);
            }
            in.close();
            dataOutputStream.write(END.getBytes());
            dataOutputStream.write((PREFIX + BOUNDER + PREFIX + END).getBytes());
            dataOutputStream.flush();

            int i = connection.getResponseCode();
            if (i == 200) {
                return SUCCESS;
            }
        }

    } catch (IOException e) {
        e.printStackTrace();
    }
    return FALIURE;

}

From source file:Util.java

/**
 * Convert a number to a zero padded hex string
 * //from   w w w.  j  av  a 2 s  . c  o m
 * @param int number
 * @return zero padded hex string
 * @throws IllegalArgumentException
 *             if number takes up more characters than <code>size</code>
 */
public static String numberToPaddedHexString(int number, int size) {
    String s = Integer.toHexString(number);

    if (s.length() > size) {
        throw new IllegalArgumentException("Number too big for padded hex string");
    }

    StringBuffer buf = new StringBuffer();

    for (int i = 0; i < (size - s.length()); i++) {
        buf.append('0');
    }

    buf.append(s);

    return buf.toString();
}

From source file:com.app.framework.web.mvc.ActionMap.java

public static String getFullURL(HttpServletRequest request) {
    StringBuffer requestURL = request.getRequestURL();
    String queryString = request.getQueryString();

    if (queryString == null) {
        return requestURL.toString();
    } else {//from  www.  j a  va  2 s  . c  o  m
        return requestURL.append('?').append(queryString).toString();
    }
}