List of usage examples for java.lang StringBuffer charAt
@Override public synchronized char charAt(int index)
From source file:egovframework.com.utl.sys.fsm.service.FileSystemUtils.java
/** * Parses the Windows dir response last line * * @param line the line to parse/*from w w w. j a v a 2 s. co m*/ * @param path the path that was sent * @return the number of bytes * @throws IOException if an error occurs */ long parseDir(String line, String path) throws IOException { // read from the end of the line to find the last numeric // character on the line, then continue until we find the first // non-numeric character, and everything between that and the last // numeric character inclusive is our free space bytes count int bytesStart = 0; int bytesEnd = 0; int j = line.length() - 1; innerLoop1: while (j >= 0) { char c = line.charAt(j); if (Character.isDigit(c)) { // found the last numeric character, this is the end of // the free space bytes count bytesEnd = j + 1; break innerLoop1; } j--; } innerLoop2: while (j >= 0) { char c = line.charAt(j); if (!Character.isDigit(c) && c != ',' && c != '.') { // found the next non-numeric character, this is the // beginning of the free space bytes count bytesStart = j + 1; break innerLoop2; } j--; } if (j < 0) { throw new IOException("Command line 'dir /-c' did not return valid info " + "for path '" + path + "'"); } // remove commas and dots in the bytes count StringBuffer buf = new StringBuffer(line.substring(bytesStart, bytesEnd)); for (int k = 0; k < buf.length(); k++) { if (buf.charAt(k) == ',' || buf.charAt(k) == '.') { buf.deleteCharAt(k--); } } return parseBytes(buf.toString(), path); }
From source file:com.xie.javacase.json.XMLTokener.java
/** * Get the text in the CDATA block./*from w ww .j a v a 2 s . c om*/ * @return The string up to the <code>]]></code>. * @throws org.json.JSONException If the <code>]]></code> is not found. */ public String nextCDATA() throws JSONException { char c; int i; StringBuffer sb = new StringBuffer(); for (;;) { c = next(); if (c == 0) { throw syntaxError("Unclosed CDATA"); } sb.append(c); i = sb.length() - 3; if (i >= 0 && sb.charAt(i) == ']' && sb.charAt(i + 1) == ']' && sb.charAt(i + 2) == '>') { sb.setLength(i); return sb.toString(); } } }
From source file:er.extensions.ERXExtensions.java
/** * This method can be used with Direct Action URLs to make sure * that the browser will reload the page. This is done by * adding the parameter [? | &]r=random_number to the end of the * url.// www .j a va 2s .c o m * @param daURL a url to add the randomization to. */ // FIXME: Should check to make sure that the key 'r' isn't already present in the url. public static void addRandomizeDirectActionURL(StringBuffer daURL) { synchronized (_random) { int r = _random.nextInt(); char c = '?'; for (int i = 0; i < daURL.length(); i++) { if (daURL.charAt(i) == '?') { c = '&'; break; } } daURL.append(c); daURL.append("r="); daURL.append(r); } }
From source file:CodePointInputMethod.java
private int getCodePoint(StringBuffer sb, int from, int to) { int value = 0; for (int i = from; i <= to; i++) { value = (value << 4) + Character.digit(sb.charAt(i), 16); }/*from w w w . j a v a 2s . c o m*/ return value; }
From source file:com.qut.middleware.spep.filter.SPEPFilter.java
/** * Transcodes %XX symbols per RFC 2369 to normalized character format - adapted from apache commons * /*w ww .j a va2 s. c om*/ * @param buffer * The stringBuffer object containing the request data * @param offset * How far into the string buffer we should start processing from * @param length * Number of chars in the buffer * @throws ServletException */ private void decode(final StringBuffer buffer, final int offset, final int length) throws ServletException { int index = offset; int count = length; int dig1, dig2; while (count > 0) { final char ch = buffer.charAt(index); if (ch != '%') { count--; index++; continue; } if (count < 3) { throw new ServletException( Messages.getString("SPEPFilter.10") + buffer.substring(index, index + count)); //$NON-NLS-1$ } dig1 = Character.digit(buffer.charAt(index + 1), 16); dig2 = Character.digit(buffer.charAt(index + 2), 16); if (dig1 == -1 || dig2 == -1) { throw new ServletException( Messages.getString("SPEPFilter.11") + buffer.substring(index, index + count)); //$NON-NLS-1$ } char value = (char) (dig1 << 4 | dig2); buffer.setCharAt(index, value); buffer.delete(index + 1, index + 3); count -= 3; index++; } }
From source file:org.openmrs.module.FacesRegister.web.controller.Faces361BRegisterManageController.java
private String dateFormat(String s) { /*/*from w w w . j a v a 2 s .c o m*/ * this method formats the date string * it takes input in the format of dd/mm/yyyy and returns yyyy-mm-dd * This is done so that we can ensure correct sql date format */ String temp = ""; StringBuffer st = new StringBuffer(s); for (int i = st.length() - 1; i >= 0; i--) { if (st.charAt(i) == '/') st.replace(i, i + 1, "-"); //replace the slash "/" with the dash "-" } temp = st.substring(6, 10) + "-" + st.substring(3, 5) + "-" + st.substring(0, 2); // format date (yyyy-mm-dd) return temp; }
From source file:org.apache.ftpserver.usermanager.DbUserManager.java
/** * Escape string to be embedded in SQL statement. *///w w w . j a va 2 s . c om private String escapeString(String input) { StringBuffer valBuf = new StringBuffer(input); for (int i = 0; i < valBuf.length(); i++) { char ch = valBuf.charAt(i); if (ch == '\'' || ch == '\\' || ch == '$' || ch == '^' || ch == '[' || ch == ']' || ch == '{' || ch == '}') { valBuf.insert(i, '\\'); i++; } } return valBuf.toString(); }
From source file:com.zimbra.common.mime.MimeDetect.java
private String readLine(InputStream is) throws IOException { StringBuffer sb = new StringBuffer(); int c;/* ww w . jav a2s. c om*/ while ((c = is.read()) != -1 && c != '\n') sb.append((char) c); if (sb.length() > 0 && sb.charAt(sb.length() - 1) == '\r') { // drop trailing \r sb.deleteCharAt(sb.length() - 1); } return sb.length() == 0 ? null : sb.toString(); }
From source file:net.sourceforge.eclipsetrader.yahoo.Feed.java
private void update() { // Builds the url for quotes download String host = "quote.yahoo.com"; //$NON-NLS-1$ StringBuffer url = new StringBuffer("http://" + host + "/download/javasoft.beans?symbols="); //$NON-NLS-1$ //$NON-NLS-2$ for (Iterator iter = map.values().iterator(); iter.hasNext();) url = url.append((String) iter.next() + "+"); //$NON-NLS-1$ if (url.charAt(url.length() - 1) == '+') url.deleteCharAt(url.length() - 1); url.append("&format=sl1d1t1c1ohgvbap"); //$NON-NLS-1$ log.debug(url.toString());// w w w. j a va 2s. c om // Read the last prices String line = ""; //$NON-NLS-1$ try { HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); BundleContext context = YahooPlugin.getDefault().getBundle().getBundleContext(); ServiceReference reference = context.getServiceReference(IProxyService.class.getName()); if (reference != null) { IProxyService proxy = (IProxyService) context.getService(reference); IProxyData data = proxy.getProxyDataForHost(host, IProxyData.HTTP_PROXY_TYPE); if (data != null) { if (data.getHost() != null) client.getHostConfiguration().setProxy(data.getHost(), data.getPort()); if (data.isRequiresAuthentication()) client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(data.getUserId(), data.getPassword())); } } HttpMethod method = new GetMethod(url.toString()); method.setFollowRedirects(true); client.executeMethod(method); BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); while ((line = in.readLine()) != null) { String[] item = line.split(","); //$NON-NLS-1$ if (line.indexOf(";") != -1) //$NON-NLS-1$ item = line.split(";"); //$NON-NLS-1$ Double open = null, high = null, low = null, close = null; Quote quote = new Quote(); // 2 = Date // 3 = Time try { GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("EST"), Locale.US); //$NON-NLS-1$ usDateTimeParser.setTimeZone(c.getTimeZone()); usDateParser.setTimeZone(c.getTimeZone()); usTimeParser.setTimeZone(c.getTimeZone()); String date = stripQuotes(item[2]); if (date.indexOf("N/A") != -1) //$NON-NLS-1$ date = usDateParser.format(Calendar.getInstance().getTime()); String time = stripQuotes(item[3]); if (time.indexOf("N/A") != -1) //$NON-NLS-1$ time = usTimeParser.format(Calendar.getInstance().getTime()); c.setTime(usDateTimeParser.parse(date + " " + time)); //$NON-NLS-1$ c.setTimeZone(TimeZone.getDefault()); quote.setDate(c.getTime()); } catch (Exception e) { log.error(e.getMessage() + ": " + line); //$NON-NLS-1$ } // 1 = Last price or N/A if (item[1].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ quote.setLast(numberFormat.parse(item[1]).doubleValue()); // 4 = Change // 5 = Open if (item[5].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ open = new Double(numberFormat.parse(item[5]).doubleValue()); // 6 = Maximum if (item[6].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ high = new Double(numberFormat.parse(item[6]).doubleValue()); // 7 = Minimum if (item[7].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ low = new Double(numberFormat.parse(item[7]).doubleValue()); // 8 = Volume if (item[8].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ quote.setVolume(numberFormat.parse(item[8]).intValue()); // 9 = Bid Price if (item[9].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ quote.setBid(numberFormat.parse(item[9]).doubleValue()); // 10 = Ask Price if (item[10].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ quote.setAsk(numberFormat.parse(item[10]).doubleValue()); // 11 = Close Price if (item[11].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ close = new Double(numberFormat.parse(item[11]).doubleValue()); // 0 = Code String symbol = stripQuotes(item[0]); for (Iterator iter = map.keySet().iterator(); iter.hasNext();) { Security security = (Security) iter.next(); if (symbol.equalsIgnoreCase((String) map.get(security))) { security.setQuote(quote, open, high, low, close); } } } in.close(); } catch (Exception e) { log.error(e); } }
From source file:com.netspective.sparx.navigate.NavigationPath.java
protected String constructQualifiedName() { StringBuffer sb = new StringBuffer(); if (parent != null) sb.append(parent.getQualifiedName()); if (sb.length() == 0 || sb.charAt(sb.length() - 1) != '/') sb.append(PATH_SEPARATOR);// ww w . ja va 2 s .co m sb.append(getName()); return sb.toString(); }