List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:com.fantasia.snakerflow.engine.SnakerHelper.java
public static String getActiveJson(List<Task> tasks) { StringBuffer buffer = new StringBuffer(); buffer.append("{'activeRects':{'rects':["); for (Task task : tasks) { buffer.append("{'paths':[],'name':'"); buffer.append(task.getTaskName()); buffer.append("'},"); }//from w ww .j a v a2s.c o m buffer.deleteCharAt(buffer.length() - 1); buffer.append("]}}"); buffer.append(""); buffer.append(""); return buffer.toString(); }
From source file:ca.on.oicr.pde.deciders.GenomicAlignmentNovoalignDecider.java
public static String _join(String separator, Set items) { StringBuffer result = new StringBuffer(); Iterator myItems = items.iterator(); while (myItems.hasNext()) { if (result.length() > 0) { result.append(separator);/*from w ww . j a v a 2 s . c o m*/ } result.append(myItems.next().toString()); } return result.toString(); }
From source file:com.googlecode.jtiger.modules.ecside.util.ExtremeUtils.java
/** * Take a map of parameter key/value pairs and create * a URI query string out of it.//from ww w. j a v a 2s. c o m */ public static String getQueryString(Map parameterMap) { StringBuffer results = new StringBuffer(); Iterator iterator = parameterMap.keySet().iterator(); for (Iterator iter = iterator; iter.hasNext();) { String key = (String) iter.next(); String value[] = (String[]) parameterMap.get(key); if (results.length() == 0) { results.append("?"); } else { results.append("&"); } results.append(key + "="); if (value != null && value.length > 0) { results.append(value[0]); } } return results.toString(); }
From source file:com.stratuscom.harvester.codebase.ClassServer.java
/** * Read up to CRLF, return false if EOF/*from w ww.ja v a2s .c om*/ */ private static boolean readLine(InputStream in, StringBuffer buf) throws IOException { while (true) { int c = in.read(); if (c < 0) { return buf.length() > 0; } /* * The characters below are part of the http protocol and not * localizable, so we're OK with character literals. */ if (c == '\r') { in.mark(1); c = in.read(); if (c != '\n') { in.reset(); } return true; } if (c == '\n') { return true; } buf.append((char) c); } }
From source file:com.ultrapower.eoms.common.plugin.ecside.util.ExtremeUtils.java
/** * Take a map of parameter key/value pairs and create * a URI query string out of it./*w ww .jav a2s. com*/ */ public static String getQueryString(Map parameterMap) { StringBuffer results = new StringBuffer(); Iterator iterator = parameterMap.keySet().iterator(); for (Iterator iter = iterator; iter.hasNext();) { String key = (String) iter.next(); String value[] = (String[]) parameterMap.get(key); if (results.length() == 0) { results.append("?"); } else { results.append("&"); } results.append(key + "="); if (value != null && value.length > 0) { results.append(value[0]); } } return results.toString(); }
From source file:info.evanchik.eclipse.karaf.core.KarafCorePluginUtils.java
/** * Implementation of join using a {@link StringBuffer} * * @param items/*from w w w . jav a2s.c o m*/ * the {@link Collection} of items that will be joined together * @param glue * the string to act as glue in the concatenation * @return the concatenation of the specified items */ public static String join(final Collection<? extends Object> items, final String glue) { final StringBuffer buffer = new StringBuffer(); for (final Object o : items) { if (buffer.length() > 0) { buffer.append(glue); } buffer.append(o.toString()); } return buffer.toString(); }
From source file:com.stratuscom.harvester.codebase.ClassServer.java
/** * Read the request/response and return the initial line. *//*from www . j a v a2s .c o m*/ private static String getInput(Socket sock, boolean isRequest) throws IOException { BufferedInputStream in = new BufferedInputStream(sock.getInputStream(), 256); StringBuffer buf = new StringBuffer(80); do { if (!readLine(in, buf)) { return null; } } while (isRequest && buf.length() == 0); String initial = buf.toString(); do { buf.setLength(0); } while (readLine(in, buf) && buf.length() > 0); return initial; }
From source file:com.sina.cloudstorage.util.HttpUtils.java
/** * Creates an encoded query string from all the parameters in the specified * request./* w w w. j ava 2 s. c o m*/ * * @param request * The request containing the parameters to encode. * * @return Null if no parameters were present, otherwise the encoded query * string for the parameters present in the specified request. */ public static String encodeParameters(Request<?> request) { StringBuffer encodedParams = new StringBuffer(); if (request.getParameters().size() > 0) { for (Entry<String, String> entry : request.getParameters().entrySet()) { final String encodedName = encode(entry.getKey(), DEFAULT_ENCODING); final String encodedValue = encode(entry.getValue(), DEFAULT_ENCODING); if (encodedParams.length() > 0) { encodedParams.append(PARAMETER_SEPARATOR); } encodedParams.append(encodedName); if (encodedValue != null) { encodedParams.append(NAME_VALUE_SEPARATOR); encodedParams.append(encodedValue); } } } return encodedParams.toString(); }
From source file:com.edgenius.wiki.render.MarkupUtil.java
/** * @param sb// w w w .j a v a 2 s. co m * @param slash * @return */ private static boolean processDoubleSlash(StringBuffer sb, int slash) { int currLen; boolean odd = slash % 2 != 0; if (slash > 1) { //if the string is like "\\\", then retrieve back from second last slash and convert double slash "\\" to single escape. //the last slash will handle in below currLen = sb.length(); //for easy programming. delete all slash here, then append last slash after all double slash converted to HTML entity. for (int sidx = 1; sidx <= slash; sidx++) { sb.deleteCharAt(currLen - sidx); } //see how many double slash int doubleSlashCount = slash / 2; for (int sidx = 0; sidx < doubleSlashCount; sidx++) { //replace escaped slash to \ sb.append(ENTITY_SLASH); } if (odd) sb.append("\\"); } return odd; }
From source file:com.vertica.hadoop.VerticaOutputFormat.java
public static void checkOutputSpecs(VerticaConfiguration vtconfig) throws IOException { Relation vTable = new Relation(vtconfig.getOutputTableName()); if (vTable.isNull()) throw new IOException("Vertica output requires a table name defined by " + VerticaConfiguration.OUTPUT_TABLE_NAME_PROP); String[] def = vtconfig.getOutputTableDef(); boolean dropTable = vtconfig.getDropTable(); Statement stmt = null;//from w w w. j a v a 2 s . c o m try { Connection conn = vtconfig.getConnection(true); DatabaseMetaData dbmd = conn.getMetaData(); ResultSet rs = dbmd.getTables(null, vTable.getSchema(), vTable.getTable(), null); boolean tableExists = rs.next(); stmt = conn.createStatement(); if (tableExists && dropTable) { stmt = conn.createStatement(); stmt.execute("TRUNCATE TABLE " + vTable.getQualifiedName().toString()); } // create table if it doesn't exist if (!tableExists) { if (def == null) throw new RuntimeException("Table " + vTable.getQualifiedName().toString() + " does not exist and no table definition provided"); if (!vTable.isDefaultSchema()) { stmt.execute("CREATE SCHEMA IF NOT EXISTS " + vTable.getSchema()); } StringBuffer tabledef = new StringBuffer("CREATE TABLE ") .append(vTable.getQualifiedName().toString()).append(" ("); for (String column : def) tabledef.append(column).append(","); tabledef.replace(tabledef.length() - 1, tabledef.length(), ")"); stmt.execute(tabledef.toString()); } } catch (Exception e) { throw new RuntimeException(e); } finally { if (stmt != null) try { stmt.close(); } catch (SQLException e) { throw new RuntimeException(e); } } }