List of usage examples for java.lang StringBuffer append
@Override public synchronized StringBuffer append(double d)
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); }/*from ww w . jav a 2 s . c o m*/ result.append(tags[tags.length - 1]); return result.toString(); }
From source file:Main.java
public static String toConstantFormat(String str) { int n = str.length(); List<Character> list = new ArrayList<Character>(); char c;/*from ww w. ja va 2 s . c o m*/ for (int i = 0; i < n; i++) { c = str.charAt(i); if (i != 0 && Character.isUpperCase(c)) { list.add('_'); } list.add(Character.toUpperCase(c)); } StringBuffer buffer = new StringBuffer(); for (Character character : list) { buffer.append(character); } return buffer.toString(); }
From source file:com.ibm.watson.catalyst.corpus.tfidf.Template.java
private static StringBuffer makeOr(List<String> aList) { StringBuffer result = new StringBuffer(); result.append("("); Iterator<String> wordsIterator = aList.iterator(); while (wordsIterator.hasNext()) { result.append(wordsIterator.next()); if (wordsIterator.hasNext()) result.append("|"); }//from w ww . ja v a2 s . co m result.append(")"); return result; }
From source file:Main.java
public static String digest(InputStream in) throws Exception { MessageDigest messageDigest = null; XMLInputFactory inputFactory = XMLInputFactory.newFactory(); messageDigest = MessageDigest.getInstance("MD5"); XMLEventReader eventReader = inputFactory.createXMLEventReader(in); while (eventReader.hasNext()) { XMLEvent event = eventReader.nextEvent(); if (event.isStartElement()) { messageDigest.update(event.asStartElement().getName().toString().getBytes()); } else if (event.isEndElement()) { messageDigest.update(event.asEndElement().getName().toString().getBytes()); }/*from w w w.j a v a 2 s . c o m*/ } StringBuffer result = new StringBuffer(); byte[] digest = messageDigest.digest(); for (byte b : digest) { result.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1)); } return result.toString(); }
From source file:Main.java
public static String getTimeString(int seconds) { int ss = seconds % 60; int mm = seconds / 60; int hh = 0;//from www . j a va 2s . com if (mm > 59) { hh = mm / 60; mm %= 60; } StringBuffer buffer = new StringBuffer(8); if (hh < 10) { buffer.append("0"); } buffer.append(hh); buffer.append(":"); if (mm < 10) { buffer.append("0"); } buffer.append(mm); buffer.append(":"); if (ss < 10) { buffer.append("0"); } buffer.append(ss); return buffer.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 va 2 s .co 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
/** * Escape invalid control characters from a text to be included in XML. * String types may contain C0 control characters that are not legal in XML. * This method convert these to the Unicode replacement character 0xFFFD. * //from ww w . j av a 2 s . co m * @param text * the text to be escaped. * @return the escaped text. */ public static String escapeInvalidXmlChars(String text) { StringBuffer ret = new StringBuffer(); for (int i = 0; i < text.length(); i++) { ret.append(escapeChar(text.charAt(i))); } return ret.toString(); }
From source file:Main.java
public static String toString(int X[][]) { StringBuffer res = new StringBuffer("{"); for (int row[] : X) { if (row != X[0]) { res.append(", "); }/*from w w w. j a va2 s .c o m*/ res.append(Arrays.toString(row)); } res.append("}"); return res.toString(); }
From source file:edu.psu.citeseerx.dbcp.DBCPFactory.java
protected static String buildURI(String uri) { StringBuffer buf = new StringBuffer(); buf.append(uri); buf.append("?useUnicode=true&characterEncoding=UTF-8"); buf.append("&autoReconnect=true"); return buf.toString(); }
From source file:Main.java
public static String toString(Throwable error) { StringBuffer buf = new StringBuffer(512); while (error != null) { buf.append(error.getClass().getName()); buf.append(error.getMessage() == null ? "" : error.getMessage()); buf.append("\r\n"); StackTraceElement[] stack = error.getStackTrace(); for (int i = 0; i < stack.length; i++) { buf.append(" "); buf.append(stack[i].toString()); buf.append("\r\n"); }//from www . ja v a2 s . c o m if (error.getCause() != null) { buf.append("\r\nCaused by :"); } error = error.getCause(); } return buf.toString(); }