List of usage examples for java.lang StringBuffer delete
@Override public synchronized StringBuffer delete(int start, int end)
From source file:org.kuali.kra.proposaldevelopment.rule.event.CalculateCreditSplitEvent.java
@Override protected void logEvent() { StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), ".")); logMessage.append(" with "); for (ProposalPerson person : ((ProposalDevelopmentDocument) getDocument()).getDevelopmentProposal() .getProposalPersons()) {/*from w w w . j a v a2 s . c o m*/ logMessage.append(person.toString()); logMessage.append(", "); } if (logMessage.substring(logMessage.length() - 2).equals(", ")) { logMessage.delete(logMessage.length() - 2, logMessage.length()); } debug(logMessage); }
From source file:org.anyframe.oden.admin.common.Cmd.java
private void parse(String line) { String[] args = CommonUtil.split(line); if (args.length == 0 || isOption(args[0])) { logger.error("Syntax Error command"); }//from w w w . ja va 2 s . c o m int idx = 0; name = args[idx++]; if (idx < args.length && !isOption(args[idx])) { action = args[idx++]; if (idx < args.length && !isOption(args[idx])) { actionArg = args[idx++]; } } if (idx < args.length) { if (!isOption(args[idx])) { logger.error("Syntax Error command"); } Opt opt = new Opt(); // collect the others StringBuffer ops = new StringBuffer(); for (int i = idx; i < args.length; i++) { if (args[i].startsWith("-")) { if (ops.length() != 0) { opt.clear(); opt.makeOpt(ops.toString()); options.add(opt); ops.delete(0, ops.length()); } ops.append(args[i].substring(1) + " "); } else { ops.append("\"" + args[i] + "\" "); } } if (ops.length() != 0) { options.add(new Opt(ops.toString())); } } }
From source file:de.tudarmstadt.ukp.dkpro.wsd.wsi.io.AMBIENTReader.java
private void downloadHTMLPage(JCas jCas, final Result result) { try {// w w w . j a va 2 s . c o m URL inputURL = new URL(URLDecoder.decode(result.url)); URLConnection conn = inputURL.openConnection(); conn.setReadTimeout(30000); InputStream is = conn.getInputStream(); String text; CharsetDetector detector = new CharsetDetector(); detector.enableInputFilter(true); try { text = IOUtils.toString(detector.getReader(is, null)); } catch (Exception e) { text = IOUtils.toString(is); } StringBuffer cleanedText = new StringBuffer(Jsoup.parse(text).text()); int index = XMLUtils.checkForNonXmlCharacters(cleanedText.toString(), false); while (index > -1) { cleanedText.delete(index, index + 1); index = XMLUtils.checkForNonXmlCharacters(cleanedText.toString(), false); } if (StringUtils.isAsciiPrintable(cleanedText.toString())) { jCas.setDocumentText(result.text + " " + cleanedText.toString()); } else { jCas.setDocumentText(result.text); } } catch (Exception e) { getLogger().warn("Connection to " + result.url + " timed out/failed, using snippet only"); e.printStackTrace(); getLogger().warn(e); jCas.setDocumentText(result.text); } }
From source file:org.eclipse.jubula.client.core.persistence.NodePM.java
/** * /*from www.j a v a 2s . co m*/ * @param specTcGuid The GUID of the reused test case. * @param parentProjectIds All returned test cases will have one of these as * their project parent ID. * @param s The session into which the test cases will be loaded. * @return list of test cases. */ @SuppressWarnings("unchecked") private static synchronized List<IExecTestCasePO> getExecTestCasesFor(String specTcGuid, List<Long> parentProjectIds, EntityManager s) { StringBuffer queryBuffer = new StringBuffer( "select ref from ExecTestCasePO as ref where ref.specTestCaseGuid = :specTcGuid and ("); //$NON-NLS-1$ for (long id : parentProjectIds) { queryBuffer.append("ref.hbmParentProjectId = " + id + " or "); //$NON-NLS-1$ //$NON-NLS-2$ } // Remove the last " or ", and close the statement queryBuffer.delete(queryBuffer.length() - 4, queryBuffer.length()); queryBuffer.append(")"); //$NON-NLS-1$ Query q = s.createQuery(queryBuffer.toString()); q.setParameter("specTcGuid", specTcGuid); //$NON-NLS-1$ List<IExecTestCasePO> execTcList = q.getResultList(); return execTcList; }
From source file:org.kuali.coeus.propdev.impl.person.SaveKeyPersonEvent.java
/** * Logs the event type and some information about the associated accountingLine */// w w w . j a v a2 s .c o m protected void logEvent() { StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), ".")); logMessage.append(" with "); for (ProposalPerson person : ((ProposalDevelopmentDocument) getDocument()).getDevelopmentProposal() .getProposalPersons()) { logMessage.append(person.toString()); logMessage.append(", "); } if (logMessage.substring(logMessage.length() - 2).equals(", ")) { logMessage.delete(logMessage.length() - 2, logMessage.length()); } LOG.debug(logMessage); }
From source file:org.owasp.jbrofuzz.graph.canvas.StatusCodeChart.java
private String calculateValue(final File inputFile) { if (inputFile.isDirectory()) { // return -1; return ERROR; }/* w w w. j av a 2s . c o m*/ String status = ERROR; BufferedReader inbuffReader = null; try { inbuffReader = new BufferedReader(new FileReader(inputFile)); final StringBuffer one = new StringBuffer(MAX_CHARS); int counter = 0; int got; while (((got = inbuffReader.read()) > 0) && (counter < MAX_CHARS)) { one.append((char) got); counter++; } inbuffReader.close(); one.delete(0, one.indexOf("\n--\n") + 4); one.delete(one.indexOf("\n--"), one.length()); // status = Integer.parseInt(one.toString()); status = one.toString(); } catch (final IOException e1) { // return -2; return ERROR; } catch (final StringIndexOutOfBoundsException e2) { // return -3; return ERROR; } catch (final NumberFormatException e3) { // return 0; return ERROR; } finally { IOUtils.closeQuietly(inbuffReader); } return status; }
From source file:org.apache.lucene.analysis.de.GermanStemmer.java
/** * suffix stripping (stemming) on the current term. The stripping is reduced * to the seven "base" suffixes "e", "s", "n", "t", "em", "er" and * "nd", * from which all regular suffixes are build of. The simplification causes * some overstemming, and way more irregular stems, but still provides * unique. discriminators in the most of those cases. The algorithm is * context free, except of the length restrictions. *//*w ww . j a v a2s . c o m*/ private void strip(StringBuffer buffer) { boolean doMore = true; while (doMore && buffer.length() > 3) { if ((buffer.length() + substCount > 5) && buffer.substring(buffer.length() - 2, buffer.length()).equals("nd")) { buffer.delete(buffer.length() - 2, buffer.length()); } else if ((buffer.length() + substCount > 4) && buffer.substring(buffer.length() - 2, buffer.length()).equals("em")) { buffer.delete(buffer.length() - 2, buffer.length()); } else if ((buffer.length() + substCount > 4) && buffer.substring(buffer.length() - 2, buffer.length()).equals("er")) { buffer.delete(buffer.length() - 2, buffer.length()); } else if (buffer.charAt(buffer.length() - 1) == 'e') { buffer.deleteCharAt(buffer.length() - 1); } else if (buffer.charAt(buffer.length() - 1) == 's') { buffer.deleteCharAt(buffer.length() - 1); } else if (buffer.charAt(buffer.length() - 1) == 'n') { buffer.deleteCharAt(buffer.length() - 1); } // "t" occurs only as suffix of verbs. else if (buffer.charAt(buffer.length() - 1) == 't') { buffer.deleteCharAt(buffer.length() - 1); } else { doMore = false; } } }
From source file:org.kuali.kra.proposaldevelopment.rule.event.SaveKeyPersonEvent.java
/** * Logs the event type and some information about the associated accountingLine */// w w w . j a v a2s . c o m protected void logEvent() { StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), ".")); logMessage.append(" with "); for (ProposalPerson person : ((ProposalDevelopmentDocument) getDocument()).getDevelopmentProposal() .getProposalPersons()) { logMessage.append(person.toString()); logMessage.append(", "); } if (logMessage.substring(logMessage.length() - 2).equals(", ")) { logMessage.delete(logMessage.length() - 2, logMessage.length()); } debug(logMessage); }
From source file:org.vfny.geoserver.wfs.servlets.TestWfsPost.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w ww . j a v a 2 s . c o m*/ * * @param request servlet request * @param response servlet response * * @throws ServletException DOCUMENT ME! * @throws IOException DOCUMENT ME! */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String requestString = request.getParameter("body"); String urlString = request.getParameter("url"); boolean doGet = (requestString == null) || requestString.trim().equals(""); if ((urlString == null)) { PrintWriter out = response.getWriter(); StringBuffer urlInfo = request.getRequestURL(); if (urlInfo.indexOf("?") != -1) { urlInfo.delete(urlInfo.indexOf("?"), urlInfo.length()); } String geoserverUrl = urlInfo.substring(0, urlInfo.indexOf("/", 8)) + request.getContextPath(); response.setContentType("text/html"); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"); out.println("<html>"); out.println("<head>"); out.println("<title>TestWfsPost</title>"); out.println("</head>"); out.println("<script language=\"JavaScript\">"); out.println("function doNothing() {"); out.println("}"); out.println("function sendRequest() {"); out.println(" if (checkURL()==true) {"); out.print(" document.frm.action = \""); out.print(urlInfo.toString()); out.print("\";\n"); out.println(" document.frm.target = \"_blank\";"); out.println(" document.frm.submit();"); out.println(" }"); out.println("}"); out.println("function checkURL() {"); out.println(" if (document.frm.url.value==\"\") {"); out.println(" alert(\"Please give URL before you sumbit this form!\");"); out.println(" return false;"); out.println(" } else {"); out.println(" return true;"); out.println(" }"); out.println("}"); out.println("function clearRequest() {"); out.println("document.frm.body.value = \"\";"); out.println("}"); out.println("</script>"); out.println("<body>"); out.println("<form name=\"frm\" action=\"JavaScript:doNothing()\" method=\"POST\">"); out.println("<table align=\"center\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\">"); out.println("<tr>"); out.println("<td><b>URL:</b></td>"); out.print("<td><input name=\"url\" value=\""); out.print(geoserverUrl); out.print("/wfs/GetFeature\" size=\"70\" MAXLENGTH=\"100\"/></td>\n"); out.println("</tr>"); out.println("<tr>"); out.println("<td><b>Request:</b></td>"); out.println("<td><textarea cols=\"60\" rows=\"24\" name=\"body\"></textarea></td>"); out.println("</tr>"); out.println("</table>"); out.println("<table align=\"center\">"); out.println("<tr>"); out.println("<td><input type=\"button\" value=\"Clear\" onclick=\"clearRequest()\"></td>"); out.println("<td><input type=\"button\" value=\"Submit\" onclick=\"sendRequest()\"></td>"); out.println("<td></td>"); out.println("</tr>"); out.println("</table>"); out.println("</form>"); out.println("</body>"); out.println("</html>"); out.close(); } else { response.setContentType("application/xml"); BufferedReader xmlIn = null; PrintWriter xmlOut = null; StringBuffer sbf = new StringBuffer(); String resp = null; try { URL u = new URL(urlString); java.net.HttpURLConnection acon = (java.net.HttpURLConnection) u.openConnection(); acon.setAllowUserInteraction(false); if (!doGet) { //System.out.println("set to post"); acon.setRequestMethod("POST"); acon.setRequestProperty("Content-Type", "application/xml"); } else { //System.out.println("set to get"); acon.setRequestMethod("GET"); } acon.setDoOutput(true); acon.setDoInput(true); acon.setUseCaches(false); //SISfixed - if there was authentication info in the request, // Pass it along the way to the target URL //DJB: applied patch in GEOS-335 String authHeader = request.getHeader("Authorization"); String username = request.getParameter("username"); if ((username != null) && !username.trim().equals("")) { String password = request.getParameter("password"); String up = username + ":" + password; byte[] encoded = Base64.encodeBase64(up.getBytes()); authHeader = "Basic " + new String(encoded); } if (authHeader != null) { acon.setRequestProperty("Authorization", authHeader); } if (!doGet) { xmlOut = new PrintWriter(new BufferedWriter(new OutputStreamWriter(acon.getOutputStream()))); xmlOut = new java.io.PrintWriter(acon.getOutputStream()); xmlOut.write(requestString); xmlOut.flush(); } // Above 400 they're all error codes, see: // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html if (acon.getResponseCode() >= 400) { PrintWriter out = response.getWriter(); out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); out.println("<servlet-exception>"); out.println("HTTP response: " + acon.getResponseCode() + "\n" + URLDecoder.decode(acon.getResponseMessage(), "UTF-8")); out.println("</servlet-exception>"); out.close(); } else { // xmlIn = new BufferedReader(new InputStreamReader( // acon.getInputStream())); // String line; // System.out.println("got encoding from acon: " // + acon.getContentType()); response.setContentType(acon.getContentType()); response.setHeader("Content-disposition", acon.getHeaderField("Content-disposition")); OutputStream output = response.getOutputStream(); int c; InputStream in = acon.getInputStream(); while ((c = in.read()) != -1) output.write(c); in.close(); output.close(); } //while ((line = xmlIn.readLine()) != null) { // out.print(line); //} } catch (Exception e) { PrintWriter out = response.getWriter(); out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); out.println("<servlet-exception>"); out.println(e.toString()); out.println("</servlet-exception>"); out.close(); } finally { try { if (xmlIn != null) { xmlIn.close(); } } catch (Exception e1) { PrintWriter out = response.getWriter(); out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); out.println("<servlet-exception>"); out.println(e1.toString()); out.println("</servlet-exception>"); out.close(); } try { if (xmlOut != null) { xmlOut.close(); } } catch (Exception e2) { PrintWriter out = response.getWriter(); out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); out.println("<servlet-exception>"); out.println(e2.toString()); out.println("</servlet-exception>"); out.close(); } } } }
From source file:immf.Util.java
public static String encodeParameter(String name, String value, String encoding, String lang) { StringBuffer result = new StringBuffer(); StringBuffer encodedPart = new StringBuffer(); boolean needWriteCES = !isAllAscii(value); boolean CESWasWritten = false; boolean encoded; boolean needFolding = false; int sequenceNo = 0; int column;/*from ww w .j a v a 2s .c o m*/ while (value.length() > 0) { // index of boundary of ascii/non ascii int lastIndex; boolean isAscii = value.charAt(0) < 0x80; for (lastIndex = 1; lastIndex < value.length(); lastIndex++) { if (value.charAt(lastIndex) < 0x80) { if (!isAscii) break; } else { if (isAscii) break; } } if (lastIndex != value.length()) needFolding = true; RETRY: while (true) { encodedPart.delete(0, encodedPart.length()); String target = value.substring(0, lastIndex); byte[] bytes; try { if (isAscii) { bytes = target.getBytes("us-ascii"); } else { bytes = target.getBytes(encoding); } } catch (UnsupportedEncodingException e) { bytes = target.getBytes(); // use default encoding encoding = MimeUtility.mimeCharset(MimeUtility.getDefaultJavaCharset()); } encoded = false; // It is not strict. column = name.length() + 7; // size of " " and "*nn*=" and ";" for (int i = 0; i < bytes.length; i++) { if (bytes[i] > ' ' && bytes[i] < 'z' && HeaderTokenizer.MIME.indexOf((char) bytes[i]) < 0) { encodedPart.append((char) bytes[i]); column++; } else { encoded = true; encodedPart.append('%'); String hex = Integer.toString(bytes[i] & 0xff, 16); if (hex.length() == 1) { encodedPart.append('0'); } encodedPart.append(hex); column += 3; } if (column > 76) { needFolding = true; lastIndex /= 2; continue RETRY; } } result.append(";\r\n ").append(name); if (needFolding) { result.append('*').append(sequenceNo); sequenceNo++; } if (!CESWasWritten && needWriteCES) { result.append("*="); CESWasWritten = true; result.append(encoding).append('\''); if (lang != null) result.append(lang); result.append('\''); } else if (encoded) { result.append("*="); } else { result.append('='); } result.append(new String(encodedPart)); value = value.substring(lastIndex); break; } } return new String(result); }