List of usage examples for java.lang StringBuffer charAt
@Override public synchronized char charAt(int index)
From source file:ORG.oclc.oai.server.catalog.AbstractCatalog.java
/** * Convert the requested 'until' paramter to the finest granularity supported by this repository * // w ww . j av a 2 s . c om * @exception BadArgumentException one or more of the arguments are bad. */ public String toFinestUntil(String until) throws BadArgumentException { if (StringUtils.isEmpty(until)) { return ""; } if (until.length() == VALID_GRANULARITIES[supportedGranularityOffset].length()) { if (!isValidGranularity(until)) { throw new BadArgumentException(); } return until; } if (until.length() > VALID_GRANULARITIES[supportedGranularityOffset].length()) { throw new BadArgumentException(); } StringBuffer sb = new StringBuffer(until); if (sb.charAt(sb.length() - 1) == 'Z') { sb.setLength(sb.length() - 1); } if (sb.length() < VALID_GRANULARITIES[0].length()) { while (sb.length() < 4) { sb.append("9"); } switch (sb.length()) { case 4: // YYYY sb.append("-"); case 5: // YYYY- sb.append("12"); case 7: // YYYY-MM sb.append("-"); case 8: // YYYY-MM- sb.append("31"); break; case 6: // YYYY-M case 9: // YYYY-MM-D throw new BadArgumentException(); } } until = sb.toString(); if (until.length() == VALID_GRANULARITIES[supportedGranularityOffset].length()) { if (!isValidGranularity(until)) { throw new BadArgumentException(); } return until; } if (sb.length() < VALID_GRANULARITIES[1].length()) { switch (sb.length()) { case 10: // YYYY-MM-DD sb.append("T"); case 11: // YYYY-MM-DDT sb.append("23"); case 13: // YYYY-MM-DDThh sb.append(":"); case 14: // YYYY-MM-DDThh: sb.append("59"); // case 16: // YYYY-MM-DDThh:mm // sb.append("Z"); // break; // case 12: // YYYY-MM-DDTh // case 15: // YYYY-MM-DDThh:m // throw new BadGranularityException(); // } // } // until = sb.toString(); // if (until.length() == // VALID_GRANULARITIES[supportedGranularityOffset].length()) { // if (!isValidGranularity(until)) // throw new BadGranularityException(); // return until; // } // if (sb.charAt(sb.length()-1) == 'Z') // sb.setLength(sb.length()-1); // remove the trailing 'Z' // if (sb.length() < VALID_GRANULARITIES[2].length()) { // switch (sb.length()) { case 16: // YYYY-MM-DDThh:mm sb.append(":"); case 17: // YYYY-MM-DDThh:mm: sb.append("59"); case 19: // YYYY-MM-DDThh:mm:ss sb.append("Z"); break; case 18: // YYYY-MM-DDThh:mm:s throw new BadArgumentException(); } } // until = sb.toString(); // if (until.length() == VALID_GRANULARITIES[supportedGranularityOffset].length()) { // if (!isValidGranularity(until)) // throw new BadGranularityException(); // return until; // } // if (sb.charAt(sb.length()-1) == 'Z') // sb.setLength(sb.length()-1); // remove the trailing 'Z' // switch (sb.length()) { // case 19: // YYYY-MM-DDThh:mm:ss // sb.append("."); // case 20: // YYYY-MM-DDThh:mm:ss. // sb.append("0"); // case 21: // YYYY-MM-DDThh:mm:ss.s // sb.append("Z"); // break; // } until = sb.toString(); if (!isValidGranularity(until)) { throw new BadArgumentException(); } return until; }
From source file:org.apache.velocity.util.ExtProperties.java
/** * Inserts a backslash before every comma and backslash. *///from w w w . j a va 2 s .com private static String escape(String s) { StringBuffer buf = new StringBuffer(s); for (int i = 0; i < buf.length(); i++) { char c = buf.charAt(i); if (c == ',' || c == '\\') { buf.insert(i, '\\'); i++; } } return buf.toString(); }
From source file:org.apache.velocity.util.ExtProperties.java
/** * Removes a backslash from every pair of backslashes. *//*from w w w . j ava2s . co m*/ private static String unescape(String s) { StringBuffer buf = new StringBuffer(s); for (int i = 0; i < buf.length() - 1; i++) { char c1 = buf.charAt(i); char c2 = buf.charAt(i + 1); if (c1 == '\\' && c2 == '\\') { buf.deleteCharAt(i); } } return buf.toString(); }
From source file:org.apache.nutch.protocol.htmlunit.HttpResponse.java
private void processHeaderLine(StringBuffer line) throws IOException, HttpException { int colonIndex = line.indexOf(":"); // key is up to colon if (colonIndex == -1) { int i;/*w w w . j a v a 2s. c om*/ for (i = 0; i < line.length(); i++) if (!Character.isWhitespace(line.charAt(i))) break; if (i == line.length()) return; throw new HttpException("No colon in header:" + line); } String key = line.substring(0, colonIndex); int valueStart = colonIndex + 1; // skip whitespace while (valueStart < line.length()) { int c = line.charAt(valueStart); if (c != ' ' && c != '\t') break; valueStart++; } String value = line.substring(valueStart); headers.set(key, value); }
From source file:org.latticesoft.util.container.MapKey.java
public int compareTo(Object o) { if (!(o instanceof MapKey)) { return 0; }/*from w w w . j a v a2 s . c o m*/ MapKey that = (MapKey) o; StringBuffer sb1 = new StringBuffer(); StringBuffer sb2 = new StringBuffer(); // sort the key in order ArrayList a = new ArrayList(); Iterator iter = null; a.clear(); a.addAll(this.getMap().keySet()); Collections.sort(a); iter = a.iterator(); sb1.append("{"); while (iter.hasNext()) { Object key = iter.next(); Object value = this.getMap().get(key); sb1.append(key).append("=").append(value).append(","); } if (sb1.charAt(sb1.length() - 1) == ',') { sb1.deleteCharAt(sb1.length() - 1); } sb1.append("}"); a.clear(); a.addAll(that.getMap().keySet()); Collections.sort(a); iter = a.iterator(); sb2.append("{"); while (iter.hasNext()) { Object key = iter.next(); Object value = that.getMap().get(key); sb2.append(key).append("=").append(value).append(","); } if (sb2.charAt(sb2.length() - 1) == ',') { sb2.deleteCharAt(sb2.length() - 1); } sb2.append("}"); //if (log.isInfoEnabled()) { log.info(sb1); } //if (log.isInfoEnabled()) { log.info(sb2); } return sb1.toString().compareTo(sb2.toString()); }
From source file:com.avricot.prediction.utils.Steemer.java
/** * Retrieve the "R zone" (1 or 2 depending on the buffer) and return the corresponding string<br> * "R is the region after the first non-vowel following a vowel * or is the null region at the end of the word if there is no such non-vowel"<br> * @param buffer java.lang.StringBuffer - the in buffer * @return java.lang.String - the resulting string *//*from w ww . j ava2s. co m*/ private String retrieveR(StringBuffer buffer) { int len = buffer.length(); int pos = -1; for (int c = 0; c < len; c++) { if (isVowel(buffer.charAt(c))) { pos = c; break; } } if (pos > -1) { int consonne = -1; for (int c = pos; c < len; c++) { if (!isVowel(buffer.charAt(c))) { consonne = c; break; } } if (consonne > -1 && (consonne + 1) < len) return buffer.substring(consonne + 1, len); else return null; } else return null; }
From source file:hudson.model.DirectoryBrowserSupport.java
private void serveFile(StaplerRequest req, StaplerResponse rsp, VirtualFile root, String icon, boolean serveDirIndex) throws IOException, ServletException, InterruptedException { // handle form submission String pattern = req.getParameter("pattern"); if (pattern == null) pattern = req.getParameter("path"); // compatibility with Hudson<1.129 if (pattern != null && !Util.isAbsoluteUri(pattern)) {// avoid open redirect rsp.sendRedirect2(pattern);// w w w . j a va 2 s .com return; } String path = getPath(req); if (path.replace('\\', '/').indexOf("/../") != -1) { // don't serve anything other than files in the artifacts dir rsp.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } // split the path to the base directory portion "abc/def/ghi" which doesn't include any wildcard, // and the GLOB portion "**/*.xml" (the rest) StringBuilder _base = new StringBuilder(); StringBuilder _rest = new StringBuilder(); int restSize = -1; // number of ".." needed to go back to the 'base' level. boolean zip = false; // if we are asked to serve a zip file bundle boolean plain = false; // if asked to serve a plain text directory listing { boolean inBase = true; StringTokenizer pathTokens = new StringTokenizer(path, "/"); while (pathTokens.hasMoreTokens()) { String pathElement = pathTokens.nextToken(); // Treat * and ? as wildcard unless they match a literal filename if ((pathElement.contains("?") || pathElement.contains("*")) && inBase && !root.child((_base.length() > 0 ? _base + "/" : "") + pathElement).exists()) inBase = false; if (pathElement.equals("*zip*")) { // the expected syntax is foo/bar/*zip*/bar.zip // the last 'bar.zip' portion is to causes browses to set a good default file name. // so the 'rest' portion ends here. zip = true; break; } if (pathElement.equals("*plain*")) { plain = true; break; } StringBuilder sb = inBase ? _base : _rest; if (sb.length() > 0) sb.append('/'); sb.append(pathElement); if (!inBase) restSize++; } } restSize = Math.max(restSize, 0); String base = _base.toString(); String rest = _rest.toString(); // this is the base file/directory VirtualFile baseFile = root.child(base); if (baseFile.isDirectory()) { if (zip) { rsp.setContentType("application/zip"); zip(rsp.getOutputStream(), baseFile, rest); return; } if (plain) { rsp.setContentType("text/plain;charset=UTF-8"); OutputStream os = rsp.getOutputStream(); try { for (VirtualFile kid : baseFile.list()) { os.write(kid.getName().getBytes("UTF-8")); if (kid.isDirectory()) { os.write('/'); } os.write('\n'); } os.flush(); } finally { os.close(); } return; } if (rest.length() == 0) { // if the target page to be displayed is a directory and the path doesn't end with '/', redirect StringBuffer reqUrl = req.getRequestURL(); if (reqUrl.charAt(reqUrl.length() - 1) != '/') { rsp.sendRedirect2(reqUrl.append('/').toString()); return; } } List<List<Path>> glob = null; if (rest.length() > 0) { // the rest is Ant glob pattern glob = patternScan(baseFile, rest, createBackRef(restSize)); } else if (serveDirIndex) { // serve directory index glob = baseFile.run(new BuildChildPaths(baseFile, req.getLocale())); } if (glob != null) { // serve glob req.setAttribute("it", this); List<Path> parentPaths = buildParentPath(base, restSize); req.setAttribute("parentPath", parentPaths); req.setAttribute("backPath", createBackRef(restSize)); req.setAttribute("topPath", createBackRef(parentPaths.size() + restSize)); req.setAttribute("files", glob); req.setAttribute("icon", icon); req.setAttribute("path", path); req.setAttribute("pattern", rest); req.setAttribute("dir", baseFile); req.getView(this, "dir.jelly").forward(req, rsp); return; } // convert a directory service request to a single file service request by serving // 'index.html' baseFile = baseFile.child(indexFileName); } //serve a single file if (!baseFile.exists()) { rsp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } boolean view = rest.equals("*view*"); if (rest.equals("*fingerprint*")) { InputStream fingerprintInput = baseFile.open(); try { rsp.forward(Jenkins.getInstance().getFingerprint(Util.getDigestOf(fingerprintInput)), "/", req); } finally { fingerprintInput.close(); } return; } long lastModified = baseFile.lastModified(); long length = baseFile.length(); if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine("Serving " + baseFile + " with lastModified=" + lastModified + ", length=" + length); InputStream in = baseFile.open(); if (view) { // for binary files, provide the file name for download rsp.setHeader("Content-Disposition", "inline; filename=" + baseFile.getName()); // pseudo file name to let the Stapler set text/plain rsp.serveFile(req, in, lastModified, -1, length, "plain.txt"); } else { String csp = System.getProperty(DirectoryBrowserSupport.class.getName() + ".CSP"); if (csp == null) { // default value unless overridden with system property csp = DEFAULT_CSP_VALUE; } if (!csp.trim().equals("")) { // allow users to prevent sending this header by setting empty system property for (String header : new String[] { "Content-Security-Policy", "X-WebKit-CSP", "X-Content-Security-Policy" }) { rsp.setHeader(header, csp); } } rsp.serveFile(req, in, lastModified, -1, length, baseFile.getName()); } }
From source file:com.wabacus.system.component.application.report.configbean.crosslist.CrossListReportDynDatasetBean.java
private String getDynamicSelectCols(List<AbsCrossListReportColAndGroupBean> lstCrossColAndGroupBeans, Map<String, String> mAllSelectCols) { if (lstCrossColAndGroupBeans == null || lstCrossColAndGroupBeans.size() == 0) return ""; if (mAllSelectCols == null || mAllSelectCols.size() == 0) return ""; StringBuffer resultBuf = new StringBuffer(); String selectColsTmp;/*from w ww .j av a2 s. c o m*/ for (AbsCrossListReportColAndGroupBean colgroupBeanTmp : lstCrossColAndGroupBeans) { selectColsTmp = mAllSelectCols.get(colgroupBeanTmp.getRootCrossColGroupId()); if (selectColsTmp == null || selectColsTmp.trim().equals("")) continue; resultBuf.append(selectColsTmp).append(","); } if (resultBuf.length() > 0 && resultBuf.charAt(resultBuf.length() - 1) == ',') resultBuf.deleteCharAt(resultBuf.length() - 1); return resultBuf.toString(); }
From source file:com.twinsoft.convertigo.eclipse.learnproxy.http.HttpProxyWorker.java
private String getNextLine(BufferedInputStream inStream) throws IOException { StringBuffer buffer = new StringBuffer(20); int readInt;//from w w w . ja v a 2s . c o m char c; while (!isInterrupted && (readInt = inStream.read()) != -1) { c = (char) readInt; buffer.append(c); if (c == (char) 10) { // check for end of line if (buffer.length() > 1 && buffer.charAt(buffer.length() - 2) == (char) 13) { return buffer.toString(); } } } return buffer.toString(); }
From source file:org.nuxeo.ecm.webengine.model.impl.AbstractWebContext.java
@Override public String getURL() { StringBuffer sb = request.getRequestURL(); if (sb.charAt(sb.length() - 1) == '/') { sb.setLength(sb.length() - 1);/*from w ww . j av a 2 s . c o m*/ } return sb.toString(); }