List of usage examples for java.lang StringBuffer replace
@Override public synchronized StringBuffer replace(int start, int end, String str)
From source file:org.springframework.security.web.debug.Logger.java
public void info(String message, boolean dumpStack) { StringBuilder output = new StringBuilder(256); output.append("\n\n************************************************************\n\n"); output.append(message).append("\n"); if (dumpStack) { StringWriter os = new StringWriter(); new Exception().printStackTrace(new PrintWriter(os)); StringBuffer buffer = os.getBuffer(); // Remove the exception in case it scares people. int start = buffer.indexOf("java.lang.Exception"); buffer.replace(start, start + 19, ""); output.append("\nCall stack: \n").append(os.toString()); }/*from w w w . java2s .c om*/ output.append("\n\n************************************************************\n\n"); logger.info(output.toString()); }
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 w w w.j a v a2 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:jag.sftp.VirtualFileSystem.java
/** * * * @param nfspath/*from w ww .ja v a 2s . co m*/ * * @return * * @throws FileNotFoundException */ public static String translateNFSPath(String nfspath) throws FileNotFoundException { nfspath = nfspath.replace('\\', '/'); // ./ means home if (nfspath.startsWith("./")) { nfspath = nfspath.substring(2); } //if (startsWithIgnoreCase(nfspath, nfshome)) { try { String nfshome = getNFSHomeDirectory().replace('\\', '/'); nfshome = translateCanonicalPath(nfshome, nfshome); String vfshome = getVFSHomeDirectory(SshThread.getCurrentThreadUser()); // First check for the userhome log.debug("NFSPath=" + nfspath); log.debug("NFSHome=" + nfshome); nfspath = translateCanonicalPath(nfspath, nfshome); int idx = nfspath.indexOf(nfshome); return vfshome + nfspath.substring(nfshome.length()); // StringBuffer buf = new StringBuffer(nfspath); // buf = buf.replace(idx, idx + nfshome.length(), vfshome); // return buf.toString(); /*nfspath.replaceFirst(nfshome, vfshome);*/ //} } catch (FileNotFoundException ex) { /* Ignore as we will try other mounts */ } // Now lets translate from the available mounts Iterator it = vfsmounts.entrySet().iterator(); Map.Entry entry; String mount; String path; VFSMount m; while (it.hasNext()) { entry = (Map.Entry) it.next(); mount = (String) entry.getKey(); m = (VFSMount) entry.getValue(); path = m.getPath(); log.debug(m.getMount() + "=" + m.getPath()); // if (startsWithIgnoreCase(nfspath, path)) { try { nfspath = translateCanonicalPath(nfspath, path); int idx = nfspath.indexOf(path); StringBuffer buf = new StringBuffer(nfspath); buf = buf.replace(idx, idx + path.length(), mount); return buf.toString(); } catch (FileNotFoundException ex) { /* Ingore as we will try other mounts */ } // } } // if (startsWithIgnoreCase(nfspath, vfsroot.getPath())) { log.debug("VFSRoot=" + vfsroot.getPath()); nfspath = translateCanonicalPath(nfspath, vfsroot.getPath()); path = nfspath.substring(vfsroot.getPath().length()); //replaceFirst(vfsroot.getPath(), ""); return (path.startsWith("/") ? path : ("/" + path)); // } else { // throw new FileNotFoundException(nfspath + " could not be found"); // } }
From source file:com.sshtools.daemon.vfs.VirtualFileSystem.java
/** * * * @param nfspath/* w w w. j ava 2 s. c o m*/ * * @return * * @throws FileNotFoundException */ public static String translateNFSPath(String nfspath) throws FileNotFoundException { nfspath = nfspath.replace('\\', '/'); // ./ means home if (nfspath.startsWith("./")) { nfspath = nfspath.substring(2); } //if (startsWithIgnoreCase(nfspath, nfshome)) { try { String nfshome = getNFSHomeDirectory().replace('\\', '/'); nfshome = translateCanonicalPath(nfshome, nfshome); String vfshome = getVFSHomeDirectory(SshThread.getCurrentThreadUser()); // First check for the userhome log.debug("NFSPath=" + nfspath); log.debug("NFSHome=" + nfshome); nfspath = translateCanonicalPath(nfspath, nfshome); int idx = nfspath.indexOf(nfshome); return vfshome + nfspath.substring(nfshome.length()); // StringBuffer buf = new StringBuffer(nfspath); // buf = buf.replace(idx, idx + nfshome.length(), vfshome); // return buf.toString(); /*nfspath.replaceFirst(nfshome, vfshome);*/ //} } catch (FileNotFoundException ex) { /* Ignore as we will try other mounts */ } // Now lets translate from the available mounts Iterator it = vfsmounts.entrySet().iterator(); Map.Entry entry; String mount; String path; VFSMount m; while (it.hasNext()) { entry = (Map.Entry) it.next(); mount = (String) entry.getKey(); m = (VFSMount) entry.getValue(); path = m.getPath(); log.debug(m.getMount() + "=" + m.getPath()); // if (startsWithIgnoreCase(nfspath, path)) { try { nfspath = translateCanonicalPath(nfspath, path); int idx = nfspath.indexOf(path); StringBuffer buf = new StringBuffer(nfspath); buf = buf.replace(idx, idx + path.length(), mount); return buf.toString(); } catch (FileNotFoundException ex) { /* Ingore as we will try other mounts */ } // } } // if (startsWithIgnoreCase(nfspath, vfsroot.getPath())) { log.debug("VFSRoot=" + vfsroot.getPath()); nfspath = translateCanonicalPath(nfspath, vfsroot.getPath()); path = nfspath.substring(vfsroot.getPath().length()); //replaceFirst(vfsroot.getPath(), ""); return (path.startsWith("/") ? path : ("/" + path)); // } else { // throw new FileNotFoundException(nfspath + " could not be found"); // } }
From source file:gate.corpora.DocumentContentImpl.java
/** Propagate changes to the document content. */ void edit(Long start, Long end, DocumentContent replacement) { int s = start.intValue(), e = end.intValue(); String repl = replacement == null ? "" : ((DocumentContentImpl) replacement).content; StringBuffer newContent = new StringBuffer(content); newContent.replace(s, e, repl); content = newContent.toString();//from ww w . j av a 2 s . c om }
From source file:org.guzz.util.PropertyUtil.java
/** * Fetch the value of the given key, and resolve ${...} placeholders , then trim() the value and return. * @param props Properties/* w w w . java2s.co m*/ * @param key the key to fetch * @param defaultValue return defaultValue on props is null or the key doesn't exsits in props. * @return the resolved value * * @see #PLACEHOLDER_PREFIX * @see #PLACEHOLDER_SUFFIX */ public static String getTrimPlaceholdersString(Properties props, String key, String defaultValue) { if (props == null) { return defaultValue; } String text = props.getProperty(key); if (text == null) { return defaultValue; } StringBuffer buf = new StringBuffer(text); // The following code does not use JDK 1.4's StringBuffer.indexOf(String) // method to retain JDK 1.3 compatibility. The slight loss in performance // is not really relevant, as this code will typically just run on startup. int startIndex = text.indexOf(PLACEHOLDER_PREFIX); while (startIndex != -1) { int endIndex = buf.toString().indexOf(PLACEHOLDER_SUFFIX, startIndex + PLACEHOLDER_PREFIX.length()); if (endIndex != -1) { String placeholder = buf.substring(startIndex + PLACEHOLDER_PREFIX.length(), endIndex); String propVal = props.getProperty(placeholder); if (propVal != null) { buf.replace(startIndex, endIndex + PLACEHOLDER_SUFFIX.length(), propVal); startIndex = buf.toString().indexOf(PLACEHOLDER_PREFIX, startIndex + propVal.length()); } else { log.warn("Could not resolve placeholder '" + placeholder + "' in [" + text + "]"); startIndex = buf.toString().indexOf(PLACEHOLDER_PREFIX, endIndex + PLACEHOLDER_SUFFIX.length()); } } else { startIndex = -1; } } return buf.toString().trim(); }
From source file:org.apache.marmotta.ldclient.provider.freebase.FreebaseProvider.java
private void warrantyClosing(StringBuffer sb, String line) { if (line.endsWith(".")) { sb.replace(sb.length() - 2, sb.length(), ".\n"); }//from w ww.ja v a 2 s . c o m }
From source file:com.aurel.track.lucene.search.LuceneSearcher.java
/** * Replaces the label for a field with the objectID value * @param analyzer /*from w w w . j av a 2 s . co m*/ * @param userQueryString a part of the user entered query string * @param fieldLabel the workItem field name (like CRM Contact) * @param fieldName the name of the user entered lucene field (like Company from CRM Contact) * @param indexStart the index to start looking for fieldName * @return */ private static String replaceFieldLabelWithFieldName(String userQueryString, String fieldLabel, String fieldName, int indexStart) { int indexFound = LuceneSearcher.fieldNameIndex(userQueryString, fieldLabel, indexStart); if (indexFound == -1) { return userQueryString; } StringBuffer original = new StringBuffer(userQueryString); original.replace(indexFound, indexFound + fieldLabel.length(), fieldName); LOGGER.debug("Replace field label '" + fieldLabel + "' with field name '" + fieldName + "'"); return replaceFieldLabelWithFieldName(original.toString(), fieldLabel, fieldName, indexFound + fieldName.length()); }
From source file:gov.nih.nci.nbia.basket.DynamicJNLPGenerator.java
private void replaceArguments(String arg, StringBuffer jnlpBuilder) { int start = jnlpBuilder.toString().indexOf("$$arguments"); int length = "$$arguments".length(); jnlpBuilder.replace(start, start + length, arg); }
From source file:gov.nih.nci.nbia.basket.DynamicJNLPGenerator.java
private void replaceCodebase(StringBuffer jnlpBuilder) { int start = jnlpBuilder.toString().indexOf("$$codebase"); int length = "$$codebase".length(); jnlpBuilder.replace(start, start + length, codebase + "/"); start = jnlpBuilder.toString().indexOf("$$codebase"); if (start > 0) { jnlpBuilder.replace(start, start + length, codebase); }/*from w w w .j ava 2 s.c om*/ }