List of usage examples for java.lang StringBuffer delete
@Override public synchronized StringBuffer delete(int start, int end)
From source file:servletunit.frame2.MockFrame2TestCase.java
/** * Strip ;jsessionid= <sessionid>from path. * @return stripped path/*from www . j ava2 s . c o m*/ */ protected static String stripJSessionID(String inPath) { if (inPath == null) return null; String path = inPath; String pathCopy = path.toLowerCase(); int jsess_idx = pathCopy.indexOf(";jsessionid="); //$NON-NLS-1$ if (jsess_idx > 0) { // Strip jsessionid from obtained path StringBuffer buf = new StringBuffer(path); path = buf.delete(jsess_idx, jsess_idx + 44).toString(); } return path; }
From source file:de.mpg.imeji.presentation.metadata.extractors.BasicExtractor.java
static void displayMetadata(List<String> techMd, Node node, int level) { StringBuffer sb = new StringBuffer(); // print open tag of element indent(techMd, sb, level);/* w ww .jav a2s . c o m*/ sb.append("<" + node.getNodeName()); NamedNodeMap map = node.getAttributes(); if (map != null) { // print attribute values int length = map.getLength(); for (int i = 0; i < length; i++) { Node attr = map.item(i); sb.append(" " + attr.getNodeName() + "=\"" + attr.getNodeValue() + "\""); } } Node child = node.getFirstChild(); if (child == null) { // no children, so close element and return sb.append("/>"); techMd.add(sb.toString()); sb.delete(0, sb.length()); return; } // children, so close current tag sb.append(">"); techMd.add(sb.toString()); sb.delete(0, sb.length()); while (child != null) { // print children recursively displayMetadata(techMd, child, level + 1); child = child.getNextSibling(); } // print close tag of element indent(techMd, sb, level); sb.append("</" + node.getNodeName() + ">"); techMd.add(sb.toString()); sb.delete(0, sb.length()); }
From source file:com.abstratt.mdd.core.util.MDDUtil.java
public static String getArgumentListString(List<? extends TypedElement> argumentList) { StringBuffer name = new StringBuffer("("); for (TypedElement argument : argumentList) { name.append(getTypeName(argument.getType())); addMultiplicity(name, argument); name.append(", "); }//from w w w. j a v a 2 s . c o m if (!argumentList.isEmpty()) name.delete(name.length() - ", ".length(), name.length()); name.append(")"); return name.toString(); }
From source file:com.vmware.bdd.utils.CommonUtil.java
public static String inputsConvert(Set<String> words) { String newWordStr = ""; if (words != null && !words.isEmpty()) { StringBuffer wordsBuff = new StringBuffer(); for (String word : words) { wordsBuff.append(word).append(","); }//www.jav a2s .c o m wordsBuff.delete(wordsBuff.length() - 1, wordsBuff.length()); newWordStr = wordsBuff.toString(); } return newWordStr; }
From source file:util.io.IOUtilities.java
/** * Clears an StringBuffer/*from ww w. j a va2 s . co m*/ * * @param buffer The buffer to clear */ public static void clear(StringBuffer buffer) { buffer.delete(0, buffer.length()); }
From source file:br.org.indt.ndg.common.MD5.java
public static String getMD5FromSurvey(StringBuffer input) throws IOException, NoSuchAlgorithmException { StringBuffer inputMD5 = new StringBuffer(input); // remove XML header String xmlStartFlag = "<?"; String xmlEndFlag = "?>"; int xmlFlagStartPosition = inputMD5.indexOf(xmlStartFlag); int xmlFlagEndPosition = inputMD5.indexOf(xmlEndFlag); if ((xmlFlagStartPosition >= 0) && (xmlFlagEndPosition >= 0)) { inputMD5.delete(xmlFlagStartPosition, xmlFlagEndPosition + xmlEndFlag.length() + 1); }/*from ww w. j ava 2 s . c o m*/ // remove checksum key String checksumFlag = "checksum=\""; int checksumFlagStartPosition = inputMD5.indexOf(checksumFlag) + checksumFlag.length(); int checksumKeySize = 32; inputMD5.replace(checksumFlagStartPosition, checksumFlagStartPosition + checksumKeySize, ""); // we need to remove last '\n' once NDG editor calculates its md5 // checksum without it (both input and inputMD5) if (input.charAt(input.toString().length() - 1) == '\n') { input.deleteCharAt(input.toString().length() - 1); } if (inputMD5.charAt(inputMD5.toString().length() - 1) == '\n') { inputMD5.deleteCharAt(inputMD5.toString().length() - 1); } MessageDigest messageDigest = java.security.MessageDigest.getInstance("MD5"); messageDigest.update(inputMD5.toString().getBytes("UTF-8")); byte[] byteArrayMD5 = messageDigest.digest(); String surveyFileMD5 = getByteArrayAsString(byteArrayMD5); return surveyFileMD5; }
From source file:org.eclipse.jubula.tools.internal.utils.StringParsing.java
/** * Method to split a text with a given delimiter and escapeChar into * a List of Strings/* w ww.j a va 2s. c o m*/ * @param string * String * @param delimeter * char * @param escape * char * @param includeEmptyToken should empty tokens (i.e. <del><del>) * be returned * @return String[] * split text */ public static List<String> splitToList(String string, char delimeter, char escape, boolean includeEmptyToken) { List<String> list = new ArrayList<String>(); if (string == null) { return list; } int length = string.length(); if (length == 0) { list.add(new String()); return list; } // index for list int index = 0; int postIndex = 0; // flag to signalize to escape next char boolean escapeNextChar = false; boolean delimWasLastChar = false; StringBuffer word = new StringBuffer(); while (index < length) { // Escape Recognition postIndex = (index < (string.length() - 1)) ? (index + 1) : index; if (string.charAt(index) == escape && string.charAt(postIndex) == delimeter && !escapeNextChar) { delimWasLastChar = false; escapeNextChar = true; // Delimiter Recognition } else if (string.charAt(index) == delimeter && !escapeNextChar) { if ((word.length() > 0) || includeEmptyToken) { list.add(word.toString()); word.delete(0, word.length()); } delimWasLastChar = true; escapeNextChar = false; // build subString } else { word.append(string.charAt(index)); delimWasLastChar = false; escapeNextChar = false; } index++; } if ((word.length() > 0) || (includeEmptyToken && delimWasLastChar)) { list.add(word.toString()); } return list; }
From source file:org.eclipse.jubula.tools.utils.StringParsing.java
/** * Method to split a text with a given delimeter and escapeChar into * a List of Strings// w ww . j a v a 2 s. co m * @param string * String * @param delimeter * char * @param escape * char * @param includeEmptyToken should empty tokens (i.e. <del><del>) * be returned * @return String[] * Splitted text */ public static List splitToList(String string, char delimeter, char escape, boolean includeEmptyToken) { List list = new ArrayList(); if (string == null) { return list; } int length = string.length(); if (length == 0) { list.add(new String()); return list; } // index for list int index = 0; int postIndex = 0; // flag to signalize to escape next char boolean escapeNextChar = false; boolean delimWasLastChar = false; StringBuffer word = new StringBuffer(); while (index < length) { // Escape Recognition postIndex = (index < (string.length() - 1)) ? (index + 1) : index; if (string.charAt(index) == escape && string.charAt(postIndex) == delimeter && !escapeNextChar) { delimWasLastChar = false; escapeNextChar = true; // Delimeter Recognition } else if (string.charAt(index) == delimeter && !escapeNextChar) { if ((word.length() > 0) || includeEmptyToken) { list.add(word.toString()); word.delete(0, word.length()); } delimWasLastChar = true; escapeNextChar = false; // build subString } else { word.append(string.charAt(index)); delimWasLastChar = false; escapeNextChar = false; } index++; } if ((word.length() > 0) || (includeEmptyToken && delimWasLastChar)) { list.add(word.toString()); } return list; }
From source file:org.rapidcontext.app.plugin.cmdline.CmdLineExecProcedure.java
/** * Analyzes the error output buffer from a process and adds the * relevant log messages//from w w w. j a va 2 s .c o m * * @param cx the procedure call context * @param buffer the process error output buffer */ private static void log(CallContext cx, StringBuffer buffer) { int pos; while ((pos = buffer.indexOf("\n")) >= 0) { String text = buffer.substring(0, pos).trim(); if (text.length() > 0 && text.charAt(0) == '#') { if (cx.getCallStack().height() <= 1) { Matcher m = PROGRESS_PATTERN.matcher(text); if (m.find()) { double progress = Double.parseDouble(m.group(1)); cx.setAttribute(CallContext.ATTRIBUTE_PROGRESS, Double.valueOf(progress)); } } } else { cx.log(buffer.substring(0, pos)); } buffer.delete(0, pos + 1); } }
From source file:com.hangum.tadpole.engine.sql.util.export.HTMLExporter.java
/** * make content file//from w w w. j a v a 2s. c om * * @param tableName * @param rsDAO * @return * @throws Exception */ public static String makeContentFile(String tableName, QueryExecuteResultDTO rsDAO) throws Exception { // full text String strTmpDir = PublicTadpoleDefine.TEMP_DIR + tableName + System.currentTimeMillis() + PublicTadpoleDefine.DIR_SEPARATOR; String strFile = tableName + ".html"; String strFullPath = strTmpDir + strFile; FileUtils.writeStringToFile(new File(strFullPath), HTMLDefine.sbHtml, true); FileUtils.writeStringToFile(new File(strFullPath), "<table class='tg'>", true); // make content List<Map<Integer, Object>> dataList = rsDAO.getDataList().getData(); // column . Map<Integer, String> mapLabelName = rsDAO.getColumnLabelName(); StringBuffer sbHead = new StringBuffer(); sbHead.append(String.format(strHead, "#")); for (int i = 1; i < mapLabelName.size(); i++) { sbHead.append(String.format(strHead, mapLabelName.get(i))); } String strLastColumnName = String.format(strGroup, sbHead.toString()); // header FileUtils.writeStringToFile(new File(strFullPath), strLastColumnName, true); // body start StringBuffer sbBody = new StringBuffer(""); for (int i = 0; i < dataList.size(); i++) { Map<Integer, Object> mapColumns = dataList.get(i); StringBuffer sbTmp = new StringBuffer(); sbTmp.append(String.format(strHead, "" + (i + 1))); //$NON-NLS-1$ for (int j = 1; j < mapColumns.size(); j++) { String strValue = mapColumns.get(j) == null ? "" : "" + mapColumns.get(j); sbTmp.append(String.format(strContent, StringEscapeUtils.unescapeHtml(strValue))); //$NON-NLS-1$ } sbBody.append(String.format(strGroup, sbTmp.toString())); if ((i % DATA_COUNT) == 0) { FileUtils.writeStringToFile(new File(strFullPath), sbBody.toString(), true); sbBody.delete(0, sbBody.length()); } } if (sbBody.length() > 0) { FileUtils.writeStringToFile(new File(strFullPath), sbBody.toString(), true); } FileUtils.writeStringToFile(new File(strFullPath), "</table>", true); return strFullPath; }