List of usage examples for java.lang StringBuffer substring
@Override public synchronized String substring(int start, int end)
From source file:org.apache.ivory.retention.FeedEvictor.java
@Override public int run(String[] args) throws Exception { CommandLine cmd = getCommand(args);// w w w . j a va2 s.c o m String feedBasePath = cmd.getOptionValue("feedBasePath").replaceAll("\\?\\{", "\\$\\{"); String retentionType = cmd.getOptionValue("retentionType"); String retentionLimit = cmd.getOptionValue("retentionLimit"); String timeZone = cmd.getOptionValue("timeZone"); String frequency = cmd.getOptionValue("frequency"); //to write out smart path filters String logFile = cmd.getOptionValue("logFile"); Path normalizedPath = new Path(feedBasePath); fs = normalizedPath.getFileSystem(getConf()); feedBasePath = normalizedPath.toUri().getPath(); LOG.info("Normalized path : " + feedBasePath); Pair<Date, Date> range = getDateRange(retentionLimit); String dateMask = getDateFormatInPath(feedBasePath); List<Path> toBeDeleted = discoverInstanceToDelete(feedBasePath, timeZone, dateMask, range.first); LOG.info("Applying retention on " + feedBasePath + " type: " + retentionType + ", Limit: " + retentionLimit + ", timezone: " + timeZone + ", frequency: " + frequency); DateFormat dateFormat = new SimpleDateFormat(format); dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone)); StringBuffer buffer = new StringBuffer(); StringBuffer instancePaths = new StringBuffer("instancePaths="); for (Path path : toBeDeleted) { if (deleteInstance(path)) { LOG.info("Deleted instance " + path); Date date = getDate(path, feedBasePath, dateMask, timeZone); buffer.append(dateFormat.format(date)).append(','); instancePaths.append(path).append(","); } } logInstancePaths(new Path(logFile), instancePaths.toString()); int len = buffer.length(); if (len > 0) { stream.println("instances=" + buffer.substring(0, len - 1)); } else { stream.println("instances=NULL"); } return 0; }
From source file:org.apache.hadoop.mapreduce.tools.CLI.java
private String getJobPriorityNames() { StringBuffer sb = new StringBuffer(); for (JobPriority p : JobPriority.values()) { // UNDEFINED_PRIORITY need not to be displayed in usage if (JobPriority.UNDEFINED_PRIORITY == p) { continue; }//from w ww . ja v a 2 s . c o m sb.append(p.name()).append(" "); } return sb.substring(0, sb.length() - 1); }
From source file:com.digitalpebble.storm.crawler.protocol.http.HttpResponse.java
private int parseStatusLine(PushbackInputStream in, StringBuffer line) throws IOException, HttpException { readLine(in, line, false);//from ww w . j a v a 2 s. com int codeStart = line.indexOf(" "); int codeEnd = line.indexOf(" ", codeStart + 1); // handle lines with no plaintext result code, ie: // "HTTP/1.1 200" vs "HTTP/1.1 200 OK" if (codeEnd == -1) codeEnd = line.length(); int code; try { code = Integer.parseInt(line.substring(codeStart + 1, codeEnd)); } catch (NumberFormatException e) { throw new HttpException("bad status line '" + line + "': " + e.getMessage(), e); } return code; }
From source file:org.pentaho.di.core.row.ValueDataUtil.java
/** * Alternate faster version of string replace using a stringbuffer as input. * * @param str/* ww w .j av a 2 s .co m*/ * The string where we want to replace in * @param code * The code to search for * @param repl * The replacement string for code */ public static void replaceBuffer(StringBuffer str, String code, String repl) { int clength = code.length(); int i = str.length() - clength; while (i >= 0) { String look = str.substring(i, i + clength); if (look.equalsIgnoreCase(code)) { // Look for a match! str.replace(i, i + clength, repl); } i--; } }
From source file:com.zhonghui.tool.controller.HttpClient.java
/** * Map?key=value&key=value/* w w w. j a v a2 s . c o m*/ * * @param requestParam * @param coder * @return */ private String getRequestParamString(Map<String, String> requestParam, String coder) { StringBuffer sf = new StringBuffer(""); String reqstr = ""; if (null != requestParam && 0 != requestParam.size()) { for (Entry<String, String> en : requestParam.entrySet()) { try { sf.append(en.getKey() + "=" + (null == en.getValue() || "".equals(en.getValue()) ? "" : URLEncoder.encode(en.getValue(), coder)) + "&"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return ""; } } reqstr = sf.substring(0, sf.length() - 1); } logger.info("(?URLEncode?):[" + reqstr + "]"); return reqstr; }
From source file:org.wso2.carbon.governance.sramp.SRAMPServlet.java
private String getServletURL(HttpServletRequest req) { try {//from w w w . j av a 2 s .c om StringBuffer requestURL = req.getRequestURL(); return requestURL.substring(0, requestURL.indexOf(S_RAMP_SERVLET_CONTEXT) + S_RAMP_SERVLET_CONTEXT.length()); } catch (Exception ignore) { // if there are any issues in obtaining the servlet URL, simply return the default HTTPS // URL. return servletURL; } }
From source file:com.digitalpebble.storm.crawler.protocol.http.HttpResponse.java
private void processHeaderLine(StringBuffer line) throws HttpException { int colonIndex = line.indexOf(":"); // key is up to colon if (colonIndex == -1) { int i;/* www . j a v a 2 s .com*/ 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.addValue(key.toLowerCase(Locale.ROOT), value); }
From source file:FormatStorage1.IColumnDataFile.java
public void create(String fileName, IHead head, ArrayList<ArrayList<Integer>> columnprojects) throws IOException { if (columnprojects == null) { this.create(fileName, head); return;//from w ww . ja v a 2 s .c om } this.columnprojects = columnprojects; this.head = head; fieldtypes = head.fieldMap().fieldtypes(); int primaryindex = head.getPrimaryIndex(); StringBuffer sb = new StringBuffer(); for (ArrayList<Integer> cp : columnprojects) { IHead subhead = new IHead(head); subhead.setPrimaryIndex((short) -1); IFieldMap fieldMap = new IFieldMap(); sb.setLength(0); sb.append("_idx"); for (int i = 0; i < cp.size(); i++) { int c = cp.get(i); if (c == primaryindex) subhead.setPrimaryIndex(i); fieldMap.addFieldType(fieldtypes.get(c)); sb.append(c).append("_"); } subhead.setFieldMap(fieldMap); IFormatDataFile ifdf = new IFormatDataFile(conf); String subfile = fileName + sb.substring(0, sb.length() - 1); ifdf.create(subfile, subhead); this.cp2ifdfs.put(cp, ifdf); for (Integer c : cp) { this.idx2ifdfs.put(c, ifdf); } } workstatus = ConstVar.WS_Write; }
From source file:org.ebayopensource.turmeric.eclipse.typelibrary.ui.wizards.pages.NewTypeLibraryWizardPage.java
private boolean validateNamespaceAndTypesDuplicated() { if (types == null) { return true; }/* w w w .j a v a2s .c o m*/ StringBuffer dupNames = new StringBuffer(); for (TypeModel type : types) { boolean hasType = true; try { hasType = SOAGlobalRegistryAdapter.getInstance().getGlobalRegistry() .getType(new QName(namespaceText.getText(), type.getTypeName())) != null; } catch (Exception e) { e.printStackTrace(); } if (hasType) { dupNames.append(type.getTypeName() + ", "); } } if (dupNames.length() > 0) { String errorMsg = "Selected types duplicated with types in the Type Repository [ " + dupNames.substring(0, dupNames.length() - 2) + "]. Please return to previous page and un-select these types or " + "change Type Library namespace."; if (overrideNamespaceBtn.getSelection() == true) { updateStatus(errorMsg, namespaceText); } else { updateStatus(errorMsg, namespaceText, domainClassifierList, serviceDomainList); } } return false; }
From source file:com.genentech.chemistry.tool.SDFSelectivityCalculator.java
private boolean readInput(OEMolBase mol) { numeratorInput = oechem.OEGetSDData(mol, numeratorTag); denominatorInput = oechem.OEGetSDData(mol, denominatorTag); if (numeratorInput == null || numeratorInput.length() == 0 || denominatorInput == null || denominatorInput.length() == 0) return false; numeratorOPInput = ""; if (numeratorOPTag != null) numeratorOPInput = oechem.OEGetSDData(mol, numeratorOPTag); denominatorOPInput = ""; if (denominatorOPTag != null) denominatorOPInput = oechem.OEGetSDData(mol, denominatorOPTag); if (numeratorOPInput.length() == 0) { if (numeratorInput.startsWith("<") || numeratorInput.startsWith(">")) { numeratorOPInput = numeratorInput.substring(0, 1); numeratorInput = numeratorInput.substring(1); }//from w w w. j a v a2 s.c o m } if (denominatorOPInput.length() == 0) { if (denominatorInput.startsWith("<") || denominatorInput.startsWith(">")) { denominatorOPInput = denominatorInput.substring(0, 1); denominatorInput = denominatorInput.substring(1); } } StringBuffer errText = new StringBuffer(); if (!DataFormat.isNumeric(numeratorInput) || !DataFormat.isNumeric(denominatorInput)) { errText.append("Numerator or denominator is not a number; "); } if (numeratorOPInput.length() > 0 && !numeratorOPInput.matches("[<>]")) { errText.append(String.format("Invalid numerator operators (%s); ", numeratorOPInput)); } if (denominatorOPInput.length() > 0 && !denominatorOPInput.matches("[<>]")) { errText.append(String.format("Invalid denominator operators (%s); ", denominatorOPInput)); } if (errText.length() > 0) { messageText = errText.substring(0, errText.length() - 2); return false; } return true; }