List of usage examples for java.lang StringBuffer delete
@Override public synchronized StringBuffer delete(int start, int end)
From source file:org.lobid.lodmill.OaiDcEncoder.java
@Override public void startRecord(final String id) { final StringBuffer buffer = writer.getBuffer(); buffer.delete(0, buffer.length()); writer.write(xmlPraeambel);/*from w ww. j a va 2s .c om*/ }
From source file:org.jboss.drools.guvnor.importgenerator.PackageFile.java
/** * returns "approval.determine" where path is /home/mallen/workspace/rules/approval/determine/1.0.0.SNAPSHOT/file.xls * and options "start" is "rules" and end is "[0-9|.]*[SNAPSHOT]+[0-9|.]*" ie. any number, dot and word SNAPSHOT * * @param directory// w w w. jav a 2 s. co m * @param options * @return */ private static String getPackageName(File directory, CmdArgsParser options) { String startPath = directory.getPath(); Matcher m = Pattern.compile("([^/|\\\\]+)").matcher(startPath); // quad-backslash is for windows paths List<String> lpath = new ArrayList<String>(); while (m.find()) lpath.add(m.group()); String[] path = lpath.toArray(new String[lpath.size()]); StringBuffer sb = new StringBuffer(); for (int i = path.length - 1; i >= 0; i--) { String dir = path[i]; if ((dir.matches(options.getOption(Parameters.OPTIONS_PACKAGE_EXCLUDE)))) continue; if ((dir.equals(options.getOption(Parameters.OPTIONS_PACKAGE_START)))) break; //since we are working in reverse, it's time to exit sb.insert(0, PACKAGE_DELIMETER).insert(0, dir); } if (sb.substring(sb.length() - 1).equals(PACKAGE_DELIMETER)) sb.delete(sb.length() - 1, sb.length()); return sb.toString(); }
From source file:com.vmware.bdd.utils.CommonUtil.java
public static void prettyOutputStrings(List<Object> objs, String fileName, String delimeter) throws Exception { StringBuffer buff = new StringBuffer(); if (isBlank(delimeter)) { delimeter = System.lineSeparator(); }/*from www. ja va2 s . c o m*/ for (Object obj : objs) { if (obj != null) { String str = obj.toString(); if (!isBlank(str)) { buff.append(str).append(delimeter); } } } if (buff.length() > 0) { buff.delete(buff.length() - delimeter.length(), buff.length()); } OutputStream out = null; BufferedWriter bw = null; try { if (!isBlank(fileName)) { out = new FileOutputStream(fileName); } else { out = System.out; } bw = new BufferedWriter(new OutputStreamWriter(out, "UTF-8")); bw.write(buff.toString()); if (!isBlank(fileName)) { // [Bug 1406542] always append a newline at the end of the file bw.newLine(); } bw.flush(); } finally { if (bw != null && out != null && !(out instanceof PrintStream)) { bw.close(); out.close(); } } }
From source file:org.guzz.util.PropertyUtil.java
/** * JDK Properties?Key??. <BR>//from ww w . j av a 2 s .c o m * JDK PropertiestoString()key??, ?, ??. * @param props JDK Properties * @param keyPrefix key? * @return Properties?Key???. */ public static String toString(Properties props, String keyPrefix) { if (props == null || keyPrefix == null) { return "null! keyPrefix=" + keyPrefix; } final String delit = ", "; final int delitLen = delit.length(); StringBuffer sb = new StringBuffer(64); sb.append('{'); // ??()Key?. JDK // Hashtable(Properties)toString. synchronized (props) { int max = props.size() - 1; Iterator it = props.entrySet().iterator(); for (int i = 0; i <= max; i++) { Map.Entry e = (Map.Entry) (it.next()); String key = (String) e.getKey(); if (key.startsWith(keyPrefix)) { sb.append(key).append('=').append(e.getValue()); sb.append(delit); } } } sb.delete((sb.length() > delitLen) ? (sb.length() - delitLen) : 1, sb.length()); sb.append('}'); return sb.toString(); }
From source file:net.sf.groovyMonkey.ScriptMetadata.java
public static String reasonableFileName(final String menuName) { if (StringUtils.isBlank(menuName)) return "script" + FILE_EXTENSION; final StringBuffer buffer = new StringBuffer(); final String[] array = split(menuName, " "); for (final String t : array) { final String token = capitalize(stripIllegalChars(t)); if (StringUtils.isBlank(token)) continue; if (token.endsWith("__")) { buffer.append(token);// w w w. j a va 2 s . c om continue; } buffer.append(token).append("_"); if (buffer.toString().endsWith("___")) buffer.delete(buffer.length() - 2, buffer.length() - 1); } if (StringUtils.isBlank(buffer.toString())) return "script" + FILE_EXTENSION; while (buffer.toString().endsWith("_")) buffer.deleteCharAt(buffer.length() - 1); while (buffer.toString().startsWith("_")) buffer.deleteCharAt(0); return buffer + FILE_EXTENSION; }
From source file:hydrograph.ui.expression.editor.styletext.ExpressionEditorStyledText.java
private String getExpressionText(String expressionText) { StringBuffer buffer = new StringBuffer(expressionText); int startIndex = buffer.indexOf(RETURN_STATEMENT); if (startIndex > -1) { buffer.delete(0, startIndex); buffer.delete(0, buffer.indexOf("\n")); }//from w ww. j ava2 s . co m return StringUtils.trim(buffer.toString()); }
From source file:org.beangle.web.agent.BrowserCategory.java
public String match(String agentString) { for (Map.Entry<Pattern, String> entry : versionMap.entrySet()) { Matcher m = entry.getKey().matcher(agentString); if (m.find()) { StringBuffer sb = new StringBuffer(); m.appendReplacement(sb, entry.getValue()); sb.delete(0, m.start()); return sb.toString(); }// w ww . j a va 2s . c o m } return null; }
From source file:hydrograph.ui.expression.editor.evaluate.EvaluateExpression.java
private String getTargetException(String error) { String tagetException = "Target exception:"; StringBuffer buffer = new StringBuffer(error); if (buffer.lastIndexOf(tagetException) > -1) buffer.delete(0, buffer.lastIndexOf(tagetException)); return buffer.toString(); }
From source file:org.culturegraph.mf.stream.converter.JsonEncoder.java
@Override public void startRecord(final String id) { final StringBuffer buffer = writer.getBuffer(); buffer.delete(0, buffer.length()); startGroup(id);//ww w . ja va 2s.c o m }
From source file:com.afis.jx.ckfinder.connector.utils.FileUtils.java
/** * This method removes any ".." characters from the path provided as parameter. * * @param path string representing path to remove unsafe characters from * @return filtered path without ".." characters. *//* w w w . ja v a 2 s . c om*/ private static String filterRelativePathChars(String path) { StringBuffer s = new StringBuffer(path); int index = s.indexOf(".."); if (index >= 0) { s = s.delete(index, index + 2); } return s.toString(); }