Example usage for java.lang StringBuilder toString

List of usage examples for java.lang StringBuilder toString

Introduction

In this page you can find the example usage for java.lang StringBuilder toString.

Prototype

@Override
    @HotSpotIntrinsicCandidate
    public String toString() 

Source Link

Usage

From source file:Main.java

/**
 * Reads an InputStream and converts it to a String.
 * @param stream//from   w ww.ja  va2  s .  co  m
 * @return
 * @throws IOException 
 */
public static String readIt(InputStream stream) throws IOException {
    BufferedReader r = new BufferedReader(new InputStreamReader(stream));
    StringBuilder total = new StringBuilder();
    String line;
    while ((line = r.readLine()) != null) {
        total.append(line);
    }

    return total.toString();
}

From source file:utils.TestObjectConverter.java

public static String createStringWithLength(int length) {
    StringBuilder builder = new StringBuilder();

    for (int index = 0; index < length; index++) {
        builder.append("a");
    }//  w ww  . j ava  2s .c  om

    return builder.toString();
}

From source file:Main.java

public static String getRandomNumString(int length) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < length; i++) {
        builder.append(String.valueOf((int) (Math.random() * 10)));
    }//from   w w w  . jav  a 2  s  .co  m
    return builder.toString();
}

From source file:Main.java

public static String getTimeString(Calendar calendar) {
    if (calendar == null)
        return "";
    String hourString = String.format("%1$02d", calendar.get(Calendar.HOUR_OF_DAY));
    String minuteString = String.format("%1$02d", calendar.get(Calendar.MINUTE));
    StringBuilder dateStringBuilder = new StringBuilder();
    dateStringBuilder.append(hourString).append(":");
    dateStringBuilder.append(minuteString);
    return dateStringBuilder.toString();
}

From source file:Main.java

public static String getByteArrayString(byte[] bytes) {
    StringBuilder builder = new StringBuilder();
    for (byte aByte : bytes) {
        builder.append(String.format("%02x ", aByte & 0xFF));
    }//from ww  w  . ja va2s. c om
    return builder.toString();
}

From source file:Main.java

public static String serializeList(List<String> data) {
    StringBuilder builder = new StringBuilder();
    for (String entry : data) {
        builder.append(entry);/*from w  ww . j  a  v a  2  s .  c o m*/
        builder.append(DELIMITER);
    }
    return builder.toString();
}

From source file:Main.java

public static String loadAssetsText(AssetManager assetManager, String fileName, String charset) {
    String text = null;/* w  w w.ja v  a 2 s .  c o m*/
    try {
        BufferedReader br = new BufferedReader(new InputStreamReader(assetManager.open(fileName), charset));
        StringBuilder sb = new StringBuilder();
        while ((text = br.readLine()) != null) {
            sb.append(text);
        }
        text = sb.toString();
    } catch (IOException e) {
        Log.e(TAG, e.getMessage(), e);
    }
    return text;
}

From source file:Main.java

public static String toIsoDateFormat(Date date) {

    TimeZone timeZone = TimeZone.getDefault();
    boolean utc = TimeZone.getTimeZone("UTC").equals(timeZone) || TimeZone.getTimeZone("GMT").equals(timeZone);

    String pattern = utc ? "yyyy-MM-dd'T'HH:mm:ss'Z'" : "yyyy-MM-dd'T'HH:mm:ssZ";
    SimpleDateFormat format = new SimpleDateFormat(pattern);
    format.setTimeZone(timeZone);//from   w  ww. j  av a2  s.c  om

    StringBuilder buffer = new StringBuilder(format.format(date));
    if (!utc) {
        buffer.insert(buffer.length() - 2, ':');
    }

    return buffer.toString();
}

From source file:Main.java

public static String readStream(InputStream stream) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(stream));
    StringBuilder contents = new StringBuilder();
    String line;//w  w w  .j  ava  2s. c  o  m
    while ((line = in.readLine()) != null) {
        contents.append(line);
    }
    return contents.toString();
}

From source file:fr.free.divde.webcam.image.DataImageUrl.java

public static String imageToDataURL(BufferedImage image, String format, String mimeType) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ImageIO.write(image, format, out);
    byte[] imageBytes = out.toByteArray();
    String base64 = Base64.encodeBase64String(imageBytes);
    StringBuilder res = new StringBuilder("data:");
    res.append(mimeType);//w w w  .  j av  a 2  s. co  m
    res.append(";base64,");
    res.append(base64);
    return res.toString();
}