List of usage examples for java.lang StringBuffer capacity
@Override public synchronized int capacity()
From source file:MainClass.java
public static void main(String args[]) { StringBuffer sb = new StringBuffer(40); System.out.println(sb);//from ww w .j a va 2s .c o m System.out.println("Length: " + sb.length()); System.out.println("Capacity:" + sb.capacity()); }
From source file:StringBufferDemo.java
public static void main(String args[]) { StringBuffer sb = new StringBuffer("Hello"); System.out.println("buffer = " + sb); System.out.println("length = " + sb.length()); System.out.println("capacity = " + sb.capacity()); }
From source file:MainClass.java
public static void main(String[] args) { StringBuffer sb = new StringBuffer("abc"); System.out.println("sb = " + sb); System.out.println("Length = " + sb.length()); System.out.println("Capacity = " + sb.capacity()); sb.setLength(2);// ww w. j a va 2 s. c o m System.out.println("sb = " + sb); System.out.println("Length = " + sb.length()); System.out.println("Capacity = " + sb.capacity()); sb.setLength(4); System.out.println("sb = " + sb); System.out.println("Length = " + sb.length()); System.out.println("Capacity = " + sb.capacity()); }
From source file:com.ing.connector.util.WStringUtil.java
/** * Pad to string to the right to "length" using character "c". * Warning: if string.length() > length then "string" is returned, not truncated *///from w w w .j a va 2 s. c o m public static String padStringRight(String string, int length, char c) { StringBuffer sb = new StringBuffer(length); sb.append(string); while (sb.length() < sb.capacity()) sb.append(c); return sb.toString(); }
From source file:hydrograph.ui.expression.editor.datastructure.MethodDetails.java
private void createPlaceHolderFromSource(IMethod iMethod, String className) throws JavaModelException { StringBuffer buffer = new StringBuffer(iMethod.getSource()); int indexOfPlaceHolder = buffer.lastIndexOf("@see"); if (indexOfPlaceHolder != -1 && iMethod.getParameterNames() != null && iMethod.getParameterNames().length > 0) { buffer = buffer.delete(0, indexOfPlaceHolder + 4); buffer = buffer.delete(buffer.indexOf("\n") + 1, buffer.capacity()); if (StringUtils.contains(buffer.toString(), className + Constants.DOT + iMethod.getElementName())) { placeHolder = StringUtils.trim(buffer.toString()); } else/* w w w . j av a2 s .c o m*/ placeHolder = createDefaultPlaceHolder(iMethod, className); } else { placeHolder = createDefaultPlaceHolder(iMethod, className); } }
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;/* ww w .j a va 2 s .c o m*/ 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:analytics.storage.store2csv.java
@Override public void storeElementValueData(HashMap<String, Integer> data, String metricName, String dataProvider, String analysisType, String headerColumn, String element, Logger logger, int time) { // TODO Auto-generated method stub String sFileName = dataProvider + analysisType + ".csv"; Properties props = new Properties(); try {// w w w.j a v a2 s . c o m props.load(new FileInputStream("configure.properties")); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); System.exit(-1); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); System.exit(-1); } ; File anls = new File(props.getProperty(AnalyticsConstants.resultsPath) + "Analysis_Results"); if (!anls.exists()) anls.mkdir(); else { // if (temporal == false) { // FileUtils.deleteQuietly(anls); // anls.mkdir(); // } } File dir = new File(anls, dataProvider); if (!dir.exists()) dir.mkdir(); File file = new File(dir, sFileName); FileWriter writer; BufferedWriter bw = null; BufferedReader reader = null; try { if (file.exists() && time == 0) file.delete(); // if (!file.exists() && time == 0) { writer = new FileWriter(file); bw = new BufferedWriter(writer); createHeaders(bw, metricName, headerColumn); Set<String> keySet = data.keySet(); Iterator<String> iterator = keySet.iterator(); StringBuffer logString = new StringBuffer(); StringBuffer key = new StringBuffer(); while (iterator.hasNext()) { // String key = iterator.next(); key.append(iterator.next()); Integer value = data.get(key.toString()); if (key.toString().contains(",")) key.replace(0, key.length(), key.toString().replace(",", "/")); // key = key.toString().replace(",", "/"); // bw.append(element); // bw.append(','); bw.append(key); logString.append(dataProvider); logString.append(" " + element); logString.append(" " + key.toString().replace(" ", "_")); // logString.append(" " + key.replace(" ", "_")); bw.append(','); bw.append(String.valueOf(value)); logString.append(" " + String.valueOf(value)); bw.newLine(); logger.info(logString.toString()); logString.delete(0, logString.capacity()); key.delete(0, key.length()); } bw.close(); // } else if (file.exists() && time == 0) { // file.delete(); // writer = new FileWriter(file); // bw = new BufferedWriter(writer); // createHeaders(bw, metricName, headerColumn); // // Set<String> keySet = data.keySet(); // Iterator<String> iterator = keySet.iterator(); // StringBuffer logString = new StringBuffer(); // // StringBuffer key = new StringBuffer(); // // while (iterator.hasNext()) { // // String key = iterator.next(); // key.append(iterator.next()); // // Integer value = data.get(key.toString()); // // if (key.toString().contains(",")) // key.replace(0, key.length(), // key.toString().replace(",", "/")); // // key = key.toString().replace(",", "/"); // // // bw.append(element); // // bw.append(','); // bw.append(key); // logString.append(dataProvider); // logString.append(" " + element); // logString.append(" " + key.toString().replace(" ", "_")); // // logString.append(" " + key.replace(" ", "_")); // bw.append(','); // bw.append(String.valueOf(value)); // logString.append(" " + String.valueOf(value)); // bw.newLine(); // // logger.info(logString.toString()); // logString.delete(0, logString.capacity()); // key.delete(0, key.length()); // } // bw.close(); // } else if (file.exists() && time > 0) { // // reader = new BufferedReader(new FileReader(file)); // // File temp = new File(dir, "temp.csv"); // // writer = new FileWriter(temp); // bw = new BufferedWriter(writer); // // String line; // int counter = 0; // // // Set<String> keySet = data.keySet(); // // Iterator<String> iterator = keySet.iterator(); // StringBuffer logString = new StringBuffer(); // StringBuffer key = new StringBuffer(); // while ((line = reader.readLine()) != null) { // String[] split = line.split(","); // // System.out.println(line); // // if (counter == 0) { // line = line + "," + metricName; // bw.append(line); // bw.newLine(); // // } else { // // String key = iterator.next(); // // String key = split[0]; // key.append(split[0]); // Integer value = data.get(key); // // // if (key.contains(",")) // // key = key.replace(",", "/"); // if (key.toString().contains(",")) // key.replace(0, key.length(), key.toString() // .replace(",", "/")); // // line = line + "," + value; // bw.append(line); // logString.append(dataProvider); // logString.append(" " + element); // logString // .append(" " + key.toString().replace(" ", "_")); // logString.append(" " + value); // // bw.newLine(); // // logger.info(logString.toString()); // logString.delete(0, logString.capacity()); // key.delete(0, key.length()); // } // // counter += 1; // // } // bw.close(); // FileUtils.copyFile(temp, file); // temp.delete(); // reader.close(); // // } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { if (bw != null) bw.close(); if (reader != null) reader.close(); } catch (IOException ex) { ex.printStackTrace(); } } }