List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:com.easyjf.util.StringUtils.java
/** * Trim trailing whitespace from the given String. * //from w w w . ja v a 2 s. co m * @param str * the String to check * @return the trimmed String * @see java.lang.Character#isWhitespace */ public static String trimTrailingWhitespace(String str) { if (!hasLength(str)) return str; StringBuffer buf = new StringBuffer(str); while (buf.length() > 0 && Character.isWhitespace(buf.charAt(buf.length() - 1))) buf.deleteCharAt(buf.length() - 1); return buf.toString(); }
From source file:com.easyjf.util.StringUtils.java
/** * Trim leading and trailing whitespace from the given String. * //from w w w .j av a 2 s . com * @param str * the String to check * @return the trimmed String * @see java.lang.Character#isWhitespace */ public static String trimWhitespace(String str) { if (!hasLength(str)) return str; StringBuffer buf = new StringBuffer(str); while (buf.length() > 0 && Character.isWhitespace(buf.charAt(0))) buf.deleteCharAt(0); while (buf.length() > 0 && Character.isWhitespace(buf.charAt(buf.length() - 1))) buf.deleteCharAt(buf.length() - 1); return buf.toString(); }
From source file:es.pode.soporte.auditoria.registrar.Registrar.java
/** * Metodo copiado de SrvBuscadorServiceImpl para parseo de VSQI. TODO Corregir para * hacer un parseo XML mas fiable.//w ww .j a va 2 s . com * * @param queryStatement * @return */ private static String parsearVSQL(String queryStatement) { String c = queryStatement.substring(13, queryStatement.length() - 14); StringBuffer terminosBuscados = new StringBuffer(); String palabrasBuscadas = null; log("Query: " + queryStatement); while (c.startsWith("<term>")) { String term = new String(c.substring(6, c.indexOf("</term>"))); terminosBuscados.append(term); terminosBuscados.append(" "); c = c.substring(13 + term.length()); } palabrasBuscadas = terminosBuscados.deleteCharAt(terminosBuscados.length()).toString(); log(palabrasBuscadas); return palabrasBuscadas; }
From source file:com.ibm.rpe.web.service.docgen.impl.GenerateBaseTemplate.java
private static void writeContextInfo(List<BaseTemplateInput> inputDataList, String contextFilePath) throws FileNotFoundException { StringBuffer contextBuf = new StringBuffer(); if (inputDataList != null) { for (BaseTemplateInput data : inputDataList) { Map<String, String> params = data.getReplaceMap(); if (params != null && params.containsKey(TemplateConstants.QUERY_CONTEXT)) { String context = params.get(TemplateConstants.QUERY_CONTEXT); if (context != null && context.length() > 0) { contextBuf.append(data.getReplacement() == null ? TemplateConstants.DOCUMENT_TITLE : data.getReplacement()).append("=").append(context).append(";"); }//from w w w. j a v a 2s . co m } } if (contextBuf.length() > 0) { FileUtils.writeFile(contextFilePath, contextBuf.toString()); } } }
From source file:fiftyfive.wicket.util.LoggingUtils.java
/** * Formats a Map with on entry per line plus a specified indent. * Keys are padded and left-aligned so that they are all the same width. *///from w w w. j a va2 s. c o m private static String formatMapEntries(Collection entries, String indent) { StringBuffer buf = new StringBuffer(); int width = 1; for (Map.Entry e : (Collection<Map.Entry>) entries) { int length = e.getKey().toString().length(); if (length > width) { width = length; } } for (Map.Entry e : (Collection<Map.Entry>) entries) { if (buf.length() > 0) { buf.append(String.format("%n")); } buf.append(String.format("%s%-" + width + "s = %s", indent, e.getKey(), e.getValue() == null ? "N/A" : e.getValue())); } return buf.toString(); }
From source file:com.sfs.Formatter.java
/** * Gets a formatted string for the number of weeks supplied. * * @param weeks the weeks value//from ww w . ja va 2s.c o m * @return the formatted string */ public static String getFormattedDuration(final int weeks) { StringBuffer sb = new StringBuffer(); int partMonths = Formatter.getPartMonths(weeks); int partWeeks = Formatter.getPartWeeks(weeks); if (partMonths > 0) { sb.append(partMonths); sb.append(" month"); if (partMonths > 1) { sb.append("s"); } } if (partWeeks > 0) { if (sb.length() > 0) { sb.append(", "); } sb.append(partWeeks); sb.append(" week"); if (partWeeks > 1) { sb.append("s"); } } return sb.toString(); }
From source file:com.hangum.tadpole.engine.sql.util.export.HTMLExporter.java
/** * make content file/*from w w w .j a v a 2 s.c om*/ * * @param tableName * @param rsDAO * @return * @throws Exception */ public static String makeContentFile(String tableName, QueryExecuteResultDTO rsDAO) throws Exception { // full text String strTmpDir = PublicTadpoleDefine.TEMP_DIR + tableName + System.currentTimeMillis() + PublicTadpoleDefine.DIR_SEPARATOR; String strFile = tableName + ".html"; String strFullPath = strTmpDir + strFile; FileUtils.writeStringToFile(new File(strFullPath), HTMLDefine.sbHtml, true); FileUtils.writeStringToFile(new File(strFullPath), "<table class='tg'>", true); // make content List<Map<Integer, Object>> dataList = rsDAO.getDataList().getData(); // column . Map<Integer, String> mapLabelName = rsDAO.getColumnLabelName(); StringBuffer sbHead = new StringBuffer(); sbHead.append(String.format(strHead, "#")); for (int i = 1; i < mapLabelName.size(); i++) { sbHead.append(String.format(strHead, mapLabelName.get(i))); } String strLastColumnName = String.format(strGroup, sbHead.toString()); // header FileUtils.writeStringToFile(new File(strFullPath), strLastColumnName, true); // body start StringBuffer sbBody = new StringBuffer(""); for (int i = 0; i < dataList.size(); i++) { Map<Integer, Object> mapColumns = dataList.get(i); StringBuffer sbTmp = new StringBuffer(); sbTmp.append(String.format(strHead, "" + (i + 1))); //$NON-NLS-1$ for (int j = 1; j < mapColumns.size(); j++) { String strValue = mapColumns.get(j) == null ? "" : "" + mapColumns.get(j); sbTmp.append(String.format(strContent, StringEscapeUtils.unescapeHtml(strValue))); //$NON-NLS-1$ } sbBody.append(String.format(strGroup, sbTmp.toString())); if ((i % DATA_COUNT) == 0) { FileUtils.writeStringToFile(new File(strFullPath), sbBody.toString(), true); sbBody.delete(0, sbBody.length()); } } if (sbBody.length() > 0) { FileUtils.writeStringToFile(new File(strFullPath), sbBody.toString(), true); } FileUtils.writeStringToFile(new File(strFullPath), "</table>", true); return strFullPath; }
From source file:com.centeractive.ws.builder.soap.SchemaUtils.java
public static String toHtml(String string, int maxSize) { if (StringUtils.isBlank(string)) return "<html><body></body></html>"; BufferedReader st = new BufferedReader(new StringReader(string)); StringBuffer buf = new StringBuffer("<html><body>"); String str = null;// ww w . ja v a 2s .co m try { str = st.readLine(); while (str != null && (maxSize == 0 || (buf.length() + str.length()) < maxSize)) { if (str.equalsIgnoreCase("<br/>")) { str = "<br>"; } buf.append(str); if (!str.equalsIgnoreCase("<br>")) { buf.append("<br>"); } str = st.readLine(); } } catch (IOException e) { e.printStackTrace(); } if (str != null) buf.append("..."); buf.append("</body></html>"); string = buf.toString(); return string; }
From source file:com.qmetry.qaf.automation.step.client.text.BehaviorScanner.java
public static ArrayList<Object[]> scan(String strFile) { ArrayList<Object[]> rows = new ArrayList<Object[]>(); File textFile;//from w ww. j av a2 s . com int lineNo = 0; BufferedReader br = null; try { logger.info("loading text file: " + strFile); textFile = new File(strFile); br = new BufferedReader(new FileReader(textFile)); String strLine = ""; // file line by line // exclude blank lines and comments StringBuffer currLineBuffer = new StringBuffer(); while ((strLine = br.readLine()) != null) { // record line number lineNo++; /** * ignore if line is empty or comment line */ if (!("".equalsIgnoreCase(strLine.trim()) || COMMENT_CHARS.contains("" + strLine.trim().charAt(0)))) { currLineBuffer.append((strLine.trim())); if (strLine.endsWith(LINE_BREAK)) { /* * Statement not completed. Remove line break character * and continue statement reading from next line */ currLineBuffer.delete(currLineBuffer.length() - LINE_BREAK.length(), currLineBuffer.length()); } else { // process single statement Object[] cols = new Object[] { "", "", "", lineNo }; String currLine = currLineBuffer.toString(); if ((StringUtil.indexOfIgnoreCase(currLine, AbstractScenarioFileParser.SCENARIO) == 0) || (StringUtil.indexOfIgnoreCase(currLine, AbstractScenarioFileParser.STEP_DEF) == 0) || (StringUtil.indexOfIgnoreCase(currLine, "META") == 0)) { System.arraycopy(currLine.split(":", 2), 0, cols, 0, 2); // append meta-data in last/scenario statement if (StringUtil.indexOfIgnoreCase(((String) cols[0]).trim(), "META") == 0) { Object[] row = new Object[4]; int prevIndex = rows.size() - 1; Object[] prevRow = rows.remove(prevIndex); System.arraycopy(prevRow, 0, row, 0, 2); row[2] = ((String) cols[1]).trim(); row[3] = prevRow[3]; rows.add(row); currLineBuffer = new StringBuffer(); continue; } } else { // this is a statement cols[0] = currLine; } rows.add(cols); currLineBuffer = new StringBuffer(); } } } } catch (Exception e) { String strMsg = "Exception while reading BDD file: " + strFile + "#" + lineNo; logger.error(strMsg + e); throw new AutomationError(strMsg, e); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } return rows; }
From source file:org.lmn.fc.common.datatranslators.DataExporter.java
/*********************************************************************************************** * exportStringBuffer().// w ww .j a v a 2 s .c o m * Saves the StringBuffer at the specified location. * * @param filename * @param timestamp * @param format * @param buffer * @param log * @param clock * * @return boolean */ public static boolean exportStringBuffer(final String filename, final boolean timestamp, final DataFormat format, final StringBuffer buffer, final Vector<Vector> log, final ObservatoryClockInterface clock) { final String SOURCE = "DataExporter.exportStringBuffer()"; boolean boolSuccess; boolSuccess = false; if ((filename != null) && (!EMPTY_STRING.equals(filename)) && (format != null) && (buffer != null) && (buffer.length() > 0) && (log != null) && (clock != null)) { try { final File file; final OutputStream outputStream; file = new File(FileUtilities.buildFullFilename(filename, timestamp, format)); FileUtilities.overwriteFile(file); outputStream = new FileOutputStream(file); outputStream.write(buffer.toString().getBytes()); boolSuccess = true; // Tidy up outputStream.flush(); outputStream.close(); SimpleEventLogUIComponent.logEvent( log, EventStatus.INFO, METADATA_TARGET + format.getFileExtension() + TERMINATOR + METADATA_ACTION_EXPORT + METADATA_FILENAME + file.getAbsolutePath() + TERMINATOR, SOURCE, clock); } catch (SecurityException exception) { SimpleEventLogUIComponent.logEvent(log, EventStatus.FATAL, METADATA_TARGET + format.getFileExtension() + TERMINATOR + METADATA_ACTION_EXPORT + METADATA_RESULT + ERROR_ACCESS_DENIED + TERMINATOR + SPACE + METADATA_EXCEPTION + exception.getMessage() + TERMINATOR, SOURCE, clock); } catch (FileNotFoundException exception) { SimpleEventLogUIComponent.logEvent(log, EventStatus.FATAL, METADATA_TARGET + format.getFileExtension() + TERMINATOR + METADATA_ACTION_EXPORT + METADATA_RESULT + ERROR_FILE_NOT_FOUND + TERMINATOR + SPACE + METADATA_EXCEPTION + exception.getMessage() + TERMINATOR, SOURCE, clock); } catch (IOException exception) { SimpleEventLogUIComponent.logEvent(log, EventStatus.FATAL, METADATA_TARGET + format.getFileExtension() + TERMINATOR + METADATA_ACTION_EXPORT + METADATA_RESULT + ERROR_FILE_SAVE + TERMINATOR + SPACE + METADATA_EXCEPTION + exception.getMessage() + TERMINATOR, SOURCE, clock); } } else { SimpleEventLogUIComponent .logEvent( log, EventStatus.FATAL, METADATA_TARGET + format.getFileExtension() + TERMINATOR + METADATA_ACTION_EXPORT + METADATA_RESULT + ERROR_XML + TERMINATOR, SOURCE, clock); } return (boolSuccess); }