List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
From source file:com.gaze.webpaser.StackWidgetService.java
private void getDatafromNetwork() { new AsyncTask<String, Void, String>() { @Override/*from ww w. j a v a 2 s . c o m*/ protected void onPreExecute() { super.onPreExecute(); onStartDataLoading(); } @Override protected String doInBackground(String... params) { ArrayList<NameValuePair> param = new ArrayList<NameValuePair>(); try { // Set up HTTP post // HttpClient is more then less deprecated. Need to change // to // URLConnection HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(listUrl); httpPost.setEntity(new UrlEncodedFormEntity(param)); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); Log.i(LOG_TAG, "finish http"); // Read content & Log inputStream = httpEntity.getContent(); } catch (UnsupportedEncodingException e1) { Log.e("UnsupportedEncodingException", e1.toString()); e1.printStackTrace(); } catch (ClientProtocolException e2) { Log.e("ClientProtocolException", e2.toString()); e2.printStackTrace(); } catch (IllegalStateException e3) { Log.e("IllegalStateException", e3.toString()); e3.printStackTrace(); } catch (IOException e4) { Log.e("IOException", e4.toString()); e4.printStackTrace(); } // Convert response to string using String Builder try { BufferedReader bReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"), 8); StringBuilder sBuilder = new StringBuilder(); String line = null; while ((line = bReader.readLine()) != null) { sBuilder.append(line + "\n"); } inputStream.close(); result = sBuilder.toString(); Log.i(LOG_TAG, "finish read stream: " + result); if (!isStreamTheTargetJson(result)) { result = ""; sBuilder.delete(0, sBuilder.length() - 1); } // parse json string here if (!result.isEmpty()) { if (result.startsWith("<html>")) return ""; JSONObject titleJson = new JSONObject(result); JSONArray datajson = titleJson.getJSONArray("data"); JSONArray urlQueue = datajson.getJSONArray(0); for (int i = 0; i < urlQueue.length(); i++) { JSONObject item = urlQueue.getJSONObject(i); String url = item.getString("link"); String introtext = item.getString("introtext"); String title = item.getString("title"); String images = item.getString("images"); String name = item.getString("name"); String time = item.getString("publish_up"); if (url != null) { // addToQueue(GlobalData.baseUrl+'/'+url); addToList(url, introtext, title, images, name, time); } } } } catch (Exception e) { Log.e("StringBuilding & BufferedReader", "Error converting result " + e.toString()); } return result; } @Override protected void onPostExecute(String msg) { // mDisplay.append(msg + "\n"); Log.i(LOG_TAG, msg.toString()); onFinishDataLoading(); } }.execute(); }
From source file:net.jofm.DefaultFixedMapper.java
private Object fromFixedField(StringBuilder line, FixedFieldMetaData fixedFieldMetadata, Class<?> fieldType) throws Exception { String fixedFieldIdentification = fixedFieldMetadata.getIdentification(); if (!line.toString().startsWith(fixedFieldIdentification)) { if (fixedFieldMetadata.isRequired()) { throw new FixedMappingException("The data doesn't start with '" + fixedFieldIdentification + "' for required fixed field '" + fixedFieldMetadata.getField().getName() + "'"); } else {/*from w w w.j a va 2s. c o m*/ //Do nothing if it is an optional fixed field. return null; } } else { line.delete(0, fixedFieldIdentification.length()); Object fieldValue = fieldType.newInstance(); fromFixed(line, fieldValue, fixedFieldMetadata.getFixedFieldMetaData()); return fieldValue; } }
From source file:org.alfresco.encryption.KeyStoreTests.java
protected TestAlfrescoKeyStore getKeyStore(String name, String type, final Map<String, String> passwords, final Map<String, String> encodedKeyData, String keyStoreLocation, String backupKeyStoreLocation) { KeyResourceLoader testKeyResourceLoader = new KeyResourceLoader() { @Override//w w w.j av a 2 s . com public InputStream getKeyStore(String keyStoreLocation) throws FileNotFoundException { return keyResourceLoader.getKeyStore(keyStoreLocation); } @Override public Properties loadKeyMetaData(String keyMetaDataFileLocation) throws IOException, FileNotFoundException { Properties p = new Properties(); p.put("keystore.password", "password"); StringBuilder aliases = new StringBuilder(); for (String keyAlias : passwords.keySet()) { p.put(keyAlias + ".password", passwords.get(keyAlias)); if (encodedKeyData != null && encodedKeyData.get(keyAlias) != null) { p.put(keyAlias + ".keyData", encodedKeyData.get(keyAlias)); } p.put(keyAlias + ".algorithm", "DESede"); aliases.append(keyAlias); aliases.append(","); } if (aliases.length() > 0) { // remove trailing comma aliases.delete(aliases.length() - 1, aliases.length()); } p.put("aliases", aliases.toString()); return p; } }; KeyStoreParameters keyStoreParameters = new KeyStoreParameters(name, type, null, "", keyStoreLocation); KeyStoreParameters backupKeyStoreParameters = new KeyStoreParameters(name + ".backup", type, null, "", backupKeyStoreLocation); TestAlfrescoKeyStore keyStore = new TestAlfrescoKeyStore(); keyStore.setKeyStoreParameters(keyStoreParameters); keyStore.setBackupKeyStoreParameters(backupKeyStoreParameters); keyStore.setKeyResourceLoader(testKeyResourceLoader); keyStore.setValidateKeyChanges(true); keyStore.setEncryptionKeysRegistry(encryptionKeysRegistry); return keyStore; }
From source file:fr.gael.dhus.olingo.v1.V1Processor.java
private URI makeLink(boolean remove_last_segment) throws ODataException { URI selfLnk = getServiceRoot(); StringBuilder sb = new StringBuilder(selfLnk.getPath()); if (remove_last_segment) { // Removes the last segment. int lio = sb.lastIndexOf("/"); while (lio != -1 && lio == sb.length() - 1) { sb.deleteCharAt(lio);//w w w. jav a 2 s . c om lio = sb.lastIndexOf("/"); } if (lio != -1) sb.delete(lio + 1, sb.length()); // Removes the `$links` segment. lio = sb.lastIndexOf("$links/"); if (lio != -1) sb.delete(lio, lio + 7); } else { if (!sb.toString().endsWith("/") && !sb.toString().endsWith("\\")) { sb.append("/"); } } try { URI res = new URI(selfLnk.getScheme(), selfLnk.getUserInfo(), selfLnk.getHost(), selfLnk.getPort(), sb.toString(), null, selfLnk.getFragment()); return res; } catch (Exception e) { throw new ODataException(e); } }
From source file:com.glaf.core.service.impl.MxTablePageServiceImpl.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public List<Object> getTableList(String tableName, String idColumn, Map<String, String> selectColumns, int begin, int pageSize, List<QueryCondition> conditions) { SqlExecutor sqlExecutor = QueryUtils.getMyBatisAndConditionSql(conditions); StringBuilder buffer = new StringBuilder(); buffer.append(" select "); if (selectColumns != null && !selectColumns.isEmpty()) { Set<Entry<String, String>> entrySet = selectColumns.entrySet(); for (Entry<String, String> entry : entrySet) { String columnName = entry.getKey(); String columnLabel = entry.getValue(); if (columnName != null && columnLabel != null) { buffer.append(columnName).append(" as ").append(columnLabel); buffer.append(" , "); }//w ww.j a v a 2 s. c om } buffer.delete(buffer.length() - 2, buffer.length()); buffer.append(" from ").append(tableName); } else { buffer.append(" * from ").append(tableName); } buffer.append(" where 1=1 "); String sql = buffer.toString() + sqlExecutor.getSql(); Map<String, Object> params = new java.util.HashMap<String, Object>(); if (sqlExecutor.getParameter() instanceof Map) { params.putAll((Map) sqlExecutor.getParameter()); } logger.debug("sql:\n" + sql); logger.debug("params:" + params); params.put("queryString", sql); if (begin < 0) { begin = 0; } if (pageSize <= 0) { pageSize = Paging.DEFAULT_PAGE_SIZE; } RowBounds rowBounds = new RowBounds(begin, pageSize); List<Object> rows = sqlSession.selectList("getSqlQueryList", params, rowBounds); return rows; }
From source file:net.rptools.maptool.client.functions.StrListFunctions.java
/** * MapTool call: <code>listReplace(list, index, target [,delim])</code> * /*w ww . j av a2 s .c om*/ * @param index * A number from 0 to (list length)-1. Out of range values are ignored. * @param target * A string or number to be placed in the list * @param delim * An optional list delimiter (default ",") * @return A new list with the entry at <code>index</code> repaced by <code>target</code> */ public Object listReplace(List<Object> parameters, String listStr, String lastParam, List<String> list) throws ParameterException { Object retval = ""; String delim = ","; int minParams = 3; int maxParams = minParams + 1; checkVaryingParameters("listReplace()", minParams, maxParams, parameters, new Class[] { null, BigDecimal.class, null, String.class }); if (parameters.size() == maxParams) { delim = lastParam; } parse(listStr, list, delim); if (list.size() == 0) // can't replace if there are no entries return retval; int index = ((BigDecimal) parameters.get(1)).intValue(); String target = parameters.get(2).toString().trim(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < list.size(); i++) { if (i == index) { sb.append(target); } else { sb.append(list.get(i)); } sb.append(delim); sb.append(" "); } sb.delete(sb.length() - 1 - delim.length(), sb.length()); // remove the trailing ", " retval = sb.toString(); return retval; }
From source file:com.abstratt.mdd.frontend.textuml.renderer.TextUMLRenderingUtils.java
private static void renderStereotypeApplication(NamedElement element, StringBuilder builder, EObject application) {// www. j a va2 s . com Stereotype stereotype = UMLUtil.getStereotype(application); builder.append(getQualifiedNameIfNeeded(stereotype, (Namespace) application.eContainer())); builder.append("("); int mark = builder.length(); for (Property stereotypeProperty : stereotype.getAllAttributes()) { if (stereotypeProperty.getAssociation() instanceof Extension) continue; Object taggedValue = element.getValue(stereotype, stereotypeProperty.getName()); if (taggedValue == null) continue; if (taggedValue instanceof Element) if (!(taggedValue instanceof NamedElement)) continue; // default value for required property of type Integer is 0 // so don't show it if (taggedValue instanceof Integer && stereotypeProperty.getLower() >= 1 && ((Integer) taggedValue).equals(0)) continue; // don't show default values for stereotype properties String defaultValue = stereotypeProperty.getDefault(); if (defaultValue != null && defaultValue.equals(taggedValue.toString())) { continue; } builder.append(name(stereotypeProperty)); builder.append("="); boolean isString = taggedValue instanceof String; if (isString) builder.append('"'); if (taggedValue instanceof NamedElement) taggedValue = ((NamedElement) taggedValue).getName(); builder.append(taggedValue); if (isString) builder.append('"'); builder.append(","); } if (builder.length() > mark) { builder.delete(builder.length() - 1, builder.length()); builder.append(")"); } else builder.delete(mark - 1, mark); }
From source file:org.matsim.counts.algorithms.CountSimComparisonKMLWriter.java
/** * Creates the CountsErrorGraph for all the data * @param kmlFilename the filename of the kml file * @param visible true if initially visible * @return the ScreenOverlay Feature/*from ww w . ja v a2 s .c om*/ */ private ScreenOverlayType createBiasErrorGraph(String kmlFilename) { BiasErrorGraph ep = new BiasErrorGraph(this.countComparisonFilter.getCountsForHour(null), this.iterationNumber, null, "error graph"); ep.createChart(0); double[] meanError = ep.getMeanRelError(); double[] meanBias = ep.getMeanAbsBias(); int index = kmlFilename.lastIndexOf(System.getProperty("file.separator")); if (index == -1) { index = kmlFilename.lastIndexOf('/'); } String outdir; if (index == -1) { outdir = ""; } else { outdir = kmlFilename.substring(0, index) + System.getProperty("file.separator"); } String file = outdir + "biasErrorGraphData.txt"; log.info("writing chart data to " + new File(file).getAbsolutePath()); try { BufferedWriter bwriter = IOUtils.getBufferedWriter(file); StringBuilder buffer = new StringBuilder(200); buffer.append("hour \t mean relative error \t mean absolute bias"); bwriter.write(buffer.toString()); bwriter.newLine(); for (int i = 0; i < meanError.length; i++) { buffer.delete(0, buffer.length()); buffer.append(i + 1); buffer.append('\t'); buffer.append(meanError[i]); buffer.append('\t'); buffer.append(meanBias[i]); bwriter.write(buffer.toString()); bwriter.newLine(); } bwriter.close(); } catch (IOException e) { e.printStackTrace(); } String filename = "errorGraphErrorBias.png"; try { writeChartToKmz(filename, ep.getChart()); return createOverlayBottomRight(filename, "Error Graph [Error/Bias]"); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.glaf.core.service.impl.MxTablePageServiceImpl.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public List<Object> getTableList(String tableName, String idColumn, Map<String, String> selectColumns, int begin, int pageSize, List<QueryCondition> conditions, LinkedHashMap<String, Boolean> orderByColumns) { SqlExecutor sqlExecutor = QueryUtils.getMyBatisAndConditionSql(conditions); StringBuilder buffer = new StringBuilder(); buffer.append(" select "); if (selectColumns != null && !selectColumns.isEmpty()) { Set<Entry<String, String>> entrySet = selectColumns.entrySet(); for (Entry<String, String> entry : entrySet) { String columnName = entry.getKey(); String columnLabel = entry.getValue(); if (columnName != null && columnLabel != null) { buffer.append(columnName).append(" as ").append(columnLabel); buffer.append(" , "); }//ww w. j ava 2s . c o m } buffer.delete(buffer.length() - 2, buffer.length()); buffer.append(" from ").append(tableName); } else { buffer.append(" * from ").append(tableName); } buffer.append(" where 1=1 "); String sql = buffer.toString() + sqlExecutor.getSql(); if (orderByColumns != null && !orderByColumns.isEmpty()) { buffer.delete(0, buffer.length()); buffer.append(" order by "); Set<Entry<String, Boolean>> entrySet = orderByColumns.entrySet(); for (Entry<String, Boolean> entry : entrySet) { String columnName = entry.getKey(); Boolean ordinal = entry.getValue(); if (columnName != null && ordinal != null) { buffer.append(columnName); if (ordinal.booleanValue()) { buffer.append(" asc"); } else { buffer.append(" desc"); } buffer.append(" ,"); } } if (buffer.toString().endsWith(",")) { buffer.delete(buffer.length() - 2, buffer.length()); } } sql = sql + buffer.toString(); Map<String, Object> params = new java.util.HashMap<String, Object>(); if (sqlExecutor.getParameter() instanceof Map) { params.putAll((Map) sqlExecutor.getParameter()); } logger.debug("sql:\n" + sql); logger.debug("params:" + params); params.put("queryString", sql); if (begin < 0) { begin = 0; } if (pageSize <= 0) { pageSize = Paging.DEFAULT_PAGE_SIZE; } RowBounds rowBounds = new RowBounds(begin, pageSize); List<Object> rows = sqlSession.selectList("getSqlQueryList", params, rowBounds); return rows; }
From source file:it.doqui.index.ecmengine.business.personalization.multirepository.index.lucene.RepositoryAwareADMLuceneSearcherImpl.java
/** * The definitions must provide a default value, or of not there must be a parameter to provide the value * * @param definition//from w w w . j ava 2 s .c om * @param queryParameters * @throws QueryParameterisationException */ private void checkParameters(CannedQueryDef definition, QueryParameter[] queryParameters) throws QueryParameterisationException { List<QName> missing = new ArrayList<QName>(); Set<QName> parameterQNameSet = new HashSet<QName>(); if (queryParameters != null) { for (QueryParameter parameter : queryParameters) { parameterQNameSet.add(parameter.getQName()); } } for (QueryParameterDefinition parameterDefinition : definition.getQueryParameterDefs()) { if (!parameterDefinition.hasDefaultValue()) { if (!parameterQNameSet.contains(parameterDefinition.getQName())) { missing.add(parameterDefinition.getQName()); } } } if (missing.size() > 0) { StringBuilder buffer = new StringBuilder(128); buffer.append("The query is missing values for the following parameters: "); for (QName qName : missing) { buffer.append(qName); buffer.append(", "); } buffer.delete(buffer.length() - 1, buffer.length() - 1); buffer.delete(buffer.length() - 1, buffer.length() - 1); throw new QueryParameterisationException(buffer.toString()); } }