List of usage examples for java.lang StringBuffer insert
@Override public StringBuffer insert(int offset, double d)
From source file:com.panet.imeta.core.row.ValueDataUtil.java
/** * Replace value occurances in a String with another value. * @param string The original String./*from w w w .ja v a 2 s . c o m*/ * @param repl The text to replace * @param with The new text bit * @return The resulting string with the text pieces replaced. */ public static final String replace(String string, String repl, String with) { StringBuffer str = new StringBuffer(string); for (int i = str.length() - 1; i >= 0; i--) { if (str.substring(i).startsWith(repl)) { str.delete(i, i + repl.length()); str.insert(i, with); } } return str.toString(); }
From source file:org.eclipse.datatools.connectivity.sample.ftp.internal.FtpContentProvider.java
private String getDirectory(FTPFileObject file) { StringBuffer sb = new StringBuffer(); FTPFileObject fileobj = file;/*w w w . j a v a2 s.c o m*/ Object obj; FTPFile ftpFile; while (fileobj != null) { ftpFile = fileobj.getFTPFile(); sb.insert(0, ftpFile.getName()); sb.insert(0, "/"); obj = getParent(fileobj); if (obj instanceof FTPFileObject) { fileobj = (FTPFileObject) obj; } else { fileobj = null; } } return sb.toString(); }
From source file:org.jboss.dashboard.ui.config.TreeShortcutHandler.java
protected String getSectionIds(String workspaceId, Long sectionId) throws Exception { Section section = ((WorkspaceImpl) UIServices.lookup().getWorkspacesManager().getWorkspace(workspaceId)) .getSection(sectionId);/*from w w w. ja va 2 s. c o m*/ StringBuffer sb = new StringBuffer(); while (section != null) { sb.insert(0, section.getId()); section = section.getParent(); if (section != null) { sb.insert(0, "/"); } } return sb.toString(); }
From source file:org.openadaptor.auxil.convertor.fixedwidth.OrderedMapToFixedWidthStringConvertor.java
/** * Either trims the supplied string or pads it out (using spaces) to the * required width and returns the new string. * <p/>/*from ww w . j a v a 2 s . c o m*/ * * If rightAlign is true then we either add space to the left of the text * or trim the text from the right. * * @param s the string to pad/trim * @param width the width that the resulting string will be * @param rightAlign if true then the text will be right aligned in the field * * @return the original string but now at the required length */ private String trimPadValue(String s, int width, boolean rightAlign) { // pad if (s.length() < width) { StringBuffer buffer = new StringBuffer(s); for (int i = width - s.length(); i > 0; --i) { if (rightAlign) buffer.insert(0, " "); else buffer.append(" "); } return buffer.toString(); } // trim if (s.length() > width) { if (rightAlign) return s.substring(s.length() - width); else return s.substring(0, width); } // the string is already at the required length return s; }
From source file:egovframework.rte.fdl.string.EgovStringUtil.java
/** * convert first letter to a big letter or a small * letter.<br>// w ww. ja v a2s . c o m * * <pre> * StringUtil.trim('Password') = 'password' * StringUtil.trim('password') = 'Password' * </pre> * @param str * String to be swapped * @return String converting result */ public static String swapFirstLetterCase(String str) { StringBuffer sbuf = new StringBuffer(str); sbuf.deleteCharAt(0); if (Character.isLowerCase(str.substring(0, 1).toCharArray()[0])) { sbuf.insert(0, str.substring(0, 1).toUpperCase()); } else { sbuf.insert(0, str.substring(0, 1).toLowerCase()); } return sbuf.toString(); }
From source file:com.huguesjohnson.retroleague.rss.RssParserHandler.java
@Override public void endElement(String uri, String localName, String qName) throws SAXException { super.endElement(uri, localName, qName); try {/*from w ww . jav a 2 s.com*/ String tagName = localName; if ((tagName == null) || (tagName.length() < 1)) { tagName = qName; } if (inItemBlock) { if (tagName.equalsIgnoreCase(TAG_ITEM)) { if (this.currentEntry.getPostedDate().compareTo(this.minimumDate) > 0) { this.entryList.add(this.currentEntry); } this.currentEntry = null; readThis = false; inItemBlock = false; } else if (tagName.equalsIgnoreCase(TAG_TITLE)) { //check if this is the rss channel title or the item title if (this.currentEntry != null) { String title = this.characters.toString(); if (this.source == Sources.Facebook) { title = StringEscapeUtils.unescapeHtml4(title); } this.currentEntry.setTitle(title); } readThis = false; } else if (tagName.equalsIgnoreCase(TAG_DESCRIPTION)) { //check if this is the rss channel description or the item description if (this.currentEntry != null) { //TODO - hack to ensure content is html, maybe look for a less hacky solution StringBuffer content = new StringBuffer(this.characters.toString()); if ((!content.substring(0, 1).equals("<")) || (!content.substring(0, 4).equals("<"))) { content.insert(0, "<p>"); content.append("</p>"); } this.currentEntry.setContent(content.toString()); } readThis = false; } else if (tagName.equalsIgnoreCase(TAG_PUBDATE)) { String sDate = this.characters.toString(); this.currentEntry.setPostedDate(this.dateParser.parseDate(sDate)); readThis = false; } else if (tagName.equalsIgnoreCase(TAG_LINK)) { //check if this is the rss channel link or the item link if (this.currentEntry != null) { this.currentEntry.setUrl(this.characters.toString()); } readThis = false; } } else { if (tagName.equalsIgnoreCase(TAG_TITLE)) { //don't care about the rss channel title readThis = false; } } } catch (Exception x) { Log.e(TAG, "endElement", x); } }
From source file:com.twosigma.beaker.autocomplete.ClasspathScanner.java
private String createClassName(File root, File file) { StringBuffer sb = new StringBuffer(); String fileName = file.getName(); sb.append(fileName.substring(0, fileName.lastIndexOf(".class"))); file = file.getParentFile();// ww w. j a v a2 s . c o m while (file != null && !file.equals(root)) { sb.insert(0, '.').insert(0, file.getName()); file = file.getParentFile(); } return sb.toString(); }
From source file:de.unidue.inf.is.ezdl.dlbackend.misc.TemplateParser.java
private StringBuffer replace(StringBuffer stringbuffer, String s, String s1) { StringBuffer sb = new StringBuffer(stringbuffer.toString()); if (stringbuffer.length() < 1 || s.length() < 1) { return sb; }/*from ww w . ja v a 2 s . c o m*/ int i; int j = 0; while ((i = sb.toString().indexOf(s, j)) != -1) { sb = sb.delete(i, i + s.length()); sb = sb.insert(i, s1); j = i + s1.length(); } return sb; }
From source file:com.microsoft.tfs.core.httpclient.Wire.java
private void wire(final String header, final InputStream instream) throws IOException { final StringBuffer buffer = new StringBuffer(); int ch;//from ww w . j a v a 2s . c om while ((ch = instream.read()) != -1) { if (ch == 13) { buffer.append("[\\r]"); } else if (ch == 10) { buffer.append("[\\n]\""); buffer.insert(0, "\""); buffer.insert(0, header); log.debug(buffer.toString()); buffer.setLength(0); } else if ((ch < 32) || (ch > 127)) { buffer.append("[0x"); buffer.append(Integer.toHexString(ch)); buffer.append("]"); } else { buffer.append((char) ch); } } if (buffer.length() > 0) { buffer.append("\""); buffer.insert(0, "\""); buffer.insert(0, header); log.debug(buffer.toString()); } }
From source file:org.eclipse.wb.internal.swing.databinding.model.generic.GenericUtils.java
private static String resolveTypeName(Type type) { if (type instanceof Class<?>) { Class<?> rawType = (Class<?>) type; return convertPrimitiveType(ReflectionUtils.getFullyQualifiedName(rawType, false)); }/*from ww w. j a v a2s .c om*/ if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; Class<?> rawType = (Class<?>) parameterizedType.getRawType(); StringBuffer fullName = new StringBuffer(); fullName.append(CoreUtils.getClassName(rawType)); fullName.append("<"); Type[] types = parameterizedType.getActualTypeArguments(); for (int i = 0; i < types.length; i++) { if (i > 0) { fullName.append(", "); } fullName.append(resolveTypeName(types[i])); } fullName.append(">"); return fullName.toString(); } if (type instanceof GenericArrayType) { StringBuffer fullName = new StringBuffer(); Type elementType = null; GenericArrayType arrayType = (GenericArrayType) type; while (true) { fullName.append("[]"); elementType = arrayType.getGenericComponentType(); if (elementType instanceof GenericArrayType) { arrayType = (GenericArrayType) elementType; continue; } break; } fullName.insert(0, resolveTypeName(elementType)); return fullName.toString(); } if (type instanceof WildcardType) { WildcardType wildcardType = (WildcardType) type; Type[] upperBounds = wildcardType.getUpperBounds(); Type[] lowerBounds = wildcardType.getLowerBounds(); if (!ArrayUtils.isEmpty(upperBounds)) { Type upperBound = upperBounds[0]; boolean isWildcard = upperBound instanceof Class<?> && ((Class<?>) upperBound).getName().equals("java.lang.Object"); if (!isWildcard) { return "? extends " + resolveTypeName(upperBound); } } else if (!ArrayUtils.isEmpty(lowerBounds)) { return "? super " + resolveTypeName(lowerBounds[0]); } return "?"; } if (type instanceof TypeVariable<?>) { return "?"; } Assert.fail("Undefine type: " + type); return null; }