List of usage examples for java.lang StringBuffer indexOf
@Override public int indexOf(String str)
From source file:com.bayontechnologies.bi.pentaho.plugin.openflashchart.OpenFlashChartComponent.java
private StringBuffer replaceByToken(StringBuffer buff, String value, String token) { int index = buff.indexOf(token); buff.replace(index, index + token.length(), value); if (buff.indexOf(token) != -1) { //loop replaceByToken again until there is no token at all. return replaceByToken(buff, value, token); }// ww w. jav a 2s . c o m return buff; }
From source file:org.venice.piazza.servicecontroller.messaging.ServiceMessageWorker.java
private MediaType createMediaType(String mimeType) { MediaType mediaType;/*from ww w.j a v a 2 s .c om*/ String type, subtype; StringBuffer sb = new StringBuffer(mimeType); int index = sb.indexOf("/"); // If a slash was found then there is a type and subtype if (index != -1) { type = sb.substring(0, index); subtype = sb.substring(index + 1, mimeType.length()); mediaType = new MediaType(type, subtype); coreLogger.log("The type is=" + type, PiazzaLogger.DEBUG); coreLogger.log("The subtype is=" + subtype, PiazzaLogger.DEBUG); } else { // Assume there is just a type for the mime, no subtype mediaType = new MediaType(mimeType); } return mediaType; }
From source file:org.owasp.jbrofuzz.graph.canvas.ResponseTimeChart.java
private int calculateValue(final File inputFile) { if (inputFile.isDirectory()) { return -1; }//from w w w.j ava 2s. co m int responseTime = 0; BufferedReader inBuffReader = null; try { inBuffReader = new BufferedReader(new FileReader(inputFile)); final StringBuffer one = new StringBuffer(MAX_CHARS); int counter = 0; int got; while (((got = inBuffReader.read()) > 0) && (counter < MAX_CHARS)) { one.append((char) got); counter++; } inBuffReader.close(); one.delete(0, 5); one.delete(one.indexOf("\n--"), one.length()); responseTime = Integer.parseInt(one.toString()); } catch (final IOException e1) { return -2; } catch (final StringIndexOutOfBoundsException e2) { return -3; } catch (final NumberFormatException e3) { return -4; } finally { IOUtils.closeQuietly(inBuffReader); } return responseTime; }
From source file:org.pssframework.xsqlbuilder.XsqlBuilder.java
/** * @see #applyFilters(String, Map)/*from w w w .ja v a 2 s . c o m*/ */ private XsqlFilterResult applyFilters(StringBuffer xsql, Object filters) { LinkedHashMap acceptedFilters = new LinkedHashMap(); for (int i = 0, end = 0, start = xsql.indexOf("/~"); ((start = xsql.indexOf("/~", end)) >= 0); i++) { end = xsql.indexOf("~/", start); KeyMetaDatas metadatas = getKeyMetaDatas(xsql, start, end); if (metadatas.markKeys.isEmpty() && metadatas.replaceKeys.isEmpty()) throw new IllegalArgumentException("Not key found in segment=" + xsql.substring(start, end + 2)); if (isAcceptedAllKeys(filters, metadatas.markKeys) && isAcceptedAllKeys(filters, metadatas.replaceKeys)) { if (logger.isDebugEnabled()) { logger.debug("The filter markKeys=" + metadatas.markKeys + " replaceKeys=" + metadatas.replaceKeys + " is accepted on segment=" + xsql.substring(start, end + 2)); } String segment = xsql.substring(start + 2, end); segment = mergeMarkKeysIntoAcceptedFilters(filters, acceptedFilters, metadatas, segment); segment = replaceReplaceKeysWithValues(filters, metadatas.replaceKeys, segment); xsql.replace(start, end + 2, segment); end = start + segment.length(); } else { if (logger.isDebugEnabled()) { logger.debug( "The filter markKeys=" + metadatas.markKeys + " replaceKeys=" + metadatas.replaceKeys + " is removed from the query on segment=" + xsql.substring(start, end + 2)); } xsql.replace(start, end + 2, ""); end = start; } } return new XsqlFilterResult(xsql.toString(), acceptedFilters); }
From source file:org.nuxeo.typeDocPkg.ODTDoc.java
private Integer countNrOfPages(String fileName) throws IOException, JDOMException { try {/*ww w .j a v a2s . c om*/ textBuffer = new StringBuffer(); Integer numPage = 0; ZipFile zipFile = new ZipFile(fileName); Enumeration<?> entries = zipFile.entries(); ZipEntry entry; while (entries.hasMoreElements()) { entry = (ZipEntry) entries.nextElement(); if (entry.getName().equals("content.xml")) { textBuffer = new StringBuffer(); StringBuffer out = new StringBuffer(); InputStream inputStream = zipFile.getInputStream(entry); byte buf[] = new byte[1024]; while (inputStream.read(buf) > 0) { out.append(new String(buf, 0, 1024)); if (out.indexOf("soft-page-break") > 0) { numPage++; } System.out.print(out); out.delete(0, out.length()); } } } return numPage; } catch (Exception e) { log.error("Error during the countNrOfPages method: ", e); return 1; } }
From source file:com.digitalpebble.storm.crawler.protocol.http.HttpResponse.java
private void processHeaderLine(StringBuffer line) throws HttpException { int colonIndex = line.indexOf(":"); // key is up to colon if (colonIndex == -1) { int i;/*from w ww.j a va2 s. co m*/ for (i = 0; i < line.length(); i++) if (!Character.isWhitespace(line.charAt(i))) break; if (i == line.length()) return; throw new HttpException("No colon in header:" + line); } String key = line.substring(0, colonIndex); int valueStart = colonIndex + 1; // skip whitespace while (valueStart < line.length()) { int c = line.charAt(valueStart); if (c != ' ' && c != '\t') break; valueStart++; } String value = line.substring(valueStart); headers.addValue(key.toLowerCase(Locale.ROOT), value); }
From source file:com.buzzdavidson.spork.client.OWAClient.java
private String determineContentType(StringBuffer buffer, MimeMessage message) { if (buffer.indexOf("_=_NextPart_") >= 0) { return CONTENT_TYPE_MULTIPART; }/*from www. j a v a 2 s. com*/ if (buffer.indexOf("This is a multi-part message in MIME format") >= 0) { return CONTENT_TYPE_MULTIPART; } if (buffer.indexOf("<html") >= 0 || buffer.indexOf("<HTML") >= 0 || buffer.indexOf("<!DOCTYPE HTML") >= 0) { return CONTENT_TYPE_HTML + "; charset=UTF-8"; } if (buffer.indexOf("<?xml") >= 0) { return CONTENT_TYPE_XML + "; charset=UTF-8"; } return CONTENT_TYPE_DEFAULT; }
From source file:net.erdfelt.android.sdkfido.util.PropertyExpander.java
public String expand(String str) { if (StringUtils.isEmpty(str)) { // Empty string. Fail fast. return str; }/*from www . j a va 2s . c o m*/ if (str.indexOf("@") < 0) { // Contains no potential expressions. Fail fast. return str; } Matcher mat = pat.matcher(str); int offset = 0; String expression; String value; StringBuffer expanded = new StringBuffer(); while (mat.find(offset)) { expression = mat.group(1); expanded.append(str.substring(offset, mat.start(1))); value = props.get(mat.group(2)); if (value != null) { expanded.append(value); } else { expanded.append(expression); } offset = mat.end(1); } expanded.append(str.substring(offset)); if (expanded.indexOf("@@") >= 0) { // Special case for escaped content. return expanded.toString().replaceAll("\\@\\@", "\\@"); } else { // return expanded return expanded.toString(); } }
From source file:org.owasp.jbrofuzz.graph.canvas.StatusCodeChart.java
private String calculateValue(final File inputFile) { if (inputFile.isDirectory()) { // return -1; return ERROR; }/* www. j a v a 2s. c om*/ String status = ERROR; BufferedReader inbuffReader = null; try { inbuffReader = new BufferedReader(new FileReader(inputFile)); final StringBuffer one = new StringBuffer(MAX_CHARS); int counter = 0; int got; while (((got = inbuffReader.read()) > 0) && (counter < MAX_CHARS)) { one.append((char) got); counter++; } inbuffReader.close(); one.delete(0, one.indexOf("\n--\n") + 4); one.delete(one.indexOf("\n--"), one.length()); // status = Integer.parseInt(one.toString()); status = one.toString(); } catch (final IOException e1) { // return -2; return ERROR; } catch (final StringIndexOutOfBoundsException e2) { // return -3; return ERROR; } catch (final NumberFormatException e3) { // return 0; return ERROR; } finally { IOUtils.closeQuietly(inbuffReader); } return status; }
From source file:ca.uhn.fhir.rest.server.IncomingRequestAddressStrategy.java
@Override public String determineServerBase(ServletContext theServletContext, HttpServletRequest theRequest) { String requestFullPath = StringUtils.defaultString(theRequest.getRequestURI()); String servletPath;/* w w w.j av a2 s .c om*/ if (myServletPath != null) { servletPath = myServletPath; } else { servletPath = StringUtils.defaultString(theRequest.getServletPath()); } StringBuffer requestUrl = theRequest.getRequestURL(); String servletContextPath = StringUtils.defaultString(theRequest.getContextPath()); String requestPath = requestFullPath.substring(servletContextPath.length() + servletPath.length()); if (requestPath.length() > 0 && requestPath.charAt(0) == '/') { requestPath = requestPath.substring(1); } int startOfPath = requestUrl.indexOf("//"); int requestUrlLength = requestUrl.length(); if (startOfPath != -1 && (startOfPath + 2) < requestUrlLength) { startOfPath = requestUrl.indexOf("/", startOfPath + 2); } if (startOfPath == -1) { startOfPath = 0; } int contextIndex; if (servletPath.length() == 0 || servletPath.equals("/")) { if (requestPath.length() == 0) { contextIndex = requestUrlLength; } else { contextIndex = requestUrl.indexOf(requestPath, startOfPath); } } else { //servletContextPath can start with servletPath contextIndex = requestUrl.indexOf(servletPath + "/", startOfPath); if (contextIndex == -1) { contextIndex = requestUrl.indexOf(servletPath, startOfPath); } } String fhirServerBase; int length = contextIndex + servletPath.length(); if (length > requestUrlLength) { length = requestUrlLength; } fhirServerBase = requestUrl.substring(0, length); return fhirServerBase; }