List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:Main.java
private static void addExports(Attributes attributes, BundleDescription compositeDesc, ExportPackageDescription[] matchingExports) { if (matchingExports.length == 0) return;//from ww w.j a v a 2 s . co m StringBuffer exportStatement = new StringBuffer(); for (int i = 0; i < matchingExports.length; i++) { if (matchingExports[i].getExporter() == compositeDesc) { // the matching export from outside is the composite bundle itself // this must be one of our own substitutable exports, it must be ignored (bug 345640) continue; } if (exportStatement.length() > 0) exportStatement.append(','); getExportFrom(matchingExports[i], exportStatement); } if (exportStatement.length() > 0) attributes.putValue(Constants.EXPORT_PACKAGE, exportStatement.toString()); }
From source file:com.edgenius.wiki.render.MarkupUtil.java
/** * Add slash "\" before any markup keyword. The reverse method is escapeMarkupToEntity(); * //from w w w .j a v a 2s . com * OK, this method looks complicated now(2009/05/05). Because input escText may include some uniqueKey, which is replacement of HTML tag. * These uniqueKey won't be calculated into leadNonWord or endNonWord,i.e., not as border. For example, * * my text uniqueK[text]uniqueK has key. (Originally, this text looks like "my text <p>[text]</p> has key.", P tag is replace into uniqueK) * * Markup [text] won't be treat as surrounding by 'K' and 'u'. It will be ' '. So the second parameter of this method, skippedTagKey, * will be skipped during processing. * * @param escText * @return */ public static String escapeMarkupToSlash(String escText, String skippedTagKey) { //plus "\" as it is keyword for escape if (StringUtils.isBlank(escText)) return escText; StringBuffer sb = new StringBuffer(); int len = escText.length(); //use \n as first start, means text start. char lastCh = '\n'; //text start, leadNonWord is true boolean leadNonWord = true; boolean endNonWord = true; char[] skipped = (skippedTagKey == null || skippedTagKey.length() == 0) ? null : skippedTagKey.toCharArray(); for (int idx = 0; idx < len; idx++) { if (skipped != null) { //try to see if the following piece of string is skipped key or not. //if it is skipped key, then just append key to result and continue. StringBuffer skipBuf = skipKey(escText, idx, skipped); if (skipBuf != null) { sb.append(skipBuf); idx += skipBuf.length() - 1; continue; } } char ch = escText.charAt(idx); if (StringUtils.contains(FilterRegxConstants.FILTER_ANYTEXT_KEYWORD, ch)) { sb.append("\\").append(ch); } else if (leadNonWord && StringUtils.contains(FilterRegxConstants.FILTER_SURR_NON_WORD_KEYWORD, ch)) { sb.append("\\").append(ch); } else if (lastCh == '\n' && StringUtils.contains(FilterRegxConstants.FILTER_ONLYLINESTART_KEYWORD, ch)) { sb.append("\\").append(ch); } else { //check if this char is tailed by non-word character //assume ch is last char, endNonWord is true then if (StringUtils.contains(FilterRegxConstants.FILTER_SURR_NON_WORD_KEYWORD, ch)) { endNonWord = true; StringBuffer skipBuf = null; if (idx < len - 1) { //get next char to check if this non-word if (skipped != null) { skipBuf = skipKey(escText, idx + 1, skipped); if (skipBuf != null) { idx += skipBuf.length(); } } //need check idx again as it modified if skipBuf is not empty if (idx < len - 1) { char nextCh = escText.charAt(idx + 1); endNonWord = FilterRegxConstants.NON_WORD_PATTERN .matcher(Character.valueOf(nextCh).toString()).matches(); } } if (endNonWord) { sb.append("\\").append(ch); } else { sb.append(ch); } if (skipBuf != null) sb.append(skipBuf); } else { sb.append(ch); } } leadNonWord = FilterRegxConstants.NON_WORD_PATTERN.matcher(Character.valueOf(ch).toString()).matches(); lastCh = ch; } //next line is very rough escape, now replace by above exact escape //EscapeUtil.escapeBySlash(escText,(FilterRegxConstants.FILTER_KEYWORD+"\\").toCharArray()); return sb.toString(); }
From source file:edu.umd.cs.marmoset.utilities.MarmosetUtilities.java
public static String commandToString(List<String> args) { StringBuffer buf = new StringBuffer(); for (Iterator<String> i = args.iterator(); i.hasNext();) { String arg = i.next();/* www . j av a2 s . co m*/ if (buf.length() > 0) buf.append(' '); buf.append(arg); } return buf.toString(); }
From source file:com.qpark.maven.plugin.flowmapper.AbstractGenerator.java
public static String toJavadocHeader(final String documentation) { final int lenght = 77; String s = documentation.replaceAll("\\t", " ").replaceAll("\\n", " ").replaceAll("( )+", " "); final StringBuffer sb = new StringBuffer(); while (s.length() > 0) { final int index = s.substring(0, Math.min(lenght, s.length())).lastIndexOf(' '); if (s.length() < lenght || index < 0) { if (sb.length() > 0) { sb.append("\n * "); }//from ww w. j a va 2 s. co m sb.append(s.trim()); s = ""; } else { if (index > 0) { sb.append("\n * "); sb.append(s.substring(0, index).trim()); s = s.substring(index + 1, s.length()); } } } s = sb.toString().trim(); if (s.length() > 0 && s.charAt(s.length() - 1) != '.') { sb.append(".\n"); } else { sb.append("\n"); } s = sb.toString(); if (s.charAt(0) == '\'') { sb.replace(0, 1, ""); } return sb.toString(); }
From source file:com.roncoo.utils.MerchantApiUtil.java
/** * ????/*from w w w .ja va 2 s .co m*/ * @param paramMap ??? * @param paySecret ?? * @return */ public static String getSign(Map<String, Object> paramMap, String paySecret) { SortedMap<String, Object> smap = new TreeMap<String, Object>(paramMap); StringBuffer stringBuffer = new StringBuffer(); for (Map.Entry<String, Object> m : smap.entrySet()) { Object value = m.getValue(); if (value != null && StringUtils.isNotBlank(String.valueOf(value))) { stringBuffer.append(m.getKey()).append("=").append(m.getValue()).append("&"); } } stringBuffer.delete(stringBuffer.length() - 1, stringBuffer.length()); String argPreSign = stringBuffer.append("&paySecret=").append(paySecret).toString(); String signStr = MD5Util.encode(argPreSign).toUpperCase(); return signStr; }
From source file:crow.util.Util.java
/** * ??//from www. j av a 2 s .c o m * * @param postParams * @param splitter * @param quot * @return */ public static String encodeParameters(List<PostParameter> postParams, String splitter, boolean quot) { StringBuffer buf = new StringBuffer(); for (PostParameter param : postParams) { if (buf.length() != 0) { if (quot) { buf.append("\""); } buf.append(splitter); } buf.append(encode(param.getName())).append("="); if (quot) { buf.append("\""); } buf.append(encode(param.getValue())); } if (buf.length() != 0) { if (quot) { buf.append("\""); } } return buf.toString(); }
From source file:com.nloko.android.Utils.java
public static String getMd5Hash(byte[] input) { if (input == null) { throw new IllegalArgumentException("input"); }/*from ww w . j a va2s .c o m*/ try { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] messageDigest = md.digest(input); BigInteger number = new BigInteger(1, messageDigest); //String md5 = number.toString(16); StringBuffer md5 = new StringBuffer(); md5.append(number.toString(16)); while (md5.length() < 32) { //md5 = "0" + md5; md5.insert(0, "0"); } return md5.toString(); } catch (NoSuchAlgorithmException e) { Log.e("MD5", e.getMessage()); return null; } }
From source file:com.panet.imeta.core.util.StringUtil.java
/** * Check if the stringBuffer supplied is empty. A StringBuffer is empty when * it is null or when the length is 0/*from w ww . j a v a 2 s. com*/ * * @param string * The stringBuffer to check * @return true if the stringBuffer supplied is empty */ public static final boolean isEmpty(StringBuffer string) { return string == null || string.length() == 0; }
From source file:Main.IrcBot.java
public static void postRequest(String pasteCode, PrintWriter out) { try {/* ww w . jav a 2 s. c om*/ String url = "http://pastebin.com/raw.php?i=" + pasteCode; URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); //add reuqest header con.setRequestMethod("POST"); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); String urlParameters = ""; // Send post request con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); System.out.println("\nSending 'POST' request to URL : " + url); System.out.println("Post parameters : " + urlParameters); System.out.println("Response Code : " + responseCode); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine + "\n"); } in.close(); //print result System.out.println(response.toString()); if (response.length() > 0) { IrcBot.postGit(response.toString(), out); } else { out.println("PRIVMSG #learnprogramming :The PasteBin URL is not valid."); } } catch (Exception p) { } }
From source file:com.boyuanitsm.pay.unionpay.util.SDKUtil.java
/** * Map???Keyascii???key1=value1&key2=value2? ????signature * /*from w ww . j av a2s . c om*/ * @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); } if (sf.length() == 0) { return ""; } return sf.substring(0, sf.length() - 1); }