List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
From source file:edu.chalmers.dat076.moviefinder.service.TitleParser.java
/** * Removes everything starting from index n until the char c. If interval * contains a positive 4 digit number (and nothing else) it is returned, * otherwise -1 is returned.// w w w. ja v a 2s .c o m * * @param mySb * @param n * @param c * @return if interval contains a number it is returned */ public int removeUntil(StringBuilder mySb, int n, char c) { int re = -1; for (int i = n; i <= mySb.length(); i++) { if (mySb.charAt(i) == c) { if (i - n == 5) { re = checkForYear(mySb.subSequence(n + 1, i)); } mySb.delete(n, i + 1); break; } } return re; }
From source file:ca.uhn.fhir.rest.method.MethodUtil.java
private static void parseTagValue(TagList theTagList, String theCompleteHeaderValue, StringBuilder theBuffer) { int firstSemicolon = theBuffer.indexOf(";"); int deleteTo; if (firstSemicolon == -1) { firstSemicolon = theBuffer.indexOf(","); if (firstSemicolon == -1) { firstSemicolon = theBuffer.length(); deleteTo = theBuffer.length(); } else {//w ww . j ava2s. c o m deleteTo = firstSemicolon; } } else { deleteTo = firstSemicolon + 1; } String term = theBuffer.substring(0, firstSemicolon); String scheme = null; String label = null; if (isBlank(term)) { return; } theBuffer.delete(0, deleteTo); while (theBuffer.length() > 0 && theBuffer.charAt(0) == ' ') { theBuffer.deleteCharAt(0); } while (theBuffer.length() > 0) { boolean foundSomething = false; if (theBuffer.length() > SCHEME.length() && theBuffer.substring(0, SCHEME.length()).equals(SCHEME)) { int closeIdx = theBuffer.indexOf("\"", SCHEME.length()); scheme = theBuffer.substring(SCHEME.length(), closeIdx); theBuffer.delete(0, closeIdx + 1); foundSomething = true; } if (theBuffer.length() > LABEL.length() && theBuffer.substring(0, LABEL.length()).equals(LABEL)) { int closeIdx = theBuffer.indexOf("\"", LABEL.length()); label = theBuffer.substring(LABEL.length(), closeIdx); theBuffer.delete(0, closeIdx + 1); foundSomething = true; } // TODO: support enc2231-string as described in // http://tools.ietf.org/html/draft-johnston-http-category-header-02 // TODO: support multiple tags in one header as described in // http://hl7.org/implement/standards/fhir/http.html#tags while (theBuffer.length() > 0 && (theBuffer.charAt(0) == ' ' || theBuffer.charAt(0) == ';')) { theBuffer.deleteCharAt(0); } if (!foundSomething) { break; } } if (theBuffer.length() > 0 && theBuffer.charAt(0) == ',') { theBuffer.deleteCharAt(0); while (theBuffer.length() > 0 && theBuffer.charAt(0) == ' ') { theBuffer.deleteCharAt(0); } theTagList.add(new Tag(scheme, term, label)); parseTagValue(theTagList, theCompleteHeaderValue, theBuffer); } else { theTagList.add(new Tag(scheme, term, label)); } if (theBuffer.length() > 0) { ourLog.warn("Ignoring extra text at the end of " + Constants.HEADER_CATEGORY + " tag '" + theBuffer.toString() + "' - Complete tag value was: " + theCompleteHeaderValue); } }
From source file:inti.ws.spring.resource.ByteWebResource.java
/** * Reads the file and stores it's content. *//*from w w w . j av a2 s . c o m*/ @Override public void update() throws Exception { StringBuilder builder = new StringBuilder(32); MessageDigest digest = DIGESTS.get(); InputStream inputStream = resource.getInputStream(); try { lastModified = resource.lastModified(); bytes = IOUtils.toByteArray(inputStream); } finally { inputStream.close(); } digest.reset(); builder.append(Hex.encodeHexString(digest.digest(bytes))); messageDigest = builder.toString(); builder.delete(0, builder.length()); DATE_FORMATTER.formatDate(lastModified, builder); lastModifiedString = builder.toString(); }
From source file:chat.viska.xmpp.NettyTcpSession.java
private String preprocessOutboundXml(@UnknownInitialization(NettyTcpSession.class) NettyTcpSession this, final Document xml) throws TransformerException { final String streamHeaderXmlnsBlock = String.format("xmlns=\"%1s\"", CommonXmlns.STREAM_HEADER); final String rootNs = xml.getDocumentElement().getNamespaceURI(); final String rootName = xml.getDocumentElement().getLocalName(); if (CommonXmlns.STREAM_OPENING_WEBSOCKET.equals(rootNs)) { if ("close".equals(rootName)) { return "</stream:stream>"; } else if ("open".equals(rootName)) { return convertToTcpStreamOpening(xml); } else {//from w w w . j ava 2 s .co m throw new IllegalArgumentException("Incorrect stream opening XML."); } } else if (CommonXmlns.STREAM_HEADER.equals(rootNs)) { // Elements with header namespace, which mean should be prefixed "stream:" final StringBuilder builder = new StringBuilder(DomUtils.writeString(xml)); final int streamHeaderNamespaceBlockIdx = builder.indexOf(streamHeaderXmlnsBlock); builder.insert(1, serverStreamPrefix + ":"); builder.delete(streamHeaderNamespaceBlockIdx, streamHeaderNamespaceBlockIdx + streamHeaderXmlnsBlock.length()); return builder.toString(); } else { return DomUtils.writeString(xml); } }
From source file:inti.util.DateFormatterPerformanceTest.java
public void format(int count) throws Exception { Date date = new Date(); DateFormatter dateFormatter = new DateFormatter(); FastDateFormat fastDateFormat = FastDateFormat.getInstance("EEE, dd-MMM-yyyy hh:mm:ss 'GMT'"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, dd-MMM-yyyy hh:mm:ss 'GMT'"); StringBuilder builder = new StringBuilder(); long start, end; Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ENGLISH); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { dateFormatter.formatDate(date.getTime(), Format.RFC1123, builder, cal); builder.delete(0, builder.length()); }/*from w w w .j a va 2 s . co m*/ Thread.sleep(10); } start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { dateFormatter.formatDate(date.getTime(), Format.RFC1123, builder, cal); builder.delete(0, builder.length()); } end = System.currentTimeMillis(); System.out.format("format(DateFormatter-special) - count: %d, duration: %dms, ratio: %#.4f", count, end - start, count / ((end - start) / 1000.0)); System.out.println(); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { dateFormatter.formatDate(date.getTime()); } Thread.sleep(10); } start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { dateFormatter.formatDate(date.getTime()); } end = System.currentTimeMillis(); System.out.format("format(DateFormatter-simple) - count: %d, duration: %dms, ratio: %#.4f", count, end - start, count / ((end - start) / 1000.0)); System.out.println(); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { fastDateFormat.format(date); } Thread.sleep(10); } start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { fastDateFormat.format(date); } end = System.currentTimeMillis(); System.out.format("format(FastDateFormat) - count: %d, duration: %dms, ratio: %#.4f", count, end - start, count / ((end - start) / 1000.0)); System.out.println(); for (int i = 0; i < 100; i++) { for (int j = 0; j < 10; j++) { simpleDateFormat.format(date); } Thread.sleep(10); } start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { simpleDateFormat.format(date); } end = System.currentTimeMillis(); System.out.format("format(SimpleDateFormat) - count: %d, duration: %dms, ratio: %#.4f", count, end - start, count / ((end - start) / 1000.0)); System.out.println(); }
From source file:se.vgregion.portal.notes.calendar.controllers.NotesCalendarViewController.java
String arrayToString(String[] array) { if (array == null || array.length == 0) { return ""; }/* w ww . ja va 2 s.co m*/ final String separator = "==SEPARATOR=="; StringBuilder sb = new StringBuilder(); for (String s : array) { sb.append(separator + s); } sb.delete(0, separator.length()); return sb.toString(); }
From source file:com.hyperiongray.rcmp.ReportExtractor.java
private String flatten(String[] values, String separator) { logger.debug("Flattening {} keys", values.length); StringBuilder builder = new StringBuilder(); for (String value : values) { logger.debug(Utils.notNull(value).trim()); builder.append(Utils.notNull(value).trim()).append(separator); }/*from w ww .j a v a2 s . c o m*/ if (values.length > 0) { builder.delete(builder.length() - 1, builder.length()); } return builder.toString() + "\n"; }
From source file:com.taobao.tanggong.DataFilePersisterImpl.java
private void saveHash2UrlMap() { if (null != dataDirectory && !this.uri2HashCodes.isEmpty()) { File url2HashMapFile = new File(this.dataDirectory, "index.txt"); File url2HashMapBackupFile = new File(this.dataDirectory, "index.txt.bak"); if (url2HashMapFile.exists()) { url2HashMapFile.renameTo(url2HashMapBackupFile); }//from w w w. j a v a 2 s . c om OutputStream output = null; try { output = new FileOutputStream(url2HashMapFile); StringBuilder sb = new StringBuilder(); for (String k : this.uri2HashCodes.keySet()) { sb.append(k).append("="); Collection<String> vs = this.uri2HashCodes.get(k); if (!vs.isEmpty()) { for (String v : vs) { sb.append(v).append(","); } sb.delete(sb.length() - 1, sb.length()); sb.append("\n"); } } IOUtils.write(sb.toString(), output); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { IOUtils.closeQuietly(output); } } }
From source file:com.wavemaker.common.util.StringUtils.java
/** * split by sep, except if within {},[] or quotes. *//*w ww . ja v a2 s. c o m*/ public static List<String> split(String s, Collection<Character> sep) { List<String> rtn = new ArrayList<String>(); boolean inDoubleQuotes = false; boolean inSingleQuotes = false; int bracesDepth = 0; int bracketsDepth = 0; StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == '{') { bracesDepth++; } else if (c == '}') { bracesDepth--; } else if (c == '[') { bracketsDepth++; } else if (c == ']') { bracketsDepth--; } else if (c == '\'') { if (inSingleQuotes) { inSingleQuotes = false; } else { inSingleQuotes = true; } } else if (c == '"') { if (inDoubleQuotes) { inDoubleQuotes = false; } else { inDoubleQuotes = true; } } boolean add = true; if (sep.contains(c)) { if (!inDoubleQuotes && !inSingleQuotes && bracesDepth == 0 && bracketsDepth == 0) { add = false; rtn.add(sb.toString().trim()); sb.delete(0, sb.length()); } } if (add) { sb.append(c); } } if (sb.length() > 0) { rtn.add(sb.toString().trim()); } return rtn; }
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); }/*from w ww. ja v a 2s .c o 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; }