List of usage examples for java.lang StringBuilder deleteCharAt
@Override public StringBuilder deleteCharAt(int index)
From source file:edu.arizona.kra.proposaldevelopment.dao.ojb.PropDevRoutingStateDaoOjb.java
@Override public List<SPSReviewer> findSPSReviewers(Collection<String> principalIds) throws SQLException, LookupException { LOG.debug("findSPSReviewers: personIds {}.", principalIds); List<SPSReviewer> result = new ArrayList<SPSReviewer>(); if (principalIds != null && principalIds.size() > 0) { StringBuilder query = new StringBuilder(SPS_REVIEWERS_QUERY); for (String id : principalIds) { query.append("'" + id + "',"); }//from ww w .j a v a 2 s . c o m //remove last comma query.deleteCharAt(query.length() - 1); query.append(")"); LOG.debug("findSPSReviewers: query={}", query); try (DBConnection dbc = new DBConnection(this.getPersistenceBroker(true))) { ResultSet rs = dbc.executeQuery(query.toString(), null); while (rs.next()) { SPSReviewer person = new SPSReviewer(); person.setPrincipalId(rs.getString(COL_SPS_REVIEWER_ID)); person.setFullName(rs.getString(COL_SPS_REVIEWER_NAME)); result.add(person); } } catch (SQLException sqle) { LOG.error("SQLException: " + sqle.getMessage(), sqle); throw sqle; } catch (LookupException le) { LOG.error("LookupException: " + le.getMessage(), le); throw le; } } LOG.debug("findSPSReviewers: Finished result size={}.", result.size()); return result; }
From source file:net.nym.library.http.UploadImagesRequest.java
/** * ???/* w ww . ja v a 2 s . c o m*/ * * @param url * Service net address * @param params * text content * @param files * pictures * @return String result of Service response * @throws java.io.IOException */ public static String postFile(String url, Map<String, Object> params, Map<String, File> files) throws IOException { String result = ""; String BOUNDARY = UUID.randomUUID().toString(); String PREFIX = "--", LINEND = "\r\n"; String MULTIPART_FROM_DATA = "multipart/form-data"; String CHARSET = "UTF-8"; StringBuilder sb = new StringBuilder("?"); for (Map.Entry<String, Object> entry : params.entrySet()) { // sb.append(PREFIX); // sb.append(BOUNDARY); // sb.append(LINEND); // sb.append("Content-Disposition: form-data; name=\"" // + entry.getKey() + "\"" + LINEND); // sb.append("Content-Type: text/plain; charset=" + CHARSET // + LINEND); // sb.append("Content-Transfer-Encoding: 8bit" + LINEND); // sb.append(LINEND); // sb.append(entry.getValue()); // sb.append(LINEND); // String key = entry.getKey(); // sb.append("&"); // sb.append(key).append("=").append(params.get(key)); // Log.i("%s=%s",key,params.get(key).toString()); sb.append(entry.getKey()).append("=").append(NetUtil.URLEncode(entry.getValue().toString())) .append("&"); } sb.deleteCharAt(sb.length() - 1); URL uri = new URL(url + sb.toString()); HttpURLConnection conn = (HttpURLConnection) uri.openConnection(); conn.setConnectTimeout(50000); conn.setDoInput(true);// ? conn.setDoOutput(true);// ? conn.setUseCaches(false); // ?? conn.setRequestMethod("POST"); conn.setRequestProperty("connection", "keep-alive"); conn.setRequestProperty("Charsert", "UTF-8"); conn.setRequestProperty("Content-Type", MULTIPART_FROM_DATA + ";boundary=" + BOUNDARY); // ? // StringBuilder sb = new StringBuilder(); // for (Map.Entry<String, Object> entry : params.entrySet()) { //// sb.append(PREFIX); //// sb.append(BOUNDARY); //// sb.append(LINEND); //// sb.append("Content-Disposition: form-data; name=\"" //// + entry.getKey() + "\"" + LINEND); //// sb.append("Content-Type: text/plain; charset=" + CHARSET //// + LINEND); //// sb.append("Content-Transfer-Encoding: 8bit" + LINEND); //// sb.append(LINEND); //// sb.append(entry.getValue()); //// sb.append(LINEND); // String key = entry.getKey(); // sb.append("&"); // sb.append(key).append("=").append(params.get(key)); // Log.i("%s=%s",key,params.get(key).toString()); // } DataOutputStream outStream = new DataOutputStream(conn.getOutputStream()); // outStream.write(sb.toString().getBytes()); // ? if (files != null) { for (Map.Entry<String, File> file : files.entrySet()) { StringBuilder sbFile = new StringBuilder(); sbFile.append(PREFIX); sbFile.append(BOUNDARY); sbFile.append(LINEND); /** * ?? name???key ?key ?? * filename?????? :abc.png */ sbFile.append("Content-Disposition: form-data; name=\"" + file.getKey() + "\"; filename=\"" + file.getValue().getName() + "\"" + LINEND); sbFile.append("Content-Type: application/octet-stream; charset=" + CHARSET + LINEND); sbFile.append(LINEND); Log.i(sbFile.toString()); outStream.write(sbFile.toString().getBytes()); InputStream is = new FileInputStream(file.getValue()); byte[] buffer = new byte[1024]; int len = 0; while ((len = is.read(buffer)) != -1) { outStream.write(buffer, 0, len); } is.close(); outStream.write(LINEND.getBytes()); } // ? byte[] end_data = (PREFIX + BOUNDARY + PREFIX + LINEND).getBytes(); outStream.write(end_data); } outStream.flush(); // ?? int res = conn.getResponseCode(); InputStream in = conn.getInputStream(); StringBuilder sbResult = new StringBuilder(); if (res == 200) { int ch; while ((ch = in.read()) != -1) { sbResult.append((char) ch); } } result = sbResult.toString(); outStream.close(); conn.disconnect(); return result; }
From source file:com.github.mhendred.face4j.ResponderImpl.java
/** * @see {@link Responder#doPost(URI, List)} *//*from w w w .j av a 2 s . com*/ public String doPost(final URI uri, final List<NameValuePair> params) throws FaceClientException, FaceServerException { try { URL url = uri.toURL(); StringBuilder strparams = new StringBuilder(); for (Iterator iterator = params.iterator(); iterator.hasNext();) { NameValuePair nameValuePair = (NameValuePair) iterator.next(); strparams.append(nameValuePair.getName()); strparams.append("="); strparams.append(nameValuePair.getValue()); strparams.append("&"); } strparams.deleteCharAt(strparams.length() - 1); byte[] postData = strparams.toString().getBytes(); String urlpath = url.toString(); url = new URL(urlpath + "?" + strparams.toString()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); /*connection.setRequestProperty("X-Custom-Header", "xxx"); connection.setRequestProperty("Content-Type", "application/json");*/ // POST the http body data // connection.setDoOutput(true); //connection.setRequestMethod("GET"); /*connection.setRequestProperty( "Content-Length",Integer.toString( postData.length )); DataOutputStream writer = new DataOutputStream(connection.getOutputStream()); writer.write(postData); writer.close();*/ if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { // OK BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); StringBuffer res = new StringBuffer(); String line; while ((line = reader.readLine()) != null) { res.append(line); } reader.close(); return res.toString(); } else { int resp = connection.getResponseCode(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getErrorStream())); StringBuffer res = new StringBuffer(); String line; while ((line = reader.readLine()) != null) { res.append(line); } reader.close(); return line; } } catch (IOException ioe) { throw new FaceClientException(ioe); } }
From source file:com.jfaker.framework.flow.web.TaskController.java
public void tip() { List<Task> tasks = engine.query().getActiveTasks(new QueryFilter().setOrderId(getPara(PARA_ORDERID))); StringBuilder builder = new StringBuilder(); String createTime = ""; for (Task task : tasks) { if (task.getTaskName().equalsIgnoreCase(getPara(PARA_TASKNAME))) { String[] actors = engine.query().getTaskActorsByTaskId(task.getId()); for (String actor : actors) { builder.append(actor).append(","); }// w ww. ja v a2 s.c o m createTime = task.getCreateTime(); } } if (builder.length() > 0) { builder.deleteCharAt(builder.length() - 1); } Map<String, String> data = new HashMap<String, String>(); data.put("actors", builder.toString()); data.put("createTime", createTime); renderJson(data); }
From source file:Dump.java
/** * Constri um buffer string contendo um <em>dumping</em> hexadecimal do array de * bytes especificado.//from w ww . j a v a2 s .c om * * @param data array de dados. * * @return buffer string contendo o dump hexadecimal. */ public static String dump(final byte[] data) { String eol = System.getProperty("line.separator"); StringBuilder buffer = new StringBuilder(); int offset = 0; int column = 0; StringBuilder hexDump = new StringBuilder(); StringBuilder chrDump = new StringBuilder(); for (int pos = 0; pos < data.length; pos++) { hexDump.append(hex((int) (data[pos] & 0xff), 2)); chrDump.append(chr((int) (data[pos] & 0xff))); column++; if (column > 15) { buffer.append(" ").append(hex(offset, 6)).append(" ").append(hexDump).append(" ").append(chrDump) .append(eol); column = 0; offset += 16; hexDump = new StringBuilder(); chrDump = new StringBuilder(); } else { if (column == 8) { // inclui um separador "-" entre a 8a. e 9a. colunas hexDump.append("-"); } else { // separa com 1 espao os valores hexadecimais dos bytes hexDump.append(" "); } } } if ((column != 0) && (column < 15)) { // completa a linha com espaos at a 16a. posio while (column < 16) { hexDump.append(" "); // 3 espaos chrDump.append(" "); // 1 espao column++; } // remove o ltimo espao da sequncia hexDump.deleteCharAt(hexDump.length() - 1); buffer.append(" ").append(hex(offset, 6)).append(" ").append(hexDump).append(" ").append(chrDump) .append(eol); } // inclui o rodap, indicando o total de bytes no dump buffer.append(" Dump: ").append(data.length).append(" byte(s).").append(eol); return buffer.toString(); }
From source file:hr.fer.zemris.vhdllab.service.extractor.testbench.TestbenchMetadataExtractor.java
/** * Populate a port map in testbench VHDL. * /*from w w w . j av a 2 s . c o m*/ * @param ci * a circuit interface from where to draw information. * @param vhdl * a string builder where to store testbench VHDL. */ private void populatePortMap(CircuitInterface ci, StringBuilder vhdl) { vhdl.append("uut: ").append(ci.getName()).append(" port map ( "); for (Port p : ci.getPorts()) { vhdl.append(getTestbenchSignal(p.getName())).append(", "); } vhdl.deleteCharAt(vhdl.length() - 2); // deleting last ',' vhdl.append(");\n"); }
From source file:com.fantasia.snakerflow.web.TaskController.java
@RequestMapping(value = "tip", method = RequestMethod.GET) @ResponseBody/*from ww w . ja v a2s . c o m*/ public Map<String, String> addTaskActor(String orderId, String taskName) { List<Task> tasks = facets.getEngine().query().getActiveTasks(new QueryFilter().setOrderId(orderId)); StringBuilder builder = new StringBuilder(); String createTime = ""; for (Task task : tasks) { if (task.getTaskName().equalsIgnoreCase(taskName)) { String[] actors = facets.getEngine().query().getTaskActorsByTaskId(task.getId()); for (String actor : actors) { builder.append(actor).append(","); } createTime = task.getCreateTime(); } } if (builder.length() > 0) { builder.deleteCharAt(builder.length() - 1); } Map<String, String> data = new HashMap<String, String>(); data.put("actors", builder.toString()); data.put("createTime", createTime); return data; }
From source file:de.zib.scalaris.InterOpTest.java
private static void valueToStr(final Object value, final StringBuilder sb) { if (value instanceof String) { sb.append('"'); // sb.append(((String) value).replace("\n", "\\n")); sb.append(value);//from w w w.j a v a2 s. co m sb.append('"'); } else if (value instanceof byte[]) { final byte[] bytes = ((byte[]) value); sb.append("<<"); for (final byte b : bytes) { sb.append(b); } sb.append(">>"); } else if (value instanceof Map<?, ?>) { @SuppressWarnings("unchecked") final Map<String, Object> map = ((Map<String, Object>) value); sb.append('{'); for (final Map.Entry<String, Object> entry : map.entrySet()) { valueToStr(entry.getKey(), sb); sb.append('='); valueToStr(entry.getValue(), sb); sb.append(','); } // remove last "," if (map.size() > 0) { sb.deleteCharAt(sb.length() - 1); } sb.append('}'); } else if (value instanceof List<?>) { @SuppressWarnings("unchecked") final List<Object> list = (List<Object>) value; sb.append('['); for (final Object object : list) { valueToStr(object, sb); sb.append(','); } // remove last "," if (list.size() > 0) { sb.deleteCharAt(sb.length() - 1); } sb.append(']'); } else if (value instanceof ErlangValue) { sb.append(((ErlangValue) value).value().toString()); } else { sb.append(value.toString()); } }
From source file:com.ming800.core.p.service.impl.JmenuManagerImpl.java
/** * ?JmenuJson?String//from ww w . j a v a 2 s. c o m * * @param jmenuName * @param type ?? * @return */ public String getJmenuJson(String jmenuName, Integer type) { doManager = (DoManager) ApplicationContextUtil.getApplicationContext().getBean("doManagerImpl"); Jmenu jmenu = (Jmenu) fetchJmenuMap().get(jmenuName); StringBuilder jMenuJson = new StringBuilder(500); if (jmenu.getChildren() != null && jmenu.getChildren().size() > 0) { jMenuJson.append("["); for (Jnode jnode : jmenu.getChildren()) { jMenuJson.append(this.getJnodeJson(jnode, type)); } jMenuJson.deleteCharAt(jMenuJson.length() - 1); jMenuJson.append("]"); } return jMenuJson.toString(); }
From source file:com.eucalyptus.blockstorage.HttpTransfer.java
/** * Constructs and returns the canonicalQuery string per EucaRSA-V2 specs. * @param httpBaseRequest// w w w.jav a 2 s . co m * @return */ private static String calcCanonicalQuery(HttpMethodBase httpBaseRequest) { StringBuilder canonicalQuery = new StringBuilder(); //Sort query elements, assume all values are already URL encoded String tmpQuery = httpBaseRequest.getQueryString(); HashMap<String, String> parameters = new HashMap<String, String>(); if (!Strings.isNullOrEmpty(tmpQuery)) { String[] rawQueryParams = tmpQuery.split("&"); String[] queryParamNames = new String[rawQueryParams.length]; String[] tmpKV = null; int i = 0; for (String paramKV : rawQueryParams) { tmpKV = paramKV.split("="); queryParamNames[i++] = tmpKV[0]; if (tmpKV.length == 2) { parameters.put(tmpKV[0], tmpKV[1]); } else { parameters.put(tmpKV[0], ""); } } Arrays.sort(queryParamNames); for (String paramName : queryParamNames) { canonicalQuery.append(paramName).append('='); if (parameters.get(paramName) != null) { canonicalQuery.append(parameters.get(paramName)); } else { //Single key, no value canonicalQuery.append(""); } canonicalQuery.append('&'); } if (canonicalQuery.length() > 0) { canonicalQuery.deleteCharAt(canonicalQuery.length() - 1); //Delete the trailing '&' } } return canonicalQuery.toString(); }