List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:baldrickv.s3streamingtool.Hash.java
public static String hash(String algo, int output_bits, byte b[], int offset, int size) { try {/*from w w w. jav a 2 s . c om*/ int output_bytes = output_bits / 4; //hex = 4 bits per byte MessageDigest sig = MessageDigest.getInstance(algo); sig.update(b, offset, size); byte d[] = sig.digest(); StringBuffer s = new StringBuffer(output_bytes); BigInteger bi = new BigInteger(1, d); s.append(bi.toString(16)); while (s.length() < output_bytes) { s.insert(0, '0'); } return s.toString(); } catch (Exception e) { e.printStackTrace(); System.exit(-1); return null; } }
From source file:HashUtil.java
/** * This is buzhash the hash function on which most other Hash methods are * built.//from w w w. j a va 2s . co m */ private static long buzhash(StringBuffer arg) { /* Hash StringBuffer */ long h = initial_hash; for (int i = 0; i < arg.length(); ++i) h = (h << 1) ^ (h >>> 63) ^ mix_master[(arg.charAt(i) ^ (arg.charAt(i) >>> 8)) & 0xff]; return h; }
From source file:com.marand.thinkmed.api.demographics.DemographicsUtils.java
public static String calculateName(final String name1, final String name2, final String nameHyphen) { final StringBuffer sBuf = new StringBuffer(); if (StringUtils.isNotBlank(name1)) { sBuf.append(name1);//from w w w. ja va 2s . c om } if (StringUtils.isNotBlank(name2)) { if (sBuf.length() != 0) { sBuf.append(' '); } if (StringUtils.isNotBlank(nameHyphen)) { sBuf.append(nameHyphen); sBuf.append(' '); } sBuf.append(name2); } return sBuf.toString(); }
From source file:Main.java
public static String join(String[] array, String delim) { if (array == null || array.length == 0) { return ""; }//from ww w . j ava2 s . c om StringBuffer sb = new StringBuffer(); for (int i = 0; i < array.length; i++) { sb.append(array[i]); sb.append(delim); } return sb.substring(0, sb.length() - delim.length()); }
From source file:com.bstek.dorado.util.PathUtils.java
public static String concatPath(String... paths) { StringBuffer result = new StringBuffer(); for (String path : paths) { if (StringUtils.isEmpty(path)) { continue; }/*from w w w . j a v a 2 s.c o m*/ if (result.length() > 0) { boolean endsWithDelim = (result.charAt(result.length() - 1) == PATH_DELIM); boolean startsWithDelim = (path.charAt(0) == PATH_DELIM); if (endsWithDelim) { if (startsWithDelim) { result.setLength(result.length() - 1); } } else if (!startsWithDelim) result.append(PATH_DELIM); } result.append(path); } return result.toString(); }
From source file:Main.java
public static String join(Number[] numbers, String delim) { if (numbers == null || numbers.length == 0) { return ""; }/*from w w w .j a v a2s .c om*/ StringBuffer sb = new StringBuffer(); for (int i = 0; i < numbers.length; i++) { sb.append(numbers[i]); sb.append(delim); } return sb.substring(0, sb.length() - delim.length()); }
From source file:Comments.java
public static String removeComment(String input) { StringBuffer sb = new StringBuffer(input); char NQ = ' ', quote = NQ; int len = sb.length(); for (int j = 0, lineno = 1; j < len; j++) { if (sb.charAt(j) == '\n') ++lineno;//from w w w. ja v a 2s . c o m if (quote != NQ) { if (sb.charAt(j) == quote) { quote = NQ; } else if (sb.charAt(j) == '\\') { j++; //fix for "123\\\r\n123" if (sb.charAt(j) == '\r') j++; // if(sb.charAt(j) == '\n') j++; } else if (sb.charAt(j) == '\n') { throw new IllegalStateException("Unterminated string at line " + lineno); } } else if (sb.charAt(j) == '/' && j + 1 < len && (sb.charAt(j + 1) == '*' || sb.charAt(j + 1) == '/')) { int l = j; boolean eol = sb.charAt(++j) == '/'; while (++j < len) { if (sb.charAt(j) == '\n') ++lineno; if (eol) { if (sb.charAt(j) == '\n') { sb.delete(l, sb.charAt(j - 1) == '\r' ? j - 1 : j); len = sb.length(); j = l; break; } } else if (sb.charAt(j) == '*' && j + 1 < len && sb.charAt(j + 1) == '/') { sb.delete(l, j + 2); len = sb.length(); j = l; break; } } } else if (sb.charAt(j) == '\'' || sb.charAt(j) == '"') { quote = sb.charAt(j); } else if (sb.charAt(j) == '/') { // regex boolean regex = false; for (int k = j;;) { if (--k < 0) { regex = true; break; } char ck = sb.charAt(k); if (!Character.isWhitespace(ck)) { regex = ck == '(' || ck == ',' || ck == '=' || ck == ':' || ck == '?' || ck == '{' || ck == '[' || ck == ';' || ck == '!' || ck == '&' || ck == '|' || ck == '^' || (ck == 'n' && k > 4 && "return".equals(sb.substring(k - 5, k + 1))) || (ck == 'e' && k > 2 && "case".equals(sb.substring(k - 3, k + 1))); break; } } if (regex) { while (++j < len && sb.charAt(j) != '/') { if (sb.charAt(j) == '\\') j++; else if (sb.charAt(j) == '\n') { throw new IllegalStateException("Unterminated regex at line " + lineno); } } } } } return sb.toString(); }
From source file:com.orientechnologies.orient.jdbc.H2.java
private static void trim(StringBuffer section) { while (section.charAt(section.length() - 1) == SPACE_CHAR) section.deleteCharAt(section.length() - 1); }
From source file:Main.java
public static String join(final ArrayList<String> array, String separator) { StringBuffer result = new StringBuffer(); if (array != null && array.size() > 0) { for (String str : array) { result.append(str);/* w w w . ja va 2s .c o m*/ result.append(separator); } result.delete(result.length() - 1, result.length()); } return result.toString(); }
From source file:net.sf.keystore_explorer.crypto.digest.DigestUtil.java
/** * Get the digest of a message as a formatted String. Returned in base-16 * with ':' separators every two characters padded with a leading 0 if * necessary to make for an even number of hex characters. * * @param message//w w w. java2 s.c om * The message to digest * @param digestType * The message digest algorithm * @return The message digest * @throws CryptoException * If message digester could not be created */ public static String getFriendlyMessageDigest(byte[] message, DigestType digestType) throws CryptoException { byte[] messageDigest = getMessageDigest(message, digestType); StringBuffer strBuff = new StringBuffer(new BigInteger(1, messageDigest).toString(16).toUpperCase()); if ((strBuff.length() % 2) == 1) { strBuff.insert(0, '0'); } if (strBuff.length() > 2) { for (int i = 2; i < strBuff.length(); i += 3) { strBuff.insert(i, ':'); } } return strBuff.toString(); }