List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
From source file:com.predic8.membrane.core.interceptor.authentication.BasicAuthenticationInterceptor.java
@Override public String getLongDescription() { StringBuilder sb = new StringBuilder(); sb.append(getShortDescription());/*from ww w . j a v a 2 s . c om*/ sb.append("<br/>"); sb.append("Users: "); for (User user : users) { sb.append(StringEscapeUtils.escapeHtml(user.getName())); sb.append(", "); } sb.delete(sb.length() - 2, sb.length()); sb.append("<br/>Passwords are not shown."); return sb.toString(); }
From source file:net.sourceforge.vulcan.core.support.ProjectImporterImpl.java
protected PathInfo computeProjectBasedirUrl(String url, String relativePath, boolean computeBuildSpecPath) { final PathInfo pathInfo = new PathInfo(); final int pathIndex = url.lastIndexOf(':') + 1; final StringBuilder sb = new StringBuilder(url.substring(pathIndex)); sb.delete(sb.lastIndexOf("/") + 1, sb.length()); if (relativePath != null) { sb.append(relativePath);/*w ww . j ava2s .co m*/ } try { String normalized = new URI(sb.toString()).normalize().toString(); if (url.startsWith("file:///") && !normalized.startsWith("///")) { /* Special case for file protocol. * URI.normalize eats the extra slashes at the begining. * This behavior does not seem to be documented in the JavaDoc for URI. */ normalized = "//" + normalized; } final String baseUrl = url.substring(0, pathIndex) + normalized; pathInfo.setProjectBasedirUrl(baseUrl); if (computeBuildSpecPath) { pathInfo.setBuildSpecPath(url.substring(baseUrl.length())); } return pathInfo; } catch (URISyntaxException e) { throw new RuntimeException(e); } }
From source file:com.predic8.membrane.core.rules.ServiceProxyKey.java
public static String createHostPattern(String host) { StringBuilder regex = new StringBuilder(); boolean quoted = false; boolean started = false; regex.append("("); for (int i = 0; i < host.length(); i++) { char c = host.charAt(i); switch (c) { case ' ': if (!started) break; if (quoted) { regex.append("\\E"); quoted = false;/* www . ja va 2 s. co m*/ } started = false; regex.append(")|("); break; case '*': if (quoted) { regex.append("\\E"); quoted = false; } regex.append(".+"); started = true; break; default: if (!quoted) { regex.append("\\Q"); quoted = true; started = true; } if (c == '\\') regex.append('\\'); regex.append(c); } } if (quoted) { regex.append("\\E"); quoted = false; } if (!started && regex.length() > 1) { regex.delete(regex.length() - 3, regex.length()); } regex.append(")"); String r = regex.toString(); return r; }
From source file:de.itsvs.cwtrpc.controller.CacheControlFilter.java
protected PreparedCacheControlUriConfig getPreparedUriConfig(HttpServletRequest request) { final String contextPath; final StringBuilder sb; final String uri; contextPath = request.getContextPath(); sb = new StringBuilder(request.getRequestURI()); if ((contextPath.length() > 0) && (sb.indexOf(contextPath) == 0)) { sb.delete(0, contextPath.length()); }/*ww w .j a v a2s. com*/ if ((sb.length() == 0) || (sb.charAt(0) != '/')) { sb.insert(0, '/'); } uri = sb.toString(); if (log.isDebugEnabled()) { log.debug("Checked URI is '" + uri + "'"); } for (PreparedCacheControlUriConfig config : getUriConfigs()) { if ((config.getMethod() == null) || config.getMethod().name().equals(request.getMethod())) { if (config.getValue().matches(uri)) { if (log.isDebugEnabled()) { log.debug("Matching configuration for URI '" + uri + "' and method '" + request.getMethod() + "' is " + config); } return config; } } } if (log.isDebugEnabled()) { log.debug("No matching configuration for URI '" + uri + "' and method '" + request.getMethod() + "'"); } return null; }
From source file:hr.fer.zemris.vhdllab.service.ci.CircuitInterface.java
@Override public String toString() { StringBuilder sb = new StringBuilder(10 + ports.size() * 50); sb.append("ENTITY ").append(name).append(" IS"); if (!ports.isEmpty()) { sb.append(" PORT(\n"); for (Port p : ports) { sb.append("\t").append(p).append(";\n"); }/*from w ww. j a v a2 s. c o m*/ // remove last semi-colon sb.delete(sb.length() - 2, sb.length() - 1); sb.append(");"); } sb.append("\nEND ").append(name).append(";"); return sb.toString(); }
From source file:org.syncope.core.AbstractTest.java
private void logTableContent(final Connection conn, final String tableName) throws SQLException { LOG.debug("Table: " + tableName); Statement stmt = null;/* w w w. j av a 2 s .c o m*/ ResultSet rs = null; try { stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT * FROM " + tableName); final StringBuilder row = new StringBuilder(); while (rs.next()) { for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) { row.append(rs.getMetaData().getColumnLabel(i + 1)).append("=").append(rs.getString(i + 1)) .append(" "); } LOG.debug(row.toString()); row.delete(0, row.length()); } } catch (SQLException sqle) { LOG.error("While dumping " + tableName + "content", sqle); } finally { rs.close(); stmt.close(); } }
From source file:com.flowpowered.commons.datatable.ManagedHashMap.java
@Override public String toString() { StringBuilder toString = new StringBuilder("ManagedHashMap {"); for (Map.Entry<? extends String, ? extends Serializable> e : entrySet()) { toString.append("("); toString.append(e.getKey());//from w w w. j av a 2 s.c o m toString.append(", "); toString.append(e.getValue()); toString.append("), "); } toString.delete(toString.length() - 2, toString.length()); toString.append("}"); return toString.toString(); }
From source file:com.marklogic.contentpump.utilities.OptionsFileUtil.java
/** * Expands any options file that may be present in the given set of arguments. * * @param args the given arguments/* w w w.j a va 2 s .c o m*/ * @return a new string array that contains the expanded arguments. * @throws Exception */ public static String[] expandArguments(String[] args) throws Exception { List<String> options = new ArrayList<String>(); for (int i = 0; i < args.length; i++) { if (args[i].equals(OPTIONS_FILE)) { if (i == args.length - 1) { throw new Exception("Missing options file"); } String fileName = args[++i]; File optionsFile = new File(fileName); BufferedReader reader = null; StringBuilder buffer = new StringBuilder(); try { reader = new BufferedReader(new FileReader(optionsFile)); String nextLine = null; while ((nextLine = reader.readLine()) != null) { nextLine = nextLine.trim(); if (nextLine.length() == 0 || nextLine.startsWith("#")) { // empty line or comment continue; } buffer.append(nextLine); if (nextLine.endsWith("\\")) { if (buffer.charAt(0) == '\'' || buffer.charAt(0) == '"') { throw new Exception("Multiline quoted strings not supported in file(" + fileName + "): " + buffer.toString()); } // Remove the trailing back-slash and continue buffer.deleteCharAt(buffer.length() - 1); } else { // The buffer contains a full option options.add(removeQuotesEncolosingOption(fileName, buffer.toString())); buffer.delete(0, buffer.length()); } } // Assert that the buffer is empty if (buffer.length() != 0) { throw new Exception( "Malformed option in options file(" + fileName + "): " + buffer.toString()); } } catch (IOException ex) { throw new Exception("Unable to read options file: " + fileName, ex); } finally { if (reader != null) { try { reader.close(); } catch (IOException ex) { LOG.info("Exception while closing reader", ex); } } } } else { // Regular option. Parse it and put it on the appropriate list options.add(args[i]); } } return options.toArray(new String[options.size()]); }
From source file:com.sf.ddao.factory.DefaultStatementFactory.java
public void init(AnnotatedElement element, String sql) throws StatementFactoryException { try {/*from w w w. j a v a 2 s. c o m*/ char lastChar = 0; boolean paramStarted = false; StringBuilder token = new StringBuilder(sql.length()); StringBuilder param = new StringBuilder(); for (char ch : sql.toCharArray()) { if (paramStarted) { if (lastChar == ch) { stmtTokens.add(token.toString()); token.delete(0, token.length()); if (ch == '$') { addInlineParameter(element, param.toString()); } else { addRefParameter(element, param.toString()); } param.delete(0, param.length()); paramStarted = false; continue; } param.append(ch); continue; } if (ch == '#' || ch == '$') { paramStarted = true; lastChar = ch; continue; } token.append(ch); } stmtTokens.add(token.toString()); } catch (Exception e) { throw new StatementFactoryException("Failed to extract statement parameters for " + element, e); } }
From source file:com.tesora.dve.sql.template.TemplateBuilder.java
public String toCreateRangeStatement(final String rangeName, final String groupName, final Set<Type> columnTypes) { final String typeSeparator = ", "; final StringBuilder statement = new StringBuilder(); statement.append("CREATE RANGE IF NOT EXISTS ").append(rangeName).append(" ("); for (final Type type : columnTypes) { statement.append(type.getTypeName()).append(typeSeparator); }/*from w w w.ja v a 2s . co m*/ final int statementLength = statement.length(); statement.delete(statementLength - typeSeparator.length(), statementLength).append(") PERSISTENT GROUP ") .append(groupName); return statement.toString(); }