List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:org.kafka.event.microaggregator.producer.MicroAggregatorProducer.java
public static String buildEndPoint(String ip, String portNo) { StringBuffer stringBuffer = new StringBuffer(); String[] ips = ip.split(","); String[] ports = portNo.split(","); for (int count = 0; count < ips.length; count++) { if (stringBuffer.length() > 0) { stringBuffer.append(","); }//from w w w . j a v a 2 s. c o m if (count < ports.length) { stringBuffer.append(ips[count] + ":" + ports[count]); } else { stringBuffer.append(ips[count] + ":" + ports[0]); } } return stringBuffer.toString(); }
From source file:com.maverick.http.SocketWithLayeredTransport.java
public static String getExceptionMessageChain(Throwable t) { StringBuffer buf = new StringBuffer(); while (t != null) { if (buf.length() > 0 && !buf.toString().endsWith(".")) { //$NON-NLS-1$ buf.append(". "); //$NON-NLS-1$ }//from w ww . j a va 2 s. c om if (t.getMessage() != null) { buf.append(t.getMessage().trim()); } try { Method m = t.getClass().getMethod("getCause", (Class[]) null); //$NON-NLS-1$ t = (Throwable) m.invoke(t, (Object[]) null); } catch (Throwable ex) { } } return buf.toString(); }
From source file:br.com.cams7.siscom.member.MemberEdit.java
private static String getStringNewLine(StringBuffer sb) { final String STRING_NEW_LINE = "\n"; if (sb.length() > 0) return STRING_NEW_LINE; return STRING_EMPTY; }
From source file:Main.java
private static String getNumericPrefix(String string) { StringBuffer numeric = new StringBuffer(); if (string != null) { string = string.trim();/*from w w w.j a va2s. c o m*/ if (string.length() > 0) { StringBuffer buffer = new StringBuffer(string); char first = buffer.charAt(0); if (Character.isDigit(first)) { numeric.append(first); for (int i = 1; i < buffer.length(); i++) { Character next = buffer.charAt(i); if (Character.isDigit(next)) { numeric.append(next); // skip commas within numbers } else if (next.equals(',')) { continue; } else { break; } } } } } return numeric.length() == 0 ? null : numeric.toString(); }
From source file:misc.TestUtils.java
private static final String removeHashCodes(String toStringValue) { StringBuffer sb = new StringBuffer(toStringValue); for (int monkeyInd = 0; monkeyInd < sb.length();) { int ind = sb.indexOf("@", monkeyInd + 1); if (ind == -1) break; int ind2 = sb.indexOf("[", ind + 1); sb.delete(ind, ind2);// ww w. java 2 s .co m } return sb.toString(); }
From source file:com.linuxbox.enkive.docsearch.indri.IndriQueryComposer.java
/** * Sanitize search term by only allowing letters, digits, and a small subset * of symbols./*from ww w. j a v a 2s .co m*/ * * @param buffer */ protected static void sanitizeStringBuffer(StringBuffer buffer) { for (int i = buffer.length() - 1; i >= 0; i--) { Character c = buffer.charAt(i); if (!Character.isLetterOrDigit(c) && !allowableSymbols.contains(c)) { buffer.deleteCharAt(i); } } }
From source file:Main.java
/** * Generate a unicast MAC address./*from www . ja v a 2 s . co m*/ * A unicast MAC address is the one with an even second hex. * i.e. x[0,2,4,6,8,A,C,E]:xx:xx:xx:xx:xx * * @return Unicast MAC address */ public static String generateRandomMACAddress() { Random r = new Random(); StringBuffer sb = new StringBuffer(); sb.append(Integer.toHexString(r.nextInt(16))); int i = r.nextInt(16); while (i % 2 != 0) i = r.nextInt(16); sb.append(Integer.toHexString(i)); while (sb.length() <= 12) sb.append(Integer.toHexString(r.nextInt())); String address = prepareMACAddress(sb.subSequence(0, 12).toString()); if (address.equals("ff:ff:ff:ff:ff:ff")) return generateRandomMACAddress(); return address; }
From source file:ExecuteSQL.java
/** This utility method is used when printing the table of results */ static void overwrite(StringBuffer b, int pos, String s) { int slen = s.length(); // string length int blen = b.length(); // buffer length if (pos + slen > blen) slen = blen - pos; // does it fit? for (int i = 0; i < slen; i++) // copy string into buffer b.setCharAt(pos + i, s.charAt(i)); }
From source file:org.pgptool.gui.tools.ConsoleExceptionUtils.java
public static String getAllMessages(Throwable t) { if (t == null) return ""; StringBuffer ret = new StringBuffer(); Throwable cur = t;/*from w ww. j a va 2 s . c om*/ while (cur != null) { if (cur == cur.getCause()) break; if (ret.length() > 0) { ret.append(" -> "); } if (cur instanceof FieldValidationException) { FieldValidationException fve = (FieldValidationException) cur; ret.append(buildMessageForFve(fve, LocaleContextHolder.getLocale())); } else if (cur instanceof HasMessageCode) { ret.append(I18nUtils.buildMessage((HasMessageCode) cur, ac())); } else { try { String className = cur.getClass().getName(); String messageMappingForClassName = Messages.get(className, cur.getMessage()); if (className.equals(messageMappingForClassName)) { throw new NoSuchMessageException(className); } ret.append(messageMappingForClassName); } catch (NoSuchMessageException nfe) { ret.append(cur.getLocalizedMessage()); } } cur = cur.getCause(); } return ret.toString(); }
From source file:SystemIDResolver.java
/** * Replace spaces with "%20" and backslashes with forward slashes in * the input string to generate a well-formed URI string. * * @param str The input string/*from w w w . ja v a 2 s.c o m*/ * @return The string after conversion */ private static String replaceChars(String str) { StringBuffer buf = new StringBuffer(str); int length = buf.length(); for (int i = 0; i < length; i++) { char currentChar = buf.charAt(i); // Replace space with "%20" if (currentChar == ' ') { buf.setCharAt(i, '%'); buf.insert(i + 1, "20"); length = length + 2; i = i + 2; } // Replace backslash with forward slash else if (currentChar == '\\') { buf.setCharAt(i, '/'); } } return buf.toString(); }