List of usage examples for java.lang StringBuilder length
int length();
From source file:com.michellemay.config.ConfigReader.java
/** * Read from an InputStream with given encoding. * * @param inputStream Config input stream. * @param encoding Text encoding in the stream. * * @return New {@link Config} object./*from w w w. j av a 2 s . c o m*/ * * @throws IOException if an error occurs while reading the configuration. */ public static Config read(InputStream inputStream, String encoding) throws IOException { StringBuilder buffer = new StringBuilder(); try (BufferedReader reader = new BufferedReader( new InputStreamReader(inputStream, Charset.forName(encoding)))) { String line; while ((line = reader.readLine()) != null) { if (buffer.length() > 0) { buffer.append(' '); } buffer.append(line); } } return read(buffer.toString()); }
From source file:com.marklogic.contentpump.ContentPump.java
private static void submitJob(Job job) throws Exception { String cpHome = System.getProperty(CONTENTPUMP_HOME_PROPERTY_NAME); // find job jar File cpHomeDir = new File(cpHome); FilenameFilter jobJarFilter = new FilenameFilter() { @Override//from ww w . ja va2 s . c o m public boolean accept(File dir, String name) { if (name.endsWith(".jar") && name.startsWith(CONTENTPUMP_JAR_PREFIX)) { return true; } else { return false; } } }; File[] cpJars = cpHomeDir.listFiles(jobJarFilter); if (cpJars == null || cpJars.length == 0) { throw new RuntimeException("Content Pump jar file " + "is not found under " + cpHome); } if (cpJars.length > 1) { throw new RuntimeException("More than one Content Pump jar file " + "are found under " + cpHome); } // set job jar Configuration conf = job.getConfiguration(); conf.set("mapreduce.job.jar", cpJars[0].toURI().toURL().toString()); // find lib jars FilenameFilter filter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { if (name.endsWith(".jar") && !name.startsWith("hadoop")) { return true; } else { return false; } } }; // set lib jars StringBuilder jars = new StringBuilder(); for (File jar : cpHomeDir.listFiles(filter)) { if (jars.length() > 0) { jars.append(','); } jars.append(jar.toURI().toURL().toString()); } conf.set("tmpjars", jars.toString()); if (LOG.isTraceEnabled()) LOG.trace("LIBJARS:" + jars.toString()); job.waitForCompletion(true); AuditUtil.auditMlcpFinish(conf, job.getJobName(), job.getCounters()); }
From source file:Main.java
public static <E> void print(Collection<E> collections) { StringBuilder builder = new StringBuilder(); for (Iterator<E> iterator = collections.iterator(); iterator.hasNext();) { E e = iterator.next();/*from w ww.j a v a 2 s . c om*/ if (e == null) { builder.append(",null"); } else { builder.append("," + e.toString()); } } System.out.println(builder.substring(1, builder.length())); }
From source file:com.weibo.api.motan.protocol.restful.support.RestfulUtil.java
public static void encodeAttachments(MultivaluedMap<String, Object> headers, Map<String, String> attachments) { if (attachments == null || attachments.isEmpty()) return;/*from ww w . jav a2 s .c o m*/ StringBuilder value = new StringBuilder(); for (Map.Entry<String, String> entry : attachments.entrySet()) { value.append(StringTools.urlEncode(entry.getKey())).append("=") .append(StringTools.urlEncode(entry.getValue())).append(";"); } if (value.length() > 1) value.deleteCharAt(value.length() - 1); headers.add(ATTACHMENT_HEADER, value.toString()); }
From source file:net.solarnetwork.node.runtime.JobUtils.java
/** * Get a setting key for a Trigger./* w w w. j av a 2 s . co m*/ * * <p> * The key is named after these elements, joined with a period character: * </p> * * <ol> * <li>job group (omitted if set to {@link Scheduler#DEFAULT_GROUP})</li> * <li>job name</li> * <li>trigger group (omitted if set to {@link Scheduler#DEFAULT_GROUP})</li> * <li>trigger name</li> * </ol> * * @param t * the trigger to generate the key from * @return the setting key */ public static String triggerKey(Trigger t) { StringBuilder buf = new StringBuilder(); if (t.getJobGroup() != null && !Scheduler.DEFAULT_GROUP.equals(t.getJobGroup())) { buf.append(t.getJobGroup()); } if (t.getJobName() != null) { if (buf.length() > 0) { buf.append('.'); } buf.append(t.getJobName()); } if (t.getGroup() != null && !Scheduler.DEFAULT_GROUP.equals(t.getGroup())) { if (buf.length() > 0) { buf.append('.'); } buf.append(t.getGroup()); } if (buf.length() > 0) { buf.append('.'); } buf.append(t.getName()); return buf.toString(); }
From source file:com.stratio.crossdata.core.utils.ParserUtils.java
/** * Generate the String representation of a set using a separator between elements. * * @param ids The set of ids./*from w w w . j av a 2s. c o m*/ * @param separator The separator between elements. * @return A string representation of the set. */ public static String stringSet(Set<String> ids, String separator) { StringBuilder sb = new StringBuilder(); for (String id : ids) { sb.append(id).append(separator); } return sb.substring(0, sb.length() - separator.length()); }
From source file:com.elogiclab.vosao.plugin.FlickrUtils.java
public static String buildQueryString(Map<String, String> params, String apiSecret) { StringBuilder result = new StringBuilder(); StringBuffer unencoded = new StringBuffer(apiSecret); List keyList = new ArrayList(params.keySet()); Collections.sort(keyList);/*from w ww . j av a2 s.c o m*/ Iterator it = keyList.iterator(); while (it.hasNext()) { if (result.length() > 0) { result.append("&"); } String key = it.next().toString(); result.append(key); result.append("="); result.append(params.get(key)); unencoded.append(key); unencoded.append(params.get(key)); } System.out.println(unencoded); String sig = digest(unencoded.toString()); result.append("&api_sig="); result.append(sig); return result.toString(); }
From source file:ext.sns.util.AuthUtil.java
/** * ?state?state????/*from w w w. j a va2 s .c o m*/ * * @param params ? * @return ?state? */ public static String encodeState(Map<String, String> params) { String state = null; try { StringBuilder stateBuilder = new StringBuilder(); for (Map.Entry<String, String> e : params.entrySet()) { stateBuilder.append(URLEncoder.encode(e.getKey(), "utf-8")).append('&'); stateBuilder.append(URLEncoder.encode(e.getValue(), "utf-8")).append('&'); } if (stateBuilder.length() > 0) { stateBuilder.deleteCharAt(stateBuilder.length() - 1); } state = URLEncoder.encode(stateBuilder.toString(), "utf-8").replace('%', '_'); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } return state; }
From source file:ch.digitalfondue.jfiveparse.TreeConstructionTest.java
static String renderDocument(Document document) { StringBuilder sb = new StringBuilder(); for (Node node : document.getChildNodes()) { renderNode(node, 0, sb);//from w ww . jav a 2s . co m } return sb.deleteCharAt(sb.length() - 1).toString(); }
From source file:com.pinterest.deployservice.common.ChangeFeedJob.java
private static String toStringRepresentation(Object object) throws IllegalAccessException { if (object == null) { return "None"; }/*from w w w . jav a2 s .c o m*/ if (object instanceof List) { List<?> list = (List<?>) object; if (list.isEmpty()) { return "[]"; } StringBuilder sb = new StringBuilder("["); for (Object element : list) { sb.append(toStringRepresentation(element)); sb.append(", "); } sb.delete(sb.length() - 2, sb.length()); sb.append(']'); return sb.toString(); } Field[] fields = object.getClass().getDeclaredFields(); if (fields.length == 0) { return "{}"; } StringBuilder sb = new StringBuilder("{"); for (Field field : fields) { field.setAccessible(true); Object fieldItem = field.get(object); sb.append(field.getName()); sb.append(":"); sb.append(fieldItem); sb.append(", "); } sb.delete(sb.length() - 2, sb.length()); sb.append('}'); return sb.toString(); }