List of usage examples for java.lang StringBuffer charAt
@Override public synchronized char charAt(int index)
From source file:org.overlord.rtgov.activity.server.rest.client.RESTActivityServer.java
/** * This method initializes the authentication properties on the supplied * URL connection.//www . j a va2s . com * * @param connection The connection */ protected void initAuth(HttpURLConnection connection) { String userPassword = _serverUsername + ":" + _serverPassword; String encoding = org.apache.commons.codec.binary.Base64.encodeBase64String(userPassword.getBytes()); StringBuffer buf = new StringBuffer(encoding); for (int i = 0; i < buf.length(); i++) { if (Character.isWhitespace(buf.charAt(i))) { buf.deleteCharAt(i); i--; } } connection.setRequestProperty("Authorization", "Basic " + buf.toString()); }
From source file:org.siphon.jssp.JsspTranslator.java
public String translate() { StringBuffer result = new StringBuffer(); result.append(//from w w w. j av a 2s .c o m "d2js.jssp = function(params){var request = this.request;var response = this.response; var out = this.out;var session = this.session;"); result.append("response.setContentType('text/html; charset=utf-8'); "); StringBuffer line = new StringBuffer(); boolean afterCode = false; for (int i = 0; i < code.length(); i++) { char c = code.charAt(i); switch (c) { case '[': if (code.startsWith("[%", i)) { if (line.length() > 0) { result.append(outputLine(line)); line.setLength(0); } StringBuffer code = new StringBuffer(); if (this.code.startsWith("[%=", i)) { i += 2; i += tillTerm(i + 1, code); result.append("out.print(").append(code).append(");"); } else if (this.code.startsWith("[%~", i)) { i += 2; i += tillTerm(i + 1, code); result.append("out.print(JSON.stringify(").append(code).append("));"); } else if (this.code.startsWith("[%-", i)) { i += 2; i += tillTerm(i + 1, code); result.append("out.printHtml(").append(code).append(");"); } else { i++; i += tillTerm(i + 1, code); result.append(code); } afterCode = true; } else { line.append(c); } break; case '\r': if (code.startsWith("\r\n", i)) { i++; } case '\n': if (line.length() == 0 && afterCode) { result.append(System.lineSeparator()); } else { line.append(System.lineSeparator()); result.append(outputLine(line)).append(System.lineSeparator()); line.setLength(0); } break; default: if (afterCode) afterCode = false; line.append(c); } } if (line.length() > 0) { result.append(outputLine(line)); } result.append("}"); return result.toString(); }
From source file:com.wabacus.util.TestFileUploadInterceptor.java
/** * ??/??????//from w w w . java2 s. com */ public boolean beforeDisplayFileUploadPrompt(HttpServletRequest request, List lstFieldItems, Map<String, String> mFormAndConfigValues, String failedMessage, PrintWriter out) { if (lstFieldItems == null || lstFieldItems.size() == 0) return true; FileItem fItemTmp; StringBuffer fileNamesBuf = new StringBuffer(); for (int i = 0; i < lstFieldItems.size(); i++) { fItemTmp = (FileItem) lstFieldItems.get(i); if (fItemTmp.isFormField()) continue;//? fileNamesBuf.append(fItemTmp.getName()).append(";"); } if (fileNamesBuf.charAt(fileNamesBuf.length() - 1) == ';') fileNamesBuf.deleteCharAt(fileNamesBuf.length() - 1); if (failedMessage != null && !failedMessage.trim().equals("")) {// out.println("<h4>??" + fileNamesBuf.toString() + "" + failedMessage + "</h4>"); } else {//? out.println("<script language='javascript'>"); out.println("alert('" + fileNamesBuf.toString() + "?');"); String inputboxid = mFormAndConfigValues.get("INPUTBOXID"); if (inputboxid != null && !inputboxid.trim().equals("")) {//? String name = mFormAndConfigValues.get("param_name"); name = name + "[" + fileNamesBuf.toString() + "]"; out.println("selectOK('" + name + "','name',null,true);"); } out.println("</script>"); } return false;//???? }
From source file:org.eclipse.datatools.connectivity.sample.ftp.internal.FTPFileObject.java
public String getName() { StringBuffer sb = new StringBuffer(); FTPFileObject parent = this; while (parent != null) { sb.insert(0, "/" + parent.getFTPFile().getName()); if (parent.getParent() instanceof FTPFileObject) { parent = (FTPFileObject) parent.getParent(); } else {/*from www. j a v a 2 s . co m*/ parent = null; } } while (sb.charAt(0) == '/') { sb.deleteCharAt(0); } return sb.toString(); }
From source file:org.archive.util.SURT.java
/** * Utility method for creating the SURT form of the URI in the * given String./* w w w .j a v a2 s . c o m*/ * * If it appears a bit convoluted in its approach, note that it was * optimized to minimize object-creation after allocation-sites profiling * indicated this method was a top source of garbage in long-running crawls. * * Assumes that the String URI has already been cleaned/fixed (eg * by UURI fixup) in ways that put it in its crawlable form for * evaluation. * * @param s String URI to be converted to SURT form * @param preserveCase whether original case should be preserved * @return SURT form */ public static String fromURI(String s, boolean preserveCase) { Matcher m = TextUtils.getMatcher(URI_SPLITTER, s); if (!m.matches()) { // not an authority-based URI scheme; return unchanged TextUtils.recycleMatcher(m); return s; } // preallocate enough space for SURT form, which includes // 3 extra characters ('(', ')', and one more ',' than '.'s // in original) StringBuffer builder = new StringBuffer(s.length() + 3); append(builder, s, m.start(1), m.end(1)); // scheme:// builder.append(BEGIN_TRANSFORMED_AUTHORITY); // '(' if (m.start(4) > -1) { // dotted-quad ip match: don't reverse append(builder, s, m.start(4), m.end(4)); } else { // other hostname match: do reverse int hostSegEnd = m.end(5); int hostStart = m.start(5); for (int i = m.end(5) - 1; i >= hostStart; i--) { if (s.charAt(i - 1) != DOT && i > hostStart) { continue; } append(builder, s, i, hostSegEnd); // rev host segment builder.append(TRANSFORMED_HOST_DELIM); // ',' hostSegEnd = i - 1; } } append(builder, s, m.start(6), m.end(6)); // :port append(builder, s, m.start(3), m.end(3)); // at append(builder, s, m.start(2), m.end(2)); // userinfo builder.append(END_TRANSFORMED_AUTHORITY); // ')' append(builder, s, m.start(7), m.end(7)); // path if (!preserveCase) { for (int i = 0; i < builder.length(); i++) { builder.setCharAt(i, Character.toLowerCase(builder.charAt((i)))); } } TextUtils.recycleMatcher(m); return builder.toString(); }
From source file:be.ibridge.kettle.trans.step.textfileinput.TextFileInput.java
public static final Value convertValue(String pol, String field_name, int field_type, String field_format, int field_length, int field_precision, String num_group, String num_decimal, String num_currency, String nullif, String ifNull, int trim_type, DecimalFormat ldf, DecimalFormatSymbols ldfs, SimpleDateFormat ldaf, DateFormatSymbols ldafs) throws Exception { Value value = new Value(field_name, field_type); // build a value! // If no nullif field is supplied, take the default. String null_value = nullif;//from w w w. j av a 2s. c om if (null_value == null) { switch (field_type) { case Value.VALUE_TYPE_BOOLEAN: null_value = Const.NULL_BOOLEAN; break; case Value.VALUE_TYPE_STRING: null_value = Const.NULL_STRING; break; case Value.VALUE_TYPE_BIGNUMBER: null_value = Const.NULL_BIGNUMBER; break; case Value.VALUE_TYPE_NUMBER: null_value = Const.NULL_NUMBER; break; case Value.VALUE_TYPE_INTEGER: null_value = Const.NULL_INTEGER; break; case Value.VALUE_TYPE_DATE: null_value = Const.NULL_DATE; break; case Value.VALUE_TYPE_BINARY: null_value = Const.NULL_BINARY; break; default: null_value = Const.NULL_NONE; break; } } String null_cmp = Const.rightPad(new StringBuffer(null_value), pol.length()); if (pol == null || pol.length() == 0 || pol.equalsIgnoreCase(null_cmp)) { if (ifNull != null && ifNull.length() != 0) pol = ifNull; } if (pol == null || pol.length() == 0 || pol.equalsIgnoreCase(null_cmp)) { value.setNull(); } else { if (value.isNumeric()) { try { StringBuffer strpol = new StringBuffer(pol); switch (trim_type) { case TextFileInputMeta.TYPE_TRIM_LEFT: while (strpol.length() > 0 && strpol.charAt(0) == ' ') strpol.deleteCharAt(0); break; case TextFileInputMeta.TYPE_TRIM_RIGHT: while (strpol.length() > 0 && strpol.charAt(strpol.length() - 1) == ' ') strpol.deleteCharAt(strpol.length() - 1); break; case TextFileInputMeta.TYPE_TRIM_BOTH: while (strpol.length() > 0 && strpol.charAt(0) == ' ') strpol.deleteCharAt(0); while (strpol.length() > 0 && strpol.charAt(strpol.length() - 1) == ' ') strpol.deleteCharAt(strpol.length() - 1); break; default: break; } pol = strpol.toString(); if (value.isNumber()) { if (field_format != null) { ldf.applyPattern(field_format); if (num_decimal != null && num_decimal.length() >= 1) ldfs.setDecimalSeparator(num_decimal.charAt(0)); if (num_group != null && num_group.length() >= 1) ldfs.setGroupingSeparator(num_group.charAt(0)); if (num_currency != null && num_currency.length() >= 1) ldfs.setCurrencySymbol(num_currency); ldf.setDecimalFormatSymbols(ldfs); } value.setValue(ldf.parse(pol).doubleValue()); } else { if (value.isInteger()) { value.setValue(Long.parseLong(pol)); } else { if (value.isBigNumber()) { value.setValue(new BigDecimal(pol)); } else { throw new KettleValueException("Unknown numeric type: contact vendor!"); } } } } catch (Exception e) { throw (e); } } else { if (value.isString()) { value.setValue(pol); switch (trim_type) { case TextFileInputMeta.TYPE_TRIM_LEFT: value.ltrim(); break; case TextFileInputMeta.TYPE_TRIM_RIGHT: value.rtrim(); break; case TextFileInputMeta.TYPE_TRIM_BOTH: value.trim(); break; default: break; } if (pol.length() == 0) value.setNull(); } else { if (value.isDate()) { try { if (field_format != null) { ldaf.applyPattern(field_format); ldaf.setDateFormatSymbols(ldafs); } value.setValue(ldaf.parse(pol)); } catch (Exception e) { throw (e); } } else { if (value.isBinary()) { value.setValue(pol.getBytes()); } } } } } value.setLength(field_length, field_precision); return value; }
From source file:com.wabacus.system.component.application.report.configbean.editablereport.StoreProcedureActionBean.java
public void parseActionscript(String reportTypeKey, String actionscript) { ReportBean rbean = this.ownerGroupBean.getOwnerUpdateBean().getOwner().getReportBean(); actionscript = this.parseAndRemoveReturnParamname(actionscript); if (actionscript.startsWith("{") && actionscript.endsWith("}")) { actionscript = actionscript.substring(1, actionscript.length() - 1).trim(); }//from w ww.j av a 2 s . c o m String procedure = actionscript.substring("call ".length()).trim(); if (procedure.equals("")) { throw new WabacusConfigLoadingException("" + rbean.getPath() + "?" + actionscript + "???"); } String procname = procedure; List lstProcedureParams = new ArrayList(); int idxLeft = procedure.indexOf("("); if (idxLeft > 0) { int idxRight = procedure.lastIndexOf(")"); if (idxLeft == 0 || idxRight != procedure.length() - 1) { throw new WabacusConfigLoadingException("" + rbean.getPath() + "?" + actionscript + "????"); } procname = procedure.substring(0, idxLeft).trim(); String params = procedure.substring(idxLeft + 1, idxRight).trim(); if (!params.equals("")) { List<String> lstParamsTmp = Tools.parseStringToList(params, ',', '\''); Object paramObjTmp; for (String paramTmp : lstParamsTmp) { paramObjTmp = createEditParams(paramTmp, reportTypeKey); if (paramObjTmp instanceof String) { String strParamTmp = ((String) paramObjTmp); if (strParamTmp.startsWith("'") && strParamTmp.endsWith("'")) strParamTmp = strParamTmp.substring(1, strParamTmp.length() - 1); if (strParamTmp.startsWith("\"") && strParamTmp.endsWith("\"")) strParamTmp = strParamTmp.substring(1, strParamTmp.length() - 1); paramObjTmp = strParamTmp; } lstProcedureParams.add(paramObjTmp); } } } StringBuffer tmpBuf = new StringBuffer("{call " + procname + "("); for (int i = 0, len = lstProcedureParams.size(); i < len; i++) { tmpBuf.append("?,"); } if (this.returnValueParamname != null && !this.returnValueParamname.trim().equals("")) tmpBuf.append("?"); if (tmpBuf.charAt(tmpBuf.length() - 1) == ',') tmpBuf.deleteCharAt(tmpBuf.length() - 1); tmpBuf.append(")}"); this.sql = tmpBuf.toString(); this.lstParams = lstProcedureParams; this.ownerGroupBean.addActionBean(this); }
From source file:com.edgenius.wiki.integration.client.Authentication.java
/** * @param cookieTokens the tokens to be encoded. * @return base64 encoding of the tokens concatenated with the ":" delimiter. *///from w w w . ja va 2 s.c om private String encodeCookie(String[] cookieTokens) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < cookieTokens.length; i++) { sb.append(cookieTokens[i]); if (i < cookieTokens.length - 1) { sb.append(WsContants.DELIMITER); } } String value = sb.toString(); sb = new StringBuffer(new String(Base64.encodeBase64(value.getBytes()))); while (sb.charAt(sb.length() - 1) == '=') { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }
From source file:org.gbif.portal.web.tag.LineBreakTag.java
/** * @see javax.servlet.jsp.tagext.TagSupport#doStartTag() *///from w w w . ja v a 2 s . c om @Override public int doEndTag() throws JspException { String bodyContentAsString = getBodyContent().getString(); StringBuffer sb = new StringBuffer(); StringTokenizer st = new StringTokenizer(bodyContentAsString, " "); List<String> tokens = new ArrayList<String>(); while (st.hasMoreTokens()) { tokens.add(st.nextToken()); } try { for (String token : tokens) { char lastChar = (char) -1; if (sb.length() > 0) lastChar = sb.charAt(sb.length() - 1); if (sb.length() > maxLengthBeforeBreak || (sb.length() > 0 && Arrays.binarySearch(breakAfterChars, lastChar) > 0)) { pageContext.getOut().print(sb.toString()); pageContext.getOut().print(lineBreak); sb = new StringBuffer(token); } else { if (sb.length() > 0) sb.append(" "); sb.append(token); } } pageContext.getOut().print(sb.toString()); } catch (Exception e) { logger.debug(e.getMessage(), e); throw new JspException(e); } return super.doStartTag(); }
From source file:br.org.indt.ndg.common.MD5.java
public static String getMD5FromSurvey(StringBuffer input) throws IOException, NoSuchAlgorithmException { StringBuffer inputMD5 = new StringBuffer(input); // remove XML header String xmlStartFlag = "<?"; String xmlEndFlag = "?>"; int xmlFlagStartPosition = inputMD5.indexOf(xmlStartFlag); int xmlFlagEndPosition = inputMD5.indexOf(xmlEndFlag); if ((xmlFlagStartPosition >= 0) && (xmlFlagEndPosition >= 0)) { inputMD5.delete(xmlFlagStartPosition, xmlFlagEndPosition + xmlEndFlag.length() + 1); }/*from w ww . ja v a 2 s. c o m*/ // remove checksum key String checksumFlag = "checksum=\""; int checksumFlagStartPosition = inputMD5.indexOf(checksumFlag) + checksumFlag.length(); int checksumKeySize = 32; inputMD5.replace(checksumFlagStartPosition, checksumFlagStartPosition + checksumKeySize, ""); // we need to remove last '\n' once NDG editor calculates its md5 // checksum without it (both input and inputMD5) if (input.charAt(input.toString().length() - 1) == '\n') { input.deleteCharAt(input.toString().length() - 1); } if (inputMD5.charAt(inputMD5.toString().length() - 1) == '\n') { inputMD5.deleteCharAt(inputMD5.toString().length() - 1); } MessageDigest messageDigest = java.security.MessageDigest.getInstance("MD5"); messageDigest.update(inputMD5.toString().getBytes("UTF-8")); byte[] byteArrayMD5 = messageDigest.digest(); String surveyFileMD5 = getByteArrayAsString(byteArrayMD5); return surveyFileMD5; }