List of usage examples for java.lang StringBuffer delete
@Override public synchronized StringBuffer delete(int start, int end)
From source file:com.upyun.sdk.UpYunClient.java
public FileVo listFileInfo(String fileName) throws UpYunExcetion { try {/*w w w. j a v a2 s .co m*/ StringBuffer url = new StringBuffer(); for (String str : fileName.split("/")) { if (str == null || str.length() == 0) { continue; } url.append(UrlCodingUtil.encodeBase64(str.getBytes("utf-8")) + "/"); } url = url.delete(url.length() - 1, url.length()); sign.setUri(url.toString()); } catch (UnsupportedEncodingException e) { LogUtil.exception(logger, e); } sign.setContentLength(0); sign.setMethod(HttpMethod.HEAD.name()); String url = autoUrl + sign.getUri(); Map<String, String> headers = sign.getHeaders(); HttpResponse httpResponse = HttpClientUtils.headByHttp(url, headers); FileVo fileVo = null; if (httpResponse.getStatusLine().getStatusCode() != 200) { throw new UpYunExcetion(httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getReasonPhrase()); } else { fileVo = new FileVo(); for (Header header : httpResponse.getAllHeaders()) { if ("x-upyun-file-type".equals(header.getName())) { fileVo.setType(header.getValue()); } else if ("x-upyun-file-size".equals(header.getName())) { fileVo.setSize(Long.valueOf(header.getValue())); } else if ("x-upyun-file-date".equals(header.getName())) { fileVo.setCreatedAt(new Date(Long.valueOf(header.getValue()) * 1000)); } } } return fileVo; }
From source file:Main.java
/** * Erases the mIRC colorcodes from a String. * The documentation of the evil color codes is available on * <a href="http://www.mirc.co.uk/help/color.txt" * target="_blank">http://www.mirc.co.uk/help/color.txt</a>. * @param buf The line which should be parsed. * @return A line as <code>StringBuffer</code> object which is cleaned from * any mIRC colorcodes.//from w w w . ja va 2 s .c o m * @see #parseColors(String) */ public static StringBuffer parseColors(StringBuffer buf) { int len = buf.length(); for (int i = 0, j = 0, c; i < len; i++, j = i) { c = buf.charAt(i); try { // COLORS Beginning // (format: <colorIndicator><int>[<int>][[,<int>[<int>]] if (c == colorIndicator) { c = buf.charAt(++j); if ('0' <= c && c <= '9') { // first int c = buf.charAt(++j); if ('0' <= c && c <= '9') c = buf.charAt(++j); // second int } if (c == ',') c = buf.charAt(++j); // comma if ('0' <= c && c <= '9') { // first int c = buf.charAt(++j); if ('0' <= c && c <= '9') c = buf.charAt(++j); // second int } // ACTION / BOLD / UNDERLINE / COLOR END // (format: <actionIndicator> / <boldIndicator> etc.) } else if (c == actionIndicator || c == boldIndicator || c == underlinedIndicator || c == colorEndIndicator || c == colorReverseIndicator) { j++; } } catch (StringIndexOutOfBoundsException exc) { // we got the end of the string with a call to charAt(++iIndexEnd) // nothing } if (j > i) { buf = buf.delete(i, j); // remove the cars len -= (j - i); i -= (j - i); } } return buf; }
From source file:com.upyun.sdk.UpYunClient.java
public void delete(String name, Boolean flag) throws UpYunExcetion { try {//from w ww. j a v a 2 s . c o m StringBuffer url = new StringBuffer(); for (String str : name.split("/")) { if (str == null || str.length() == 0) { continue; } url.append(UrlCodingUtil.encodeBase64(str.getBytes("utf-8")) + "/"); } if (flag) { url = url.delete(url.length() - 1, url.length()); } sign.setUri(url.toString()); } catch (UnsupportedEncodingException e) { LogUtil.exception(logger, e); } sign.setContentLength(0); sign.setMethod(HttpMethod.DELETE.name()); String url = autoUrl + sign.getUri(); Map<String, String> headers = sign.getHeaders(); HttpResponse httpResponse = HttpClientUtils.deleteByHttp(url, headers); if (httpResponse.getStatusLine().getStatusCode() != 200) { throw new UpYunExcetion(httpResponse.getStatusLine().getStatusCode(), httpResponse.getStatusLine().getReasonPhrase()); } }
From source file:com.chinamobile.bcbsp.pipes.TaskHandler.java
@Override @SuppressWarnings("unchecked") public boolean saveResult(String vertexId, String vertexValue, String[] edges) { try {/*from ww w. j a v a 2 s . com*/ OutputFormat outputformat = (OutputFormat) ReflectionUtils.newInstance( job.getConf().getClass(Constants.USER_BC_BSP_JOB_OUTPUT_FORMAT_CLASS, OutputFormat.class), job.getConf()); outputformat.initialize(job.getConf()); RecordWriter newoutput = outputformat.getRecordWriter(job, sid); // for (int i = 0; i < graphData.sizeForAll(); i++) { // Vertex<?, ?, Edge> vertex = graphData.getForAll(i); StringBuffer outEdges = new StringBuffer(); for (String edge : edges) { outEdges.append(vertexId + Constants.SPLIT_FLAG + vertexValue + Constants.SPACE_SPLIT_FLAG); } if (outEdges.length() > 0) { int j = outEdges.length(); outEdges.delete(j - 1, j - 1); } newoutput.write(new Text(vertexId + Constants.SPLIT_FLAG + vertexValue), new Text(outEdges.toString())); // } newoutput.close(job); // graphData.clean(); } catch (Exception e) { LOG.error("Exception has been catched in BSPStaff--saveResult !", e); BSPConfiguration conf = new BSPConfiguration(); if (staff.getRecoveryTimes() < conf.getInt(Constants.BC_BSP_JOB_RECOVERY_ATTEMPT_MAX, 0)) { staff.recovery(job, staff, workerAgent); } else { workerAgent.setStaffStatus(sid, Constants.SATAFF_STATUS.FAULT, new Fault(Fault.Type.DISK, Fault.Level.INDETERMINATE, workerAgent.getWorkerManagerName(job.getJobID(), sid), e.toString(), job.toString(), sid.toString()), 2); LOG.info("=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=" + "*=*=*=*"); LOG.error("Other Exception has happened and been catched, " + "the exception will be reported to WorkerManager", e); } } return true; }
From source file:initializers.FSInitializer.java
@Override public void logElementAnalysis(Logger logger, String providerName, String resultsPath) { // TODO Auto-generated method stub File elAnalysisFile = new File(resultsPath + "Analysis_Results" + File.separator + providerName + File.separator + providerName + "_Element_Analysis.csv"); BufferedReader br = null;/*from ww w . j a va 2 s. com*/ try { String sCurrentLine; br = new BufferedReader(new FileReader(elAnalysisFile)); int counter = 0; StringBuffer buffer = new StringBuffer(); while ((sCurrentLine = br.readLine()) != null) { if (counter > 0) { buffer.append(providerName); buffer.append(" " + sCurrentLine.replace(",", " ")); logger.info(buffer.toString()); buffer.delete(0, buffer.capacity()); } counter++; } } catch (IOException e) { e.printStackTrace(); } finally { try { if (br != null) br.close(); } catch (IOException ex) { ex.printStackTrace(); } } }
From source file:org.j2free.util.HtmlFilter.java
/** * * @param msg/*from ww w. j a va 2 s . co m*/ * @param allowedTags * @return */ public String filter(String msg, String[] allowedTags) { if (msg == null) return ""; else if (msg.length() == 0 || msg.equals("") || !msg.contains("<")) return msg; okayTags.clear(); if (allowedTags != null && allowedTags.length > 0) okayTags.addAll(Arrays.asList(allowedTags)); StringBuffer line = new StringBuffer(msg); for (int i = 0; i < line.length(); i++) { if (line.charAt(i) == '<') { int begin = i, end = i; for (int j = i + 1; j < line.length(); j++) { if (line.charAt(j) == '>') { end = j + 1; break; } } if (!isOkayTag(new String(line.substring(begin, end)))) { line = line.delete(begin, end); } } } return new String(line); }
From source file:org.ejbca.core.protocol.ocsp.OcspJunitHelper.java
public void alterConfig(final Map<String, String> config) throws IOException, URISyntaxException { if (config == null || config.size() < 1) { return;/* w ww . j a v a 2 s .com*/ } final StringBuffer sb = new StringBuffer("newConfig="); for (Map.Entry<String, String> entry : config.entrySet()) { sb.append(entry.getKey()); sb.append('='); sb.append(entry.getValue()); sb.append("||"); } sb.delete(sb.length() - 2, sb.length());// remove last "||" servletGetWithParam(sb.toString()); }
From source file:pl.edu.agh.iosr.lsf.QueryExecutor.java
public void execute(Connection dbc, InputStream in, PrintWriter pw) throws SQLException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF-8"))); String line;//from ww w .j a va 2s . com StringBuffer sql = new StringBuffer(); try (Statement s = dbc.createStatement()) { while (true) { line = br.readLine(); if (line == null) break; line = line.trim(); int i = line.indexOf("--"); if (i >= 0) { line = line.substring(0, i).trim(); } sql.append(line); if (line.endsWith(";")) { //pw.println("execute: ("+sql.toString()+");"); s.execute(sql.toString()); sql.delete(0, sql.length()); } } if (sql.length() > 0) { s.execute(sql.toString()); } } }
From source file:org.jlibrary.client.export.freemarker.FreemarkerExporter.java
/** * Returns the relative root URL from the path of the directory * /*w w w . j av a 2s . c o m*/ * @param directory Directory * * @return String relative root URL */ public String getRootURL(Directory directory) { StringBuffer buffer = new StringBuffer("../"); if (directory.getParent() == null) { buffer = new StringBuffer("./"); } String[] parts = StringUtils.split(directory.getPath(), "/"); for (int i = 0; i < parts.length - 1; i++) { buffer.append("../"); } if (buffer.length() > 0) { buffer.delete(buffer.length() - 1, buffer.length()); } return buffer.toString(); }
From source file:org.jboss.drools.guvnor.importgenerator.PackageFile.java
public void addImports(String imports) { //strip out any "package " lines from additional imports StringBuffer sb = new StringBuffer(imports); if (imports.length() > 0) { int posPackage = imports.indexOf("package "); sb.delete(posPackage, imports.indexOf("\n", posPackage)); }//from w w w. j a va 2s. co m this.imports = new StringBuffer().append(imports).append("\n").append(sb).toString(); }