List of usage examples for java.lang StringBuffer setLength
@Override public synchronized void setLength(int newLength)
From source file:com.tremolosecurity.unison.openshiftv3.OpenShiftTarget.java
public String callWSPut(String token, HttpCon con, String uri, String json) throws IOException, ClientProtocolException { StringBuffer b = new StringBuffer(); b.append(this.url).append(uri); HttpPut put = new HttpPut(b.toString()); b.setLength(0); b.append("Bearer ").append(token); put.addHeader(new BasicHeader("Authorization", "Bearer " + token)); StringEntity str = new StringEntity(json, ContentType.APPLICATION_JSON); put.setEntity(str);/* www. j a v a 2 s .c o m*/ HttpResponse resp = con.getHttp().execute(put); json = EntityUtils.toString(resp.getEntity()); return json; }
From source file:com.tremolosecurity.unison.openshiftv3.OpenShiftTarget.java
public String callWSDelete(String token, HttpCon con, String uri) throws IOException, ClientProtocolException { StringBuffer b = new StringBuffer(); b.append(this.url).append(uri); HttpDelete get = new HttpDelete(b.toString()); b.setLength(0); b.append("Bearer ").append(token); get.addHeader(new BasicHeader("Authorization", "Bearer " + token)); HttpResponse resp = con.getHttp().execute(get); String json = EntityUtils.toString(resp.getEntity()); return json;/*www. java 2s .c om*/ }
From source file:com.tremolosecurity.unison.openshiftv3.OpenShiftTarget.java
public String callWSPost(String token, HttpCon con, String uri, String json) throws IOException, ClientProtocolException { StringBuffer b = new StringBuffer(); b.append(this.url).append(uri); HttpPost put = new HttpPost(b.toString()); b.setLength(0); b.append("Bearer ").append(token); put.addHeader(new BasicHeader("Authorization", "Bearer " + token)); StringEntity str = new StringEntity(json, ContentType.APPLICATION_JSON); put.setEntity(str);/*from w ww . j a va 2 s . c om*/ HttpResponse resp = con.getHttp().execute(put); json = EntityUtils.toString(resp.getEntity()); return json; }
From source file:org.nmrfx.processor.gui.spectra.DrawSpectrum.java
boolean getContours(DatasetAttributes fileData, Contour[] contours, int iChunk, double[] offset, float[] levels) throws IOException { StringBuffer chunkLabel = new StringBuffer(); chunkLabel.setLength(0); int[][] apt = new int[fileData.getDataset().getNDim()][2]; int fileStatus = fileData.getMatrixRegion(iChunk, viewPar.mode, apt, offset, chunkLabel); if (fileStatus != 0) { return false; }/* w ww . ja v a 2 s .c o m*/ float[][] z = null; try { z = fileData.Matrix2(fileData.mChunk, chunkLabel.toString(), apt); } catch (IOException ioE) { throw ioE; } if (z == null) { return false; } for (int iPosNeg = 0; iPosNeg < 2; iPosNeg++) { if ((iPosNeg == 0) && !fileData.getPos()) { continue; } else if ((iPosNeg == 1) && !fileData.getNeg()) { continue; } contours[iPosNeg].setLineCount(0); if (checkLevels(z, iPosNeg, levels)) { if (contours[iPosNeg] != null) { if (!contours[iPosNeg].contour(levels, z)) { contours[iPosNeg].xOffset = offset[0] + fileData.ptd[0][0]; contours[iPosNeg].yOffset = offset[1] + fileData.ptd[1][0]; } } } } return true; }
From source file:org.apache.ode.bpel.compiler.v1.xpath20.XPath20ExpressionCompilerImpl.java
/** * Returns the list of variable references in the given XPath expression * that may not have been resolved properly, which is the case especially * if the expression contains a function, which short circuited the evaluation. * // ww w .j av a 2s . co m * @param xpathStr * @return list of variable expressions that may not have been resolved properly */ private List<String> extractVariableExprs(String xpathStr) { ArrayList<String> variableExprs = new ArrayList<String>(); int firstVariable = xpathStr.indexOf("$"), lastVariable = xpathStr.lastIndexOf("$"), firstFunction = xpathStr.indexOf("("); if ((firstVariable > 0 && // the xpath references a variable firstFunction > 0) || // the xpath contains a function (firstVariable < lastVariable)) { // the xpath references multiple variables // most likely, the variable reference has not been resolved, so make that happen StringBuffer variableExpr = new StringBuffer(); boolean quoted = false, doubleQuoted = false, variable = false; Name11Checker nameChecker = Name11Checker.getInstance(); for (int index = 0; index < xpathStr.length(); index++) { char ch = xpathStr.charAt(index); if (ch == '\'') { quoted = !quoted; } if (ch == '\"') { doubleQuoted = !doubleQuoted; } if (quoted || doubleQuoted) { continue; } if (ch == '$') { variable = true; variableExpr.setLength(0); variableExpr.append(ch); } else { if (variable) { variableExpr.append(ch); // in the name is qualified, don't check if its a qname when we're at the ":" character if (ch == ':') { continue; } if (index == xpathStr.length() || !nameChecker.isQName(variableExpr.substring(1))) { variable = false; variableExpr.setLength(variableExpr.length() - 1); variableExprs.add(variableExpr.toString()); } } } } } return variableExprs; }
From source file:edu.isi.misd.tagfiler.upload.FileUploadImplementation.java
/** * Sets the files to be uploaded on the Web Page. * // w w w. j a v a 2 s . c o m * @param filesList * the list of files */ public void addFilesToList(List<String> filesList) { if (filesList == null) throw new IllegalArgumentException("" + filesList); StringBuffer buffer = new StringBuffer(); for (String file : filesList) { buffer.append(file).append("<br/>"); } if (buffer.length() > 0) { buffer.setLength(buffer.length() - "<br/>".length()); } applet.eval("setFiles", buffer.toString().replaceAll("\\\\", "\\\\\\\\")); }
From source file:cn.knet.showcase.demos.servletproxy.ProxyServlet.java
/** For a redirect response from the target server, this translates {@code theUrl} to redirect to * and translates it to one the original client can use. */ protected String rewriteUrlFromResponse(HttpServletRequest servletRequest, String theUrl) { //TODO document example paths final String targetUri = getTargetUri(servletRequest); if (theUrl.startsWith(targetUri)) { /*-//from www . j av a 2 s . c o m * The URL points back to the back-end server. * Instead of returning it verbatim we replace the target path with our * source path in a way that should instruct the original client to * request the URL pointed through this Proxy. * We do this by taking the current request and rewriting the path part * using this servlet's absolute path and the path from the returned URL * after the base target URL. */ StringBuffer curUrl = servletRequest.getRequestURL();//no query int pos; // Skip the protocol part if ((pos = curUrl.indexOf("://")) >= 0) { // Skip the authority part // + 3 to skip the separator between protocol and authority if ((pos = curUrl.indexOf("/", pos + 3)) >= 0) { // Trim everything after the authority part. curUrl.setLength(pos); } } // Context path starts with a / if it is not blank curUrl.append(servletRequest.getContextPath()); // Servlet path starts with a / if it is not blank curUrl.append(servletRequest.getServletPath()); curUrl.append(theUrl, targetUri.length(), theUrl.length()); theUrl = curUrl.toString(); } return theUrl; }
From source file:com.digitalpebble.storm.crawler.protocol.http.HttpResponse.java
private void parseHeaders(PushbackInputStream in, StringBuffer line) throws IOException, HttpException { while (readLine(in, line, true) != 0) { // handle HTTP responses with missing blank line after headers int pos;//from w w w. ja v a 2 s .c o m if (((pos = line.indexOf("<!DOCTYPE")) != -1) || ((pos = line.indexOf("<HTML")) != -1) || ((pos = line.indexOf("<html")) != -1)) { in.unread(line.substring(pos).getBytes(StandardCharsets.UTF_8)); line.setLength(pos); try { // TODO: (CM) We don't know the header names here // since we're just handling them generically. It would // be nice to provide some sort of mapping function here // for the returned header names to the standard metadata // names in the ParseData class processHeaderLine(line); } catch (Exception e) { // fixme: HttpProtocol.LOGGER.warn("Error: ", e); } return; } processHeaderLine(line); } }
From source file:org.eclipse.orion.internal.server.servlets.xfer.ClientImport.java
private byte[] readMultiPartChunk(ServletInputStream requestStream, String contentType) throws IOException { //fast forward stream past multi-part header int boundaryOff = contentType.indexOf("boundary="); //$NON-NLS-1$ String boundary = contentType.substring(boundaryOff + 9); BufferedReader reader = new BufferedReader(new InputStreamReader(requestStream, "ISO-8859-1")); //$NON-NLS-1$ StringBuffer out = new StringBuffer(); //skip headers up to the first blank line String line = reader.readLine(); while (line != null && line.length() > 0) line = reader.readLine();/*from ww w.j ava 2 s . c o m*/ //now process the file char[] buf = new char[1000]; int read; while ((read = reader.read(buf)) > 0) { out.append(buf, 0, read); } //remove the boundary from the output (end of input is \r\n--<boundary>--\r\n) out.setLength(out.length() - (boundary.length() + 8)); return out.toString().getBytes("ISO-8859-1"); //$NON-NLS-1$ }
From source file:com.sun.faban.harness.webclient.XFormServlet.java
/** * A get request starts a new form.//from w ww . ja va2 s . c o m * * @param request The servlet request * @param response The servlet response * @throws ServletException Error in request handling * @throws IOException Error doing other IO */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(true); Adapter adapter = null; String templateFile = (String) session.getAttribute("faban.submit.template"); String styleSheet = (String) session.getAttribute("faban.submit.stylesheet"); String srcURL = new File(templateFile).toURI().toString(); logger.finer("benchmark.template: " + srcURL); session.removeAttribute("faban.submit.template"); session.removeAttribute("faban.submit.stylesheet"); try { String requestURI = request.getRequestURI(); String formURI = null; String contextPath = request.getContextPath(); String benchPath = contextPath + "/bm_submit/"; if (requestURI.startsWith(benchPath)) { int idx = requestURI.indexOf('/', benchPath.length()); String benchName = requestURI.substring(benchPath.length(), idx); String formName = requestURI.substring(idx + 1); formURI = com.sun.faban.harness.common.Config.FABAN_HOME + "benchmarks/" + benchName + "/META-INF/" + formName; } else { StringBuffer buffer = new StringBuffer(request.getScheme()); buffer.append("://"); buffer.append(request.getServerName()); buffer.append(":"); buffer.append(request.getServerPort()); buffer.append(request.getContextPath()); buffer.append(request.getParameter("form")); formURI = buffer.toString(); } if (formURI == null) { throw new IOException("Resource not found: " + formURI); } logger.finer("Form URI: " + formURI); String css = request.getParameter("css"); String actionURL = response.encodeURL(request.getRequestURI()); logger.finer("actionURL: " + actionURL); // Find the base URL used by Faban. We do not use Config.FABAN_URL // because this base URL can vary by the interface name the Faban // master is accessed in this session. Otherwise it is identical. StringBuffer baseURL = request.getRequestURL(); int uriLength = baseURL.length() - requestURI.length() + contextPath.length(); baseURL.setLength(++uriLength); // Add the ending slash adapter = new Adapter(); if (configFile != null && configFile.length() > 0) adapter.setConfigPath(configFile); File xsl = null; if (styleSheet != null) xsl = new File(styleSheet); if (xsl != null && xsl.exists()) { adapter.xslPath = xsl.getParent(); adapter.stylesheet = xsl.getName(); } else { adapter.xslPath = xsltDir; adapter.stylesheet = "faban.xsl"; } adapter.baseURI = baseURL.toString(); adapter.formURI = formURI; adapter.actionURL = actionURL; adapter.beanCtx.put("chiba.web.uploadDir", uploadDir); adapter.beanCtx.put("chiba.useragent", request.getHeader("User-Agent")); adapter.beanCtx.put("chiba.web.request", request); adapter.beanCtx.put("chiba.web.session", session); adapter.beanCtx.put("benchmark.template", srcURL); if (css != null) { adapter.CSSFile = css; logger.fine("using css stylesheet: " + css); } Map servletMap = new HashMap(); servletMap.put(ChibaAdapter.SESSION_ID, session.getId()); adapter.beanCtx.put(ChibaAdapter.SUBMISSION_RESPONSE, servletMap); Enumeration params = request.getParameterNames(); while (params.hasMoreElements()) { String s = (String) params.nextElement(); //store all request-params we don't use in the beanCtx map if (!(s.equals("form") || s.equals("xslt") || s.equals("css") || s.equals("action_url"))) { String value = request.getParameter(s); adapter.beanCtx.put(s, value); logger.finer("added request param '" + s + "' to beanCtx"); } } adapter.init(); adapter.execute(); response.setContentType("text/html"); PrintWriter out = response.getWriter(); adapter.generator.setOutput(out); adapter.buildUI(); session.setAttribute("chiba.adapter", adapter); out.close(); } catch (Exception e) { logger.log(Level.SEVERE, "Exception processing XForms", e); shutdown(adapter, session, e, request, response); } }