List of usage examples for java.lang StringBuilder indexOf
@Override public int indexOf(String str)
From source file:org.sonatype.nexus.plugins.rrb.MavenRepositoryReader.java
/** * Used to detect access denied in S3 response. *///w ww . ja va2s.c o m private boolean responseContainsAccessDenied(StringBuilder indata) { return indata.indexOf("<Code>AccessDenied</Code>") != -1 || indata.indexOf("<code>AccessDenied</code>") != -1; }
From source file:org.piraso.api.sql.SQLViewEntry.java
@JsonIgnore public String getParameterReplacedSql() { if (MapUtils.isEmpty(parameters)) { return sql; }// w w w. jav a 2 s . co m List<Integer> sorted = new ArrayList<Integer>(parameters.keySet()); Collections.sort(sorted); StringBuilder buf = new StringBuilder(sql); for (Integer key : sorted) { SQLParameterEntry parameter = parameters.get(key); int index = buf.indexOf("?"); if (index != -1) { buf.replace(index, index + 1, SQLParameterUtils.toPSLiteral(parameter)); } } return buf.toString(); }
From source file:org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingConverter.java
/** * Currently this is a quick-hack implementation. TODO implement using a real templating library */// w ww.j a v a 2 s. c o m private String applyTemplate(String uriTemplate, SimpleObject object) { StringBuilder sb = new StringBuilder(uriTemplate); while (sb.indexOf("{") >= 0) { int startIndex = sb.indexOf("{"); int endIndex = sb.indexOf("}", startIndex + 1); if (endIndex < 0) { throw new IllegalArgumentException("Cannot find matching } in " + uriTemplate); } String varName = sb.substring(startIndex + 1, endIndex); String replaceWithValue = (String) ConversionUtil.convert(object.get(varName), String.class); sb.replace(startIndex, endIndex + 1, replaceWithValue); } return sb.toString(); }
From source file:gov.nih.nci.cabig.caaers.domain.AdverseEventMeddraLowLevelTerm.java
@Transient public String getUniversalTerm() { if (getTerm() == null) { return null; } else if (getAdverseEvent() != null && (getAdverseEvent().getDetailsForOther() != null)) { StringBuilder sb = new StringBuilder(getTerm().getFullName()); // strip everything after "Other", if it is in the name int otherAt = sb.indexOf("Other"); if (otherAt >= 0) { sb.delete(otherAt + 5, sb.length()); }/*from w w w.j a v a 2 s . c o m*/ if (getAdverseEvent().getDetailsForOther() != null) sb.append(": ").append(getAdverseEvent().getDetailsForOther()); return sb.toString(); } else { return getTerm().getFullName(); } }
From source file:pl.nask.hsn2.normalizers.URLNormalizerUtils.java
public static String removeObfuscatedEncoding(StringBuilder sb, EncodingType[] type) { if (type == null) { return sb.toString(); }//from w ww. j a v a 2s . co m for (EncodingType t : type) { if (t == EncodingType.PLUS_AS_SPACE) { normalizeSpaceEncoding(sb); } else if (t == EncodingType.IIS_ENC) { removeIISenc(sb); } else { int i = sb.indexOf("%"); while (i >= 0) { if (i + 3 <= sb.length()) { try { int v = Integer.parseInt(sb.substring(i + 1, i + 3), 16); if (t.allowed(v)) { sb.replace(i, i + 3, Character.toString((char) v)); } } catch (NumberFormatException e) { LOG.debug(e.getMessage()); } } i = sb.indexOf("%", i + 1); } } } return sb.toString(); }
From source file:com.smartitengineering.util.opensearch.io.impl.dom.DomIOImplTest.java
public void testWrite() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); OpenSearchDescriptorWriter writer = new OpenSearchDescriptorWriter(outputStream, MAX_DESC, true); try {/*from ww w . ja v a2 s . co m*/ final long start = System.currentTimeMillis(); writer.write(); final long end = System.currentTimeMillis(); System.out.println("Time taken to write: " + (end - start)); } catch (IOException ex) { ex.printStackTrace(); Assert.fail(ex.getMessage()); } final String toString = outputStream.toString(); System.out.println(toString); assertEquals(MAX, toString); outputStream = new ByteArrayOutputStream(); MAX_BUILDER.queries(OpenSearchAPIBuilders.getQueryBuilder().searchTerms("some terms") .customAttribute("xmlns:cns", "http://google.com/1.1").customAttribute("cns:add", "value").build()); writer = new OpenSearchDescriptorWriter(outputStream, MAX_BUILDER.build(), true); try { final long start = System.currentTimeMillis(); writer.write(); final long end = System.currentTimeMillis(); System.out.println("Time taken to write: " + (end - start)); } catch (IOException ex) { ex.printStackTrace(); Assert.fail(ex.getMessage()); } final String extendedString = outputStream.toString(); System.out.println(extendedString); StringBuilder newStringBuilder = new StringBuilder(MAX); int insertionPoint = newStringBuilder.indexOf("<Developer>"); String additionalString = "<Query xmlns:cns=\"http://google.com/1.1\" cns:add=\"value\" role=\"example\" " + "searchTerms=\"some terms\" />"; newStringBuilder.insert(insertionPoint, additionalString); assertEquals(newStringBuilder.toString(), extendedString); }
From source file:com.mindquarry.model.source.ModelSourceFactory.java
private Collection<String> parseStatements(String unparsedStatements) { StringBuilder remainingStatements = new StringBuilder(unparsedStatements); Collection<String> result = new LinkedList<String>(); int i;//from w w w . ja v a 2 s .c o m while ((i = remainingStatements.indexOf(").")) != -1) { String statement = remainingStatements.substring(0, i + 1); remainingStatements = remainingStatements.delete(0, i + 2); result.add(statement); } result.add(remainingStatements.toString()); return result; }
From source file:com.digitalpebble.behemoth.io.warc.HttpResponse.java
private void processHeaderLine(StringBuilder line) throws IOException { int colonIndex = line.indexOf(":"); // key is up to colon if (colonIndex == -1) { int i;//w w w . j ava 2 s. c o m for (i = 0; i < line.length(); i++) if (!Character.isWhitespace(line.charAt(i))) break; if (i == line.length()) return; throw new IOException("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.set(key, value); }
From source file:chat.ServletLog.java
protected void log(Level l, Object message, Throwable t) { if (t == null && message instanceof Throwable) { t = (Throwable) message;//from ww w.ja v a 2s. c om message = ""; } StringBuilder s = new StringBuilder(format); int i = s.indexOf(FORMAT_DATE); if (i >= 0) s.replace(i, i + FORMAT_DATE.length(), DATE.format(new Date())); i = s.indexOf(FORMAT_LEVEL); if (i >= 0) s.replace(i, i + FORMAT_LEVEL.length(), l.name()); i = s.indexOf(FORMAT_LOG); if (i >= 0) s.replace(i, i + FORMAT_LOG.length(), String.valueOf(message)); i = s.indexOf(FORMAT_CALL); if (i >= 0) { StackTraceElement[] stack = new Throwable().getStackTrace(); // Caller is the third element String clazz = "unknown"; String method = "unknown"; if (stack != null && stack.length > 2) { clazz = stack[2].getClassName(); method = stack[2].getMethodName(); } s.replace(i, i + FORMAT_CALL.length(), clazz + '-' + method); } if (logger != null) logger.log(s.toString(), t); else { if (t != null) { StringWriter ts = new StringWriter(1024); PrintWriter tp = new PrintWriter(ts); t.printStackTrace(tp); tp.close(); s.append("\n ").append(ts.toString()); } (l.ordinal() <= Level.debug.ordinal() ? System.out : System.err).println(s); } }
From source file:com.smartitengineering.util.opensearch.io.impl.dom.DomIOImplTest.java
public void testRead() { OpenSearchDescriptorParser parser = new OpenSearchDescriptorParser(IOUtils.toInputStream(MIN)); try {//from w w w . jav a 2 s . c o m ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final OpenSearchDescriptor parsedDesc = parser.parse(); OpenSearchDescriptorWriter writer = new OpenSearchDescriptorWriter(outputStream, parsedDesc, true); writer.write(); final String toString = outputStream.toString(); System.out.println(toString); assertEquals(MIN, toString); } catch (IOException ex) { ex.printStackTrace(); Assert.fail(ex.getMessage()); } parser = new OpenSearchDescriptorParser(IOUtils.toInputStream(MAX)); try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final OpenSearchDescriptor parsedDesc = parser.parse(); OpenSearchDescriptorWriter writer = new OpenSearchDescriptorWriter(outputStream, parsedDesc, true); writer.write(); final String toString = outputStream.toString(); System.out.println(toString); assertEquals(MAX, toString); } catch (IOException ex) { ex.printStackTrace(); Assert.fail(ex.getMessage()); } StringBuilder newStringBuilder = new StringBuilder(MAX); int insertionPoint = newStringBuilder.indexOf("<Developer>"); String additionalString = "<Query xmlns:cns=\"http://google.com/1.1\" cns:add=\"value\" role=\"example\" " + "searchTerms=\"some terms\" />"; newStringBuilder.insert(insertionPoint, additionalString); parser = new OpenSearchDescriptorParser(IOUtils.toInputStream(newStringBuilder.toString())); try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final OpenSearchDescriptor parsedDesc = parser.parse(); OpenSearchDescriptorWriter writer = new OpenSearchDescriptorWriter(outputStream, parsedDesc, true); writer.write(); final String toString = outputStream.toString(); System.out.println(toString); assertEquals(newStringBuilder.toString(), toString); } catch (IOException ex) { ex.printStackTrace(); Assert.fail(ex.getMessage()); } }