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

public static String convertStreamToString(InputStream is) throws Exception {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();
    String line;//from  w ww. ja va 2  s. com
    while ((line = reader.readLine()) != null) {
        sb.append(line).append("\n");
    }
    return sb.toString();
}

From source file:Main.java

public static void writeJsonOnDisk(Context context, String fileName, StringBuilder bigStr) {
    try {/*from  ww  w . ja  va  2s.c  o m*/
        FileWriter Filewriter = new FileWriter(context.getApplicationInfo().dataDir + "/" + fileName + ".json");
        Filewriter.write(bigStr.toString());
        Filewriter.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static boolean getNextPermutation(StringBuilder sb) {
    List<Character> list = asList(sb.toString().toCharArray());
    boolean ret = getNextPermutation(list);

    Object[] array = list.toArray();
    sb.delete(0, sb.length());/*from   w  w  w . j  a v  a2s.c  o  m*/
    sb.append(toCharArray(array));

    return ret;
}

From source file:Main.java

public static String nextString(int length) {
    StringBuilder vals = new StringBuilder();
    for (int i = 0; i < length; i++) {
        vals.append(LETTER_NUMBER_LOWER.charAt(random.nextInt(length)));
    }//from   w  w w.  j  a va 2s .  c  o  m
    return vals.toString();
}

From source file:Main.java

public static String toHexString(byte[] bytes) {
    StringBuilder sb = new StringBuilder(bytes.length * 2);
    for (byte b : bytes) {
        sb.append(hex[((b >> 4) & 0xF)]).append(hex[((b >> 0) & 0xF)]);
    }//from  w w w .  j a v  a2 s .  c  o  m
    return sb.toString();
}

From source file:Main.java

public static String getTxRef() {
    String ints = "0123456789";
    SecureRandom rnd = new SecureRandom();
    StringBuilder sb = new StringBuilder("rave-checkout-");
    for (int i = 0; i < 10; i++) {
        sb.append(ints.charAt(rnd.nextInt(ints.length())));
    }/*from w w w  .  jav  a  2s . com*/
    return sb.toString();
}

From source file:Main.java

public static String getHour(int Hour) {
    StringBuilder hourStr = new StringBuilder();
    if (Hour < 10) {
        hourStr.append("0" + Hour);
    } else {// w  w  w. jav  a 2  s  . c  o  m
        hourStr.append(Hour);
    }

    return hourStr.toString();
}

From source file:Main.java

private static String create(int i) {
    StringBuilder sb = new StringBuilder();
    sb.append("Welcome to <a href=");
    sb.append("'http://www.java2s.com'>Example ");
    sb.append(i);//from w  w w  .  j a v a2  s.co  m
    sb.append("</a>.<br>");
    return sb.toString();
}

From source file:Main.java

public static String asciiToHex(String ascii) {
    StringBuilder hex = new StringBuilder();

    for (int i = 0; i < ascii.length(); i++) {
        hex.append(Integer.toHexString(ascii.charAt(i)));
    }//  w w w  .j a  v  a2s. c  o m
    return hex.toString();
}

From source file:com.github.rinde.dynurg.PoissonDynamismExperiment.java

static void createDynamismHistogram(TimeSeriesGenerator generator, long seed, File file, int repetitions) {
    try {//from   w  w  w .  j a  v a  2  s .c om
        Files.createParentDirs(file);
    } catch (final IOException e1) {
        throw new IllegalStateException(e1);
    }
    final RandomGenerator rng = new MersenneTwister(seed);
    final List<Double> values = newArrayList();
    final SummaryStatistics ss = new SummaryStatistics();
    for (int i = 0; i < repetitions; i++) {
        final List<Double> times = generator.generate(rng.nextLong());
        ss.addValue(times.size());
        final double dynamism = Metrics.measureDynamism(times, LENGTH_OF_DAY);
        values.add(dynamism);
    }
    System.out.println(
            file.getName() + " has #events: mean: " + ss.getMean() + " +- " + ss.getStandardDeviation());

    final StringBuilder sb = new StringBuilder();
    sb.append(Joiner.on("\n").join(values));
    try {
        Files.write(sb.toString(), file, Charsets.UTF_8);
    } catch (final IOException e) {
        throw new IllegalStateException(e);
    }
}