List of usage examples for java.lang StringBuilder insert
@Override public StringBuilder insert(int offset, double d)
From source file:de.hybris.platform.webservices.AbstractWebServicesTest.java
/** * Helper method to import csv from <tt>resources/test/</tt> directory located in b2bcore extension. It expects, that * file has <tt>.csv</tt> extension, and is in standard ImpEx csv format. There is no need to add test/ base * directory or <tt>.csv</tt> extension to parameter when calling this method. Following calls are equals: * // w w w . ja v a 2 s . co m * <pre> * importCSVFromResources("/test/fooBar.csv"); * importCSVFromResources("/test/fooBar"); * importCSVFromResources("fooBar"); * </pre> * * All of them assumes that there is file called <tt>fooBar.csv</tt> in <tt>resources/testsrc/</tt> directory. * * @param fileName * the file name * @throws ImpExException * - thrown on any problems with importing data. Such problems will be dumped into file in system temp * directory. */ public static void importCSVFromResources(final String fileName) throws ImpExException { final StringBuilder resource = new StringBuilder(fileName); if (!hasExtension(resource.toString())) { resource.append(CSV_EXTENSION); } if (!hasResourceFolder(resource.toString())) { resource.insert(0, CSV_RESOURCE_DIR); } LOG.info("importing resource " + fileName); final InputStream inStr = Case1Test.class.getResourceAsStream(resource.toString()); ImpExManager.getInstance().importDataLight(inStr, "UTF-8", true); }
From source file:edu.uci.ics.jung.visualization.util.LabelWrapper.java
/** * line-wrap the passed String as an html string with * break Strings inserted./*from w ww . j a v a 2 s . c om*/ * * @param str * @return */ private String wrap(String str) { StringBuilder buf = new StringBuilder(str); int len = lineLength; while (len < buf.length()) { int idx = buf.lastIndexOf(" ", len); if (idx != -1) { buf.replace(idx, idx + 1, breaker); len = idx + breaker.length() + lineLength; } else { buf.insert(len, breaker); len += breaker.length() + lineLength; } } buf.insert(0, "<html>"); return buf.toString(); }
From source file:com.sonyericsson.hudson.plugins.gerrit.trigger.diagnostics.Diagnostics.java
/** * Construct an url with a potential context for {@link #getContextMenu(String)}. * @param context potential string to prefix with * @param name the url/*from w w w. ja va 2s . c om*/ * @return an url, relative or not. */ private String makeRelativeUrl(String context, String name) { StringBuilder url = new StringBuilder(name); if (!StringUtils.isBlank(context)) { if (!context.endsWith("/")) { url.insert(0, '/'); } url.insert(0, context); } return url.toString(); }
From source file:com.johncroth.histo.logging.LogHistogramWriterParserTest.java
private String makeFile(boolean includeErrors) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("Preamble"); if (includeErrors) { // duplicate start or missing json line pw.println(LogHistogramWriter.MESSAGE_START_LINE); }//w w w .j a v a 2 s .co m pw.println(writer.formatMessage(new RecordedInterval<LogHistogramRecorder>(makeRecorder(), 100, 200))); pw.println(writer .formatMessage(new RecordedInterval<LogHistogramRecorder>(new LogHistogramRecorder(), 200, 300))); pw.println("Whatever."); if (includeErrors) { StringBuilder sb = new StringBuilder( writer.formatMessage(new RecordedInterval<LogHistogramRecorder>(makeRecorder(), 1000, 2000))); sb.insert(sb.indexOf("\n") + 5, "\n"); pw.println(sb); sb = new StringBuilder( writer.formatMessage(new RecordedInterval<LogHistogramRecorder>(makeRecorder(), 1000, 2000))); sb.delete(sb.indexOf("\n") + 2, sb.indexOf("\n") + 3); pw.println(sb); } pw.println(writer.formatMessage(new RecordedInterval<LogHistogramRecorder>(makeRecorder(), 300, 400))); String x = sw.toString(); return x; }
From source file:com.dianping.resource.io.util.ClassUtils.java
/** * Build a nice qualified name for an array: * component type class name + "[]"./*from w w w .j ava 2 s .c o m*/ * @param clazz the array class * @return a qualified name for the array class */ private static String getQualifiedNameForArray(Class<?> clazz) { StringBuilder result = new StringBuilder(); while (clazz.isArray()) { clazz = clazz.getComponentType(); result.append(ClassUtils.ARRAY_SUFFIX); } result.insert(0, clazz.getName()); return result.toString(); }
From source file:com.rockagen.gnext.service.spring.AccountServImpl.java
private String getBillSn(long uid) { Date now = new Date(); String tmp = CommUtil.dateTime2StringFS(now); StringBuilder sb = new StringBuilder(tmp); String suid = String.format("%08d", uid); sb.insert(8, suid); return sb.toString(); }
From source file:com.freetmp.common.util.ClassUtils.java
private static String getQualifiedNameForArray(Class<?> clazz) { StringBuilder result = new StringBuilder(); while (clazz.isArray()) { clazz = clazz.getComponentType(); result.append(ClassUtils.ARRAY_SUFFIX); }//from w w w . ja v a 2s. c o m result.insert(0, clazz.getName()); return result.toString(); }
From source file:cache.reverseproxy.Wire.java
private void wire(final String header, final byte[] b, final int pos, final int off) { final StringBuilder buffer = new StringBuilder(); for (int i = 0; i < off; i++) { final int ch = b[pos + i]; if (ch == 13) { buffer.append("[\\r]"); } else if (ch == 10) { buffer.append("[\\n]\""); buffer.insert(0, "\""); buffer.insert(0, header);//from w w w.j ava 2s.c om this.log.debug(this.id + " " + 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); this.log.debug(this.id + " " + buffer.toString()); } }
From source file:com.redhat.rhn.common.util.StringUtil.java
/** * Converts the passed in string to a valid java Class name. This basically * capitalizes each word and removes all word delimiters. * @param strIn The string to convert.//from w w w. j ava2 s. co m * @return The converted string. */ public static String classify(String strIn) { String str = strIn.trim(); StringBuilder result = new StringBuilder(str.length()); boolean wasWhitespace = false; for (int i = 0, j = 0; i < str.length(); i++) { char c = str.charAt(i); if (Character.isLetterOrDigit(c)) { if (i == 0) { c = Character.toUpperCase(c); } if (wasWhitespace) { c = Character.toUpperCase(c); wasWhitespace = false; } result.insert(j, c); j++; continue; } wasWhitespace = true; } return result.toString(); }
From source file:net.sourceforge.pmd.benchmark.TextTimingReportRenderer.java
private void renderHeader(final String displayName, final Writer writer) throws IOException { final StringBuilder sb = new StringBuilder(COLUMNS).append(displayName); // Make sure we have an even-length string if (displayName.length() % 2 == 1) { sb.append(' '); }//from w w w . j av a2 s . c o m // Surround with <<< and >>> sb.insert(0, "<<< ").append(" >>>"); // Create the ruler while (sb.length() < COLUMNS) { sb.insert(0, '-').append('-'); } writer.write(sb.toString()); writer.write(PMD.EOL); // Write table titles writer.write(StringUtils.rightPad("Label", LABEL_COLUMN_WIDTH)); writer.write(StringUtils.leftPad("Time (secs)", TIME_COLUMN_WIDTH)); writer.write(StringUtils.leftPad("Self Time (secs)", SELF_TIME_COLUMN_WIDTH)); writer.write(StringUtils.leftPad("# Calls", CALL_COLUMN_WIDTH)); writer.write(StringUtils.leftPad("Counter", COUNTER_COLUMN_WIDTH)); writer.write(PMD.EOL); writer.write(PMD.EOL); }