List of usage examples for java.lang StringBuilder deleteCharAt
@Override public StringBuilder deleteCharAt(int index)
From source file:com.orange.wro.taglib.tag.AsJsArrayIncludeTag.java
@Override protected void writeEnd(StringBuilder builder) { int length = builder.length(); if (length == 0) { throw new AssertionError( "The builder length is zero. This should not happen as we normally append something at the very beginning."); }/*from w ww.j a v a2 s . c o m*/ try { if (builder.charAt(length - 1) == ',') { // will be false if we didn't add any file builder.deleteCharAt(length - 1); } } catch (IndexOutOfBoundsException e) { // must not happen as we check before throw new AssertionError( "deleteCharAt triggered a StringIndexOutOfBoundsException, which should not happen."); } builder.append("]"); }
From source file:de.ifgi.mosia.wpswfs.handler.ProxyRequestHandler.java
protected HttpResponse executeHttpGet(Map<String, String[]> urlParameters) throws IOException { StringBuilder sb = new StringBuilder(); for (String key : urlParameters.keySet()) { String[] val = urlParameters.get(key); for (String v : val) { sb.append(key);//from w w w . j a va2 s . c o m sb.append("="); sb.append(v); sb.append("&"); } } sb.deleteCharAt(sb.length() - 1); return executeHttpGet(sb.toString()); }
From source file:com.jillesvangurp.urlbuilder.UrlBuilder.java
public String build() { StringBuilder result = new StringBuilder(url); if (params.size() > 0) { result.append('?'); for (Entry<String, String> entry : params.entrySet()) { String value = entry.getValue(); result.append(entry.getKey() + '=' + value); result.append('&'); }//from www . j a va 2 s .co m result.deleteCharAt(result.length() - 1); // remove trailing & } return result.toString(); }
From source file:com.yenlo.synapse.transport.vfs.VFSOutTransportInfo.java
private String cleanURI(String vfsURI, String queryParams, String originalFileURI) { // Using Apache Commons StringUtils and Java StringBuilder for improved performance. vfsURI = StringUtils.replace(vfsURI, "?" + queryParams, ""); for (String deleteParam : uriParamsToDelete) { queryParams = StringUtils.replace(queryParams, deleteParam, ""); }/* w ww . j ava2 s.c o m*/ queryParams = StringUtils.replace(queryParams, "&&", "&"); // We can sometimes be left with && in the URI if (!"".equals(queryParams) && queryParams.toCharArray()[0] == "&".charAt(0)) { queryParams = queryParams.substring(1); } else if ("".equals(queryParams)) { return vfsURI; } String[] queryParamsArray = queryParams.split("&"); StringBuilder newQueryParams = new StringBuilder(""); if (queryParamsArray.length > 0) { for (String param : queryParamsArray) { newQueryParams.append(param); newQueryParams.append("&"); } newQueryParams = newQueryParams.deleteCharAt(newQueryParams.length() - 1); if (!"".equals(newQueryParams)) { return vfsURI + "?" + newQueryParams; } else { return vfsURI; } } else { return originalFileURI.substring(VFSConstants.VFS_PREFIX.length()); } }
From source file:com.wxxr.nirvana.json.JSONValidationInterceptor.java
private String buildArray(Collection<String> values) { StringBuilder sb = new StringBuilder(); sb.append("["); for (String value : values) { sb.append("\""); sb.append(StringEscapeUtils.escapeJson(value)); sb.append("\","); }/*from w ww . j a va 2s . c o m*/ if (values.size() > 0) sb.deleteCharAt(sb.length() - 1); sb.append("]"); return sb.toString(); }
From source file:com.baidu.qa.service.test.setup.SetUpWithMysqlImpl.java
public boolean setTestDataWithSql(File file, Config config) { FileCharsetDetector det = new FileCharsetDetector(); try {// w ww . j a va 2s . co m String oldcharset = det.guestFileEncoding(file); if (oldcharset.equalsIgnoreCase("UTF-8") == false) FileUtil.transferFile(file, oldcharset, "UTF-8"); } catch (Exception ex) { log.error("[change expect file charset error]:" + ex); } List<String> datalist = FileUtil.getListFromFile(file); if (datalist.size() <= 1) { return true; } try { String table = file.getName().substring(0, file.getName().indexOf(Constant.FILE_TYPE_DB) - 1); String[] name = table.split("\\."); Assert.assertEquals("[get db name error]:from " + file.getName(), 2, name.length); String dbname = name[0]; StringBuilder sb = new StringBuilder(); sb.append("insert into "); sb.append(table); sb.append(" ( " + datalist.get(0) + " )"); sb.append(" values "); for (int i = 1; i < datalist.size(); i++) { sb.append(" (" + datalist.get(i) + " ),"); } sb.deleteCharAt(sb.length() - 1); log.info("[insert csv data into db,the sql is]:" + sb.toString()); JdbcUtil.excuteInsertOrUpdateSql(sb.toString(), dbname, config.getReplace_time()); log.debug("[insert csv data into db,the data are]:"); for (int i = 0; i < datalist.size(); i++) { System.out.println(datalist.get(i)); } return true; } catch (Exception e) { log.error("[insert csv data into mysql error]:", e); throw new AssertionError("insert csv data into mysql error..." + e.getMessage()); } }
From source file:io.github.jeddict.orm.generator.compiler.Snippet.java
default String buildSnippets(String key, List<? extends Snippet> snippets) throws InvalidDataException { StringBuilder builder = new StringBuilder(); if (snippets != null && !snippets.isEmpty()) { builder.append(key).append(" ="); if (snippets.size() > 1) { builder.append(OPEN_BRACES); }//from ww w . j av a2s. c om for (Snippet snippet : snippets) { builder.append(snippet.getSnippet()).append(COMMA); } builder.deleteCharAt(builder.length() - 1); if (snippets.size() > 1) { builder.append(CLOSE_BRACES); } builder.append(COMMA); } return builder.toString(); }
From source file:com.googlecode.wickedcharts.highcharts.jackson.DateTimeLabelFormatSerializer.java
@Override public void serialize(final DateTimeLabelFormat value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { StringBuilder dateTimeFormatBuilder = new StringBuilder(); dateTimeFormatBuilder.append("{"); for (Entry<DateTimeProperties, String> property : value.getProperties().entrySet()) { dateTimeFormatBuilder.append(" " + property.getKey().toCode() + ": '" + property.getValue() + "',"); }// w ww . j ava 2 s. c o m int lastCommaPosition = dateTimeFormatBuilder.lastIndexOf(","); if (lastCommaPosition != -1) { dateTimeFormatBuilder.deleteCharAt(lastCommaPosition); } dateTimeFormatBuilder.append(" }"); jgen.writeRawValue(dateTimeFormatBuilder.toString()); }
From source file:com.heliosapm.tsdblite.metric.Metric.java
/** * {@inheritDoc}/* w w w . ja va 2 s .co m*/ * @see java.lang.Object#toString() */ @Override public String toString() { final StringBuilder b = new StringBuilder(metricName).append(":{"); if (!tags.isEmpty()) { for (Map.Entry<String, String> entry : tags.entrySet()) { b.append(entry.getKey()).append("=").append(entry.getValue()).append(","); } b.deleteCharAt(b.length() - 1); } return b.append("}").toString(); }
From source file:csv.to.sql.parser.mainMenu.java
private String formatFields(String line) { if (line.contains(",")) { String[] Data = null; StringBuilder resultado = new StringBuilder(); resultado.append("("); Data = line.split(","); for (String currLine : Data) { resultado.append(currLine);//from w ww. ja v a 2 s . c om resultado.append(","); } resultado.deleteCharAt(resultado.length() - 1).append(")"); return resultado.toString(); } return line; }