List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:com.mycomm.dao.mydao.base.MyDaoSupport.java
/** * order by?/*from w ww . j a v a 2 s .c o m*/ * * @param orderby * @return */ protected static String buildOrderby(LinkedHashMap<String, String> orderby) { StringBuffer orderbyql = new StringBuffer(""); if (orderby != null && orderby.size() > 0) { orderbyql.append(" order by "); for (String key : orderby.keySet()) { orderbyql.append("o.").append(key).append(" ").append(orderby.get(key)).append(","); } orderbyql.deleteCharAt(orderbyql.length() - 1); } return orderbyql.toString(); }
From source file:IndexService.IndexMR.java
public static RunningJob run(Configuration conf2, String inputfiles, boolean column, String ids, String outputdir) {/*w ww . j a v a 2 s .c o m*/ if (inputfiles == null || outputdir == null) return null; JobConf conf = new JobConf(conf2); conf.setJobName("IndexMR:\t" + ids); conf.setJarByClass(IndexMR.class); FileSystem fs = null; try { fs = FileSystem.get(conf); fs.delete(new Path(outputdir), true); } catch (IOException e3) { e3.printStackTrace(); } conf.set("index.ids", ids); if (column) { conf.set("datafiletype", "column"); } else { conf.set("datafiletype", "format"); } String[] ifs = inputfiles.split(","); long wholerecnum = 0; String[] idxs = ids.split(","); String[] fieldStrings = new String[idxs.length + 2]; if (!column) { IFormatDataFile ifdf; try { ifdf = new IFormatDataFile(conf); ifdf.open(ifs[0]); for (int i = 0; i < idxs.length; i++) { int id = Integer.parseInt(idxs[i]); byte type = ifdf.fileInfo().head().fieldMap().fieldtypes().get(id).type(); fieldStrings[i] = type + ConstVar.RecordSplit + i; } ifdf.close(); } catch (IOException e) { e.printStackTrace(); } } else { try { IColumnDataFile icdf = new IColumnDataFile(conf); icdf.open(ifs[0]); for (int i = 0; i < idxs.length; i++) { int id = Integer.parseInt(idxs[i]); byte type = icdf.fieldtypes().get(id).type(); fieldStrings[i] = type + ConstVar.RecordSplit + i; } icdf.close(); } catch (IOException e) { e.printStackTrace(); } } fieldStrings[fieldStrings.length - 2] = ConstVar.FieldType_Short + ConstVar.RecordSplit + (fieldStrings.length - 2); fieldStrings[fieldStrings.length - 1] = ConstVar.FieldType_Int + ConstVar.RecordSplit + (fieldStrings.length - 1); conf.setStrings(ConstVar.HD_fieldMap, fieldStrings); if (!column) { conf.set(ConstVar.HD_index_filemap, inputfiles); for (String file : ifs) { IFormatDataFile fff; try { fff = new IFormatDataFile(conf); fff.open(file); wholerecnum += fff.segIndex().recnum(); fff.close(); } catch (IOException e) { e.printStackTrace(); } } } else { HashSet<String> files = new HashSet<String>(); for (String file : ifs) { files.add(file); } StringBuffer sb = new StringBuffer(); for (String str : files) { sb.append(str).append(","); } conf.set(ConstVar.HD_index_filemap, sb.substring(0, sb.length() - 1)); for (String file : files) { Path parent = new Path(file).getParent(); try { FileStatus[] fss = fs.listStatus(parent); String openfile = ""; for (FileStatus status : fss) { if (status.getPath().toString().contains(file)) { openfile = status.getPath().toString(); break; } } IFormatDataFile fff = new IFormatDataFile(conf); fff.open(openfile); wholerecnum += fff.segIndex().recnum(); fff.close(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } } conf.setNumReduceTasks((int) ((wholerecnum - 1) / (100000000) + 1)); FileInputFormat.setInputPaths(conf, inputfiles); Path outputPath = new Path(outputdir); FileOutputFormat.setOutputPath(conf, outputPath); conf.setOutputKeyClass(IndexKey.class); conf.setOutputValueClass(IndexValue.class); conf.setPartitionerClass(IndexPartitioner.class); conf.setMapperClass(IndexMap.class); conf.setCombinerClass(IndexReduce.class); conf.setReducerClass(IndexReduce.class); if (column) { conf.setInputFormat(IColumnInputFormat.class); } else { conf.setInputFormat(IFormatInputFormat.class); } conf.setOutputFormat(IndexIFormatOutputFormat.class); try { JobClient jc = new JobClient(conf); return jc.submitJob(conf); } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static String getValue(Element el) { if (el != null) { NodeList nodes = el.getChildNodes(); StringBuffer sb = new StringBuffer(); // String s; int length = nodes.getLength(); for (int i = 0; i < length; ++i) { Node node = nodes.item(i); String s = null;/* ww w.j a v a 2s. com*/ s = node.getNodeValue(); // System.out.println("XMLUtil.getValue: s=" + s); if (s != null) sb.append(s.trim()); } if (sb.length() > 0) { if (debug) { System.out.println("XMLUtil.getValue: sb=" + sb.toString()); } return sb.toString(); } } return null; }
From source file:arena.cron.CronUtils.java
/** * Take a single cron token, and remove any duplicates, modulus on max value, etc. Basically * clean it up and make it legal/*from www . ja va 2s.c om*/ */ protected static String formatCronPatternToken(String token, int minValue, int maxValue) { // Break on commas String splitOnCommas[] = splitOnCommas(token); for (int n = 0; n < splitOnCommas.length; n++) { splitOnCommas[n] = splitOnCommas[n].trim(); if (splitOnCommas[n].equals(STAR)) { return STAR; } int parsed = Integer.parseInt(splitOnCommas[n]); if (parsed < minValue) { LogFactory.getLog(CronUtils.class).warn("Skipping cron pattern element " + splitOnCommas[n] + " - should be between " + minValue + " and " + maxValue); } else if (parsed > maxValue) { parsed = ((parsed - minValue) % (maxValue + 1 - minValue)) + minValue; } splitOnCommas[n] = Integer.toString(parsed); } Arrays.sort(splitOnCommas, new Comparator<String>() { public int compare(String one, String two) { return Integer.valueOf(one).compareTo(Integer.valueOf(two)); } }); StringBuffer out = new StringBuffer(); for (int n = 0; n < splitOnCommas.length; n++) { if ((n == 0) || !splitOnCommas[n].equals(splitOnCommas[n - 1])) { out.append(splitOnCommas[n]).append(","); } } return out.length() > 0 ? out.substring(0, out.length() - 1) : STAR; }
From source file:acp.sdk.SDKUtil.java
/** * Map???Keyascii???key1=value1&key2=value2? ????signature * /*www . j av a 2 s.c o m*/ * @param data * Map? * @return ? */ public static String coverMap2String(Map<String, String> data) { TreeMap<String, String> tree = new TreeMap<String, String>(); Iterator<Entry<String, String>> it = data.entrySet().iterator(); while (it.hasNext()) { Entry<String, String> en = it.next(); if (SDKConstants.param_signature.equals(en.getKey().trim())) { continue; } tree.put(en.getKey(), en.getValue()); } it = tree.entrySet().iterator(); StringBuffer sf = new StringBuffer(); while (it.hasNext()) { Entry<String, String> en = it.next(); sf.append(en.getKey() + SDKConstants.EQUAL + en.getValue() + SDKConstants.AMPERSAND); } return sf.substring(0, sf.length() - 1); }
From source file:edu.internet2.middleware.openid.message.encoding.EncodingUtils.java
/** * Append the URL encoded OpenID message parameters to the query string of the provided URI. * /*from w w w .j a v a2 s .com*/ * @param uri URI to append OpenID message parameter to * @param message URL encoded OpenID message parameters * @return URI with message parameters appended */ public static URI appendMessageParameters(URI uri, String message) { if (uri == null || message == null) { return uri; } // build new query string StringBuffer queryBuffer = new StringBuffer(); if (uri.getRawQuery() != null) { queryBuffer.append(uri.getRawQuery()); } if (queryBuffer.length() > 0 && queryBuffer.charAt(queryBuffer.length() - 1) != '&') { queryBuffer.append('&'); } queryBuffer.append(message); try { return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), queryBuffer.toString(), uri.getFragment()); } catch (URISyntaxException e) { log.error("Unable to append message parameters to URI: {}", e); } return null; }
From source file:ch.entwine.weblounge.common.url.PathUtils.java
/** * Concatenates the path elements with respect to leading and trailing * slashes. The path will always end with a trailing slash. * /*from w w w . j a v a 2 s. c o m*/ * @param pathElements * the path elements * @return the concatenated url of the two arguments * @throws IllegalArgumentException * if less than two path elements are provided */ public static String concat(String... pathElements) throws IllegalArgumentException { if (pathElements == null || pathElements.length < 1) throw new IllegalArgumentException("Prefix cannot be null or empty"); if (pathElements.length < 2) throw new IllegalArgumentException("Suffix cannot be null or empty"); StringBuffer b = new StringBuffer(); for (String s : pathElements) { if (StringUtils.isBlank(s)) throw new IllegalArgumentException("Path element cannot be null"); String element = adjustSeparator(s); element = removeDoubleSeparator(element); element = cleanSpecializedCharacter(element); if (b.length() == 0) { b.append(element); } else if (b.lastIndexOf(File.separator) < b.length() - 1 && !element.startsWith(File.separator)) { b.append(File.separator).append(element); } else if (b.lastIndexOf(File.separator) == b.length() - 1 && element.startsWith(File.separator)) { b.append(element.substring(1)); } else { b.append(element); } } return b.toString(); }
From source file:com.facebook.infrastructure.utils.FBUtilities.java
public static String getCurrentThreadStackTrace() { Throwable throwable = new Throwable(); StackTraceElement[] ste = throwable.getStackTrace(); StringBuffer sbuf = new StringBuffer(); for (int i = ste.length - 1; i > 0; --i) { sbuf.append(ste[i].getClassName() + "." + ste[i].getMethodName()); sbuf.append("/"); }/*from w ww. ja v a 2 s. co m*/ sbuf.deleteCharAt(sbuf.length() - 1); return sbuf.toString(); }
From source file:TextUtilities.java
/** * <P>Returns a substring of the given StringBuffer's string which consists of * the characters from the beginning of it until the first occurrence of the * given delimiter string or if the delimiter doesn't occur, until the end * of the string. The StringBuffer is modified so it no longer contains those * characters or the delimiter.//from w w w. j av a 2 s.co m * <P>Examples: * <UL> * <LI>nextToken(new StringBuffer("abcdefgh"), "de") returns "abc" and * the StringBuffer is modified to represent the string "fgh". * <LI>nextToken(new StringBuffer("abcdefgh"), "a") returns an empty string * and the StringBuffer is modified to represent the string "bcdefgh". * <LI>nextToken(new StringBuffer("abcdefgh"), "k") returns "abcdefgh" and * the StringBuffer is modified to represent an empty string. * </UL> */ public static String nextToken(StringBuffer buf, String delimiter) { String bufStr = buf.toString(); int delimIndex = bufStr.indexOf(delimiter); if (delimIndex == -1) { buf.setLength(0); return bufStr; } String str = bufStr.substring(0, delimIndex); buf.reverse(); buf.setLength(buf.length() - delimIndex - delimiter.length()); buf.reverse(); return str; }
From source file:com.liusoft.dlog4j.search.SearchProxy.java
/** * //from w w w . j a va 2 s. c om * @param obj * @param field * @param value * @throws IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException * @throws IntrospectionException * @throws InstantiationException */ private static void setNestedProperty(Object obj, String field, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, IntrospectionException, InstantiationException { StringTokenizer st = new StringTokenizer(field, "."); Class nodeClass = obj.getClass(); StringBuffer tmp_prop = new StringBuffer(); while (st.hasMoreElements()) { String f = st.nextToken(); if (tmp_prop.length() > 0) tmp_prop.append('.'); tmp_prop.append(f); PropertyDescriptor[] props = Introspector.getBeanInfo(nodeClass).getPropertyDescriptors(); for (int i = 0; i < props.length; i++) { if (props[i].getName().equals(f)) { if (PropertyUtils.getNestedProperty(obj, tmp_prop.toString()) == null) { nodeClass = props[i].getPropertyType(); PropertyUtils.setNestedProperty(obj, f, nodeClass.newInstance()); } continue; } } } PropertyUtils.setNestedProperty(obj, field, value); }