List of usage examples for java.lang StringBuilder toString
@Override
@HotSpotIntrinsicCandidate
public String toString()
From source file:com.shahnami.fetch.Controller.JsonReader.java
private static String readAll(Reader rd) throws IOException { StringBuilder sb = new StringBuilder(); int cp;/* ww w .j av a 2s. c om*/ while ((cp = rd.read()) != -1) { sb.append((char) cp); } return sb.toString().replace(".ag", ".bypassed.me"); }
From source file:Main.java
public static String join(String r[], String d) { if (r.length == 0) return ""; StringBuilder sb = new StringBuilder(); int i;/* ww w .jav a2 s . c om*/ for (i = 0; i < r.length - 1; i++) { sb.append(r[i]); sb.append(d); } return sb.toString() + r[i]; }
From source file:Main.java
private static String makeContent(InputStream is) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line;/*ww w .j a v a2s. com*/ while ((line = br.readLine()) != null) { sb.append(line + "\n"); } br.close(); return sb.toString(); }
From source file:Main.java
public static String map2Str(Map<String, String> map) { StringBuilder sb = new StringBuilder(""); Set<String> keys = map.keySet(); for (String key : keys) sb.append(key + ":" + map.get(key) + ", "); String s = sb.toString().trim(); if (!s.endsWith(",")) return s; else/*from w ww .ja va 2 s .c o m*/ return s.substring(0, s.lastIndexOf(",") - 1); }
From source file:Main.java
private static String encodeHex(byte[] data) { StringBuilder sb = new StringBuilder(data.length * 2); Formatter formatter = new Formatter(sb); for (byte b : data) { formatter.format("%02x", b); }/*from w w w .j av a2s . c o m*/ return sb.toString(); }
From source file:Main.java
private static synchronized void logToFile(String tag, String msg) { try {/* w w w. j a va 2 s .c o m*/ if (LOG_FILE == null) { LOG_FILE = new File(LOG_FILE_PATH); if (LOG_FILE.exists()) { LOG_FILE.delete(); } LOG_FILE.createNewFile(); } FileOutputStream outputStream = new FileOutputStream(LOG_FILE, true); StringBuilder builder = new StringBuilder(); builder.append(tag).append(" : ").append(msg).append("\n"); outputStream.write(builder.toString().getBytes()); outputStream.flush(); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Util.java
/** * Charge le contenu d'un stream dans un string * /*from ww w.j av a 2 s. co m*/ * @param stream * @return * @throws IOException */ public static String loadStream(InputStream stream) throws IOException { Reader reader = new InputStreamReader(stream, Charset.forName("UTF-8")); char[] buffer = new char[1024]; int count; StringBuilder str = new StringBuilder(); while ((count = reader.read(buffer)) != -1) str.append(buffer, 0, count); return str.toString(); }
From source file:Main.java
public static String getStringContent(List<Object> content) { StringBuilder b = new StringBuilder(); for (Object o : content) { if (o instanceof String) { b.append(o);/*from w w w .j a va 2 s.c o m*/ } } return b.toString(); }
From source file:Main.java
/** * Decompresses a array of bytes back into a string. * * @param bytes The compressed list of bytes. * * @return The string uncompress./*from www. ja v a 2 s .c o m*/ * * @throws Exception If failed to uncompress. */ public static String decompress(byte[] bytes) throws Exception { if (bytes == null || bytes.length == 0) { return null; } GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(bytes)); BufferedReader bf = new BufferedReader(new InputStreamReader(gis, "UTF-8")); StringBuilder result = new StringBuilder(); String line; while ((line = bf.readLine()) != null) { result.append(line); } return result.toString(); }
From source file:Main.java
/** * Generate a random String//from w w w.j a v a 2 s . c om * * @param values The characters list to use in the randomization * @param len The number of characters in the output String * @return The randomized String */ public static String randomString(char[] values, int len) { Random rnd = new SecureRandom(); StringBuilder sb = new StringBuilder(len); for (int i = 0; i < len; i++) { sb.append(values[rnd.nextInt(values.length)]); } return sb.toString(); }