List of usage examples for java.lang StringBuffer toString
@Override @HotSpotIntrinsicCandidate public synchronized String toString()
From source file:Main.java
public static String fillSpace(String str, int length) { int strLength = str.length(); if (strLength >= length) { return str; }//from w w w. j av a 2 s . c o m StringBuffer spaceBuffer = new StringBuffer(); for (int i = 0; i < (length - strLength); i++) { spaceBuffer.append(" "); } return str + spaceBuffer.toString(); }
From source file:Main.java
public static String hash(String pass) { MessageDigest md = null;//from w w w .j a v a 2 s . c o m try { md = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } md.update(pass.getBytes()); byte byteData[] = md.digest(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < byteData.length; i++) { sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); }
From source file:Main.java
/** * Return a string padded with the given string for the given count. * * @param buff String buffer used for padding (buffer is not reset). * @param string Pad element.//from w w w . j a va 2s.c o m * @param count Pad count. * @return Padded string. */ public static String pad(final StringBuffer buff, final String string, final int count) { for (int i = 0; i < count; i++) { buff.append(string); } return buff.toString(); }
From source file:Main.java
public static String SHA1(String input) throws NoSuchAlgorithmException { MessageDigest mDigest = MessageDigest.getInstance("SHA1"); byte[] result = mDigest.digest(input.getBytes()); StringBuffer sb = new StringBuffer(); for (int i = 0; i < result.length; i++) { sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1)); }/*from w w w. j ava 2 s. c om*/ return sb.toString(); }
From source file:Main.java
public static String generateRandomString(final int len) { final String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; final Random random = new Random(); final StringBuffer sb = new StringBuffer(); for (int i = 0; i < len; i++) { final int number = random.nextInt(base.length()); sb.append(base.charAt(number));/* ww w. j av a2 s .c o m*/ } return sb.toString(); }
From source file:Main.java
public static String fillSpaceByByte(String str, int length) { byte[] strbyte = str.getBytes(); int strLength = strbyte.length; if (strLength >= length) { return str; }/* w w w.j av a 2s . c o m*/ StringBuffer spaceBuffer = new StringBuffer(); for (int i = 0; i < (length - strLength); i++) { spaceBuffer.append(" "); } return str.concat(spaceBuffer.toString()); }
From source file:Main.java
private static String buildURI(String host, String location, boolean isSecure) { StringBuffer uri = new StringBuffer(); if (isSecure) uri.append("https://"); else/* w w w.j a v a 2 s .c om*/ uri.append("http://"); uri.append(host); uri.append(location); return uri.toString(); }
From source file:Endians.java
static String toString(byte[] a) { StringBuffer result = new StringBuffer("["); for (int i = 0; i < a.length; i++) { result.append(a[i]);/*from ww w. ja v a2 s .co m*/ if (i < a.length - 1) result.append(", "); } result.append("]"); return result.toString(); }
From source file:Main.java
public static String string2Unicode(String string) { StringBuffer unicode = new StringBuffer(); for (int i = 0; i < string.length(); i++) { char c = string.charAt(i); unicode.append("\\" + "u" + Integer.toHexString(c)); }/* ww w . ja v a 2s. c o m*/ return unicode.toString(); }
From source file:Main.java
public static String cleanBlankToString(String des) { char[] chars = des.toCharArray(); StringBuffer sb = new StringBuffer(); for (Character c : chars) { if (java.util.regex.Pattern.matches("\\d", String.valueOf(c))) { sb.append(c);/*from w w w .ja va 2 s . co m*/ } } return sb.toString(); }