List of usage examples for java.lang StringBuffer toString
@Override @HotSpotIntrinsicCandidate public synchronized String toString()
From source file:Main.java
/** * Reads test json//from w w w .j av a 2 s . c o m * * @param filename * @return */ public static String readJSON(String filename) { try { FileInputStream fileInputStream = new FileInputStream(new File(filename)); InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String readData = ""; StringBuffer stringBuffer = new StringBuffer(); while ((readData = bufferedReader.readLine()) != null) { stringBuffer.append(readData); } return stringBuffer.toString(); } catch (IOException e) { e.printStackTrace(); return e.toString(); } }
From source file:Main.java
public static String getMD5Str(String password) { String strResult = ""; MessageDigest md5;/* w w w . j a v a 2s . co m*/ try { md5 = MessageDigest.getInstance("MD5"); md5.update(password.getBytes("UTF-8")); byte[] bzpassword_1 = md5.digest(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < bzpassword_1.length; ++i) { sb.append(String.format("%02x", bzpassword_1[i])); } md5.update(sb.toString().getBytes("UTF-8")); return sb.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static Method getGetMethod(Class<?> objectClass, String fieldName) { StringBuffer sb = new StringBuffer(); sb.append("get"); sb.append(fieldName.substring(0, 1).toUpperCase()); sb.append(fieldName.substring(1));//from w ww . ja v a 2 s.co m try { return objectClass.getMethod(sb.toString()); } catch (Exception e) { } return null; }
From source file:Main.java
public static String join(CharSequence separator, Collection<CharSequence> values) { StringBuffer sb = new StringBuffer(); for (CharSequence value : values) { if (sb.length() > 0) { sb.append(separator);/*from w ww . j av a 2s .c o m*/ } sb.append(value); } return sb.toString(); }
From source file:Main.java
public static String readRawByName(Context context, int id, String encoding) { String text = null;//from w w w. j ava 2s . c om InputStreamReader inputReader = null; BufferedReader bufReader = null; try { inputReader = new InputStreamReader(context.getResources().openRawResource(id)); bufReader = new BufferedReader(inputReader); String line = null; StringBuffer buffer = new StringBuffer(); while ((line = bufReader.readLine()) != null) { buffer.append(line); } text = new String(buffer.toString().getBytes(), encoding); } catch (Exception e) { } finally { try { if (bufReader != null) { bufReader.close(); } if (inputReader != null) { inputReader.close(); } } catch (Exception e) { e.printStackTrace(); } } return text; }
From source file:Main.java
/** * Escapes a string so it may be returned as text content or attribute * value. Non printable characters are escaped using character references. * Where the format specifies a deault entity reference, that reference * is used (e.g. <tt>&lt;</tt>). * * @param source the string to escape. *//*from w w w . ja v a2 s . c om*/ public static String escape(String source) { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < source.length(); ++i) { buffer.append(escape(source.charAt(i))); } return buffer.toString(); }
From source file:Main.java
public static String capWords(String givenString) { String[] arr = givenString.split(" "); StringBuffer sb = new StringBuffer(); for (int i = 0; i < arr.length; i++) { sb.append(Character.toUpperCase(arr[i].charAt(0))).append(arr[i].substring(1)).append(" "); }//from w ww. j a v a2s. c o m return sb.toString().trim(); }
From source file:Main.java
/** * Pad Hex./*from w w w . j a va 2 s . com*/ * * @param s * a String * @param i * a int * @return a String */ private static String padHex(String s, int i) { final StringBuffer tmpBuffer = new StringBuffer(); if (s.length() < i) { for (int j = 0; j < i - s.length(); j++) { tmpBuffer.append('0'); } } return tmpBuffer.toString(); }
From source file:Main.java
/** * Configures a button as if it was an hyperlink. * //from www. j av a 2 s .c o m * @param button * the button to configure. */ public static void configureButtonAsHyperlink(JButton button) { if (button == null) { return; } StringBuffer html = new StringBuffer(); html.append("<html><font color=\"blue\"><u>"); html.append(button.getText()); html.append("</u></font></html>"); button.setText(html.toString()); button.setMargin(new Insets(0, 0, 0, 0)); button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); button.setFocusPainted(false); button.setBorderPainted(false); button.setContentAreaFilled(false); }
From source file:Main.java
public static String byteArrayToHexString(byte[] b) { StringBuffer sb = new StringBuffer(b.length * 2); for (int i = 0; i < b.length; i++) { int v = b[i] & 0xff; if (v < 16) { sb.append('0'); }/*from www .j a v a 2 s.c om*/ sb.append(Integer.toHexString(v)); } return sb.toString().toUpperCase(); }