List of usage examples for java.lang StringBuffer toString
@Override @HotSpotIntrinsicCandidate public synchronized String toString()
From source file:Main.java
public static String getURLContent(String urlStr) throws Exception { URL url = new URL(urlStr); URLConnection connection = url.openConnection(); connection.setDoOutput(true);//from w w w. j a v a 2 s . c o m connection.connect(); OutputStream ous = connection.getOutputStream(); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(ous)); bw.write("index.htm"); bw.flush(); bw.close(); printRequestHeaders(connection); InputStream ins = connection.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(ins)); StringBuffer sb = new StringBuffer(); String msg = null; while ((msg = br.readLine()) != null) { sb.append(msg); sb.append("\n"); // Append a new line } br.close(); return sb.toString(); }
From source file:Main.java
public static String adaptTags(String[] tags, String noneText, String delimiter) { if (tags.length == 0) return noneText; if (tags.length == 1) return tags[0]; final StringBuffer result = new StringBuffer(); for (int i = 0; i < (tags.length - 1); i++) { result.append(tags[i]).append(delimiter); }//ww w. ja v a 2s . c o m result.append(tags[tags.length - 1]); return result.toString(); }
From source file:Main.java
public static String asCsv(String[] arr) { StringBuffer tagcsv = new StringBuffer(); for (String tag : arr) { if (tagcsv.length() > 0) { tagcsv.append(","); }/*w w w . j ava 2 s .c om*/ tagcsv.append(tag); } return tagcsv.toString(); }
From source file:co.turnus.ui.util.HtmlUtil.java
public static String appendStyle(String htmlContent, String name) { StringBuffer b = new StringBuffer(); b.append("<style>"); b.append(fileToString(name + ".css")); b.append("</style>"); b.append(htmlContent);//from ww w .j a v a 2 s . com return b.toString(); }
From source file:Main.java
/** * Convert the given map to a string.// w ww. j a v a2 s. c o m * @param m Any map to display * @return A string (multi-line) containing a view of the desired map */ public static <A, B> String toString(Map<A, B> m) { StringBuffer sb = new StringBuffer(); sb.append("[\n"); for (A key : m.keySet()) { sb.append(" " + key + " => " + m.get(key) + "\n"); } sb.append("]"); return sb.toString(); }
From source file:Main.java
public static String crypt(String senha) { try {/* w ww. j a v a 2 s. com*/ MessageDigest digest = MessageDigest.getInstance("MD5"); digest.update(senha.getBytes()); byte messageDigest[] = digest.digest(); StringBuffer hexString = new StringBuffer(); for (int i = 0; i < messageDigest.length; i++) { hexString.append(Integer.toHexString(0xFF & messageDigest[i])); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return senha; } }
From source file:Main.java
public static String getSringBeforeChar(String sourceStr, char ch) { StringBuffer sb = new StringBuffer(sourceStr); StringBuffer newSb = new StringBuffer(); for (int i = 0; i < sb.length(); i++) { if (sb.charAt(i) == ch) { break; }/*w w w . ja va 2s . co m*/ newSb.append(sb.charAt(i)); } return newSb.toString(); }
From source file:Main.java
public static String stringFromHttpGet(String urlString) { try {/*from w w w.ja va 2s. co m*/ URL url = new URL(urlString); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); return response.toString(); } catch (Exception e) { e.printStackTrace(); logError(e.getMessage()); return null; } }
From source file:Main.java
public static String MD5(String md5) { try {/*from w w w.j a va2s. c om*/ java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); byte[] array; try { array = md.digest(md5.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); array = md.digest(md5.getBytes()); } StringBuffer sb = new StringBuffer(); for (int i = 0; i < array.length; ++i) { sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); } return sb.toString(); } catch (java.security.NoSuchAlgorithmException e) { } return null; }
From source file:Main.java
/** * Calculation md5 hash of string/*w w w.ja v a2 s . c o m*/ * * @param s - string for hash calculation * @return md5 hash of input string */ public static String MD5Hash(String s) { int sHash = s.hashCode(); String result = md5Cache.get(sHash); if (result != null) return result; try { if (MD5 == null) MD5 = MessageDigest.getInstance("MD5"); MessageDigest alg = (MessageDigest) MD5.clone(); alg.update(s.getBytes()); StringBuffer hexString = new StringBuffer(32); for (byte b : alg.digest()) hexString.append(intToHexChars(0xFF & b)); result = hexString.toString(); } catch (Exception e) { } if (result == null) result = String.valueOf(s.hashCode()); md5Cache.put(sHash, result); return result; }