From 701b67c3153a6431ec6c7d18e41bc3202ef86a57 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 21 Nov 2019 22:01:20 +0000 Subject: [PATCH] replace more StringBuffers git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1870121 13f79535-47bb-0310-9956-ffa450edef68 --- .../poibrowser/PropertySetDescriptorRenderer.java | 4 ++-- .../poi/hssf/extractor/EventBasedExcelExtractor.java | 2 +- src/java/org/apache/poi/hssf/model/InternalSheet.java | 2 +- .../org/apache/poi/hssf/record/MergeCellsRecord.java | 2 +- .../poi/hssf/record/pivottable/PageItemRecord.java | 4 ++-- .../org/apache/poi/hssf/usermodel/FontDetails.java | 2 +- .../org/apache/poi/ss/formula/CellEvaluationFrame.java | 2 +- .../apache/poi/ss/formula/FormulaUsedBlankCellSet.java | 2 +- .../apache/poi/ss/formula/constant/ErrorConstant.java | 2 +- src/java/org/apache/poi/util/HexRead.java | 6 +++--- .../poi/hpbf/extractor/PublisherTextExtractor.java | 2 +- .../org/apache/poi/hslf/record/StyleTextPropAtom.java | 4 +--- .../org/apache/poi/hssf/usermodel/TestBugs.java | 10 ---------- .../function/ExcelFileFormatDocFunctionExtractor.java | 6 +++--- 14 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/examples/src/org/apache/poi/poifs/poibrowser/PropertySetDescriptorRenderer.java b/src/examples/src/org/apache/poi/poifs/poibrowser/PropertySetDescriptorRenderer.java index e6e55c0a27..153dc5e205 100644 --- a/src/examples/src/org/apache/poi/poifs/poibrowser/PropertySetDescriptorRenderer.java +++ b/src/examples/src/org/apache/poi/poifs/poibrowser/PropertySetDescriptorRenderer.java @@ -108,7 +108,7 @@ public class PropertySetDescriptorRenderer extends DocumentDescriptorRenderer */ protected String sectionsToString(final List
sections) { - final StringBuffer b = new StringBuffer(); + final StringBuilder b = new StringBuilder(); int count = 1; for (Iterator
i = sections.iterator(); i.hasNext();) { @@ -129,7 +129,7 @@ public class PropertySetDescriptorRenderer extends DocumentDescriptorRenderer */ protected String toString(final Section s, final String name) { - final StringBuffer b = new StringBuffer(); + final StringBuilder b = new StringBuilder(); b.append("\n" + name + " Format ID: "); b.append(HexDump.toHex(s.getFormatID().getBytes())); b.append("\n" + name + " Offset: " + s.getOffset()); diff --git a/src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java b/src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java index e49a66b2fe..11f2d46369 100644 --- a/src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java +++ b/src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java @@ -162,7 +162,7 @@ public class EventBasedExcelExtractor extends POIOLE2TextExtractor implements or private SSTRecord sstRecord; private final List sheetNames; - final StringBuffer _text = new StringBuffer(); + final StringBuilder _text = new StringBuilder(); private int sheetNum = -1; private int rowNum; diff --git a/src/java/org/apache/poi/hssf/model/InternalSheet.java b/src/java/org/apache/poi/hssf/model/InternalSheet.java index 4e8798e886..1b2531aee7 100644 --- a/src/java/org/apache/poi/hssf/model/InternalSheet.java +++ b/src/java/org/apache/poi/hssf/model/InternalSheet.java @@ -553,7 +553,7 @@ public final class InternalSheet { { log.log(POILogger.DEBUG, "Sheet.setDimensions"); log.log(POILogger.DEBUG, - (new StringBuffer("firstrow")).append(firstrow) + (new StringBuilder("firstrow")).append(firstrow) .append("firstcol").append(firstcol).append("lastrow") .append(lastrow).append("lastcol").append(lastcol) .toString()); diff --git a/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java b/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java index d1e5121154..c71cbb2b66 100644 --- a/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java +++ b/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java @@ -90,7 +90,7 @@ public final class MergeCellsRecord extends StandardRecord implements Cloneable @Override public String toString() { - StringBuffer retval = new StringBuffer(); + StringBuilder retval = new StringBuilder(); retval.append("[MERGEDCELLS]").append("\n"); retval.append(" .numregions =").append(getNumAreas()).append("\n"); diff --git a/src/java/org/apache/poi/hssf/record/pivottable/PageItemRecord.java b/src/java/org/apache/poi/hssf/record/pivottable/PageItemRecord.java index a41d2ca031..8d8a059cd4 100644 --- a/src/java/org/apache/poi/hssf/record/pivottable/PageItemRecord.java +++ b/src/java/org/apache/poi/hssf/record/pivottable/PageItemRecord.java @@ -52,7 +52,7 @@ public final class PageItemRecord extends StandardRecord { out.writeShort(_idObj); } - public void appendDebugInfo(StringBuffer sb) { + public void appendDebugInfo(StringBuilder sb) { sb.append('('); sb.append( "isxvi=").append(HexDump.shortToHex(_isxvi)); sb.append(" isxvd=").append(HexDump.shortToHex(_isxvd)); @@ -97,7 +97,7 @@ public final class PageItemRecord extends StandardRecord { @Override public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("[SXPI]\n"); for (int i = 0; i < _fieldInfos.length; i++) { diff --git a/src/java/org/apache/poi/hssf/usermodel/FontDetails.java b/src/java/org/apache/poi/hssf/usermodel/FontDetails.java index d40ec07fcd..d9fc1d54c2 100644 --- a/src/java/org/apache/poi/hssf/usermodel/FontDetails.java +++ b/src/java/org/apache/poi/hssf/usermodel/FontDetails.java @@ -156,7 +156,7 @@ public class FontDetails { if(max != -1 && i == listSize - 1) { - StringBuffer buf = new StringBuffer((text.length() * (listSize - i)) / listSize); + StringBuilder buf = new StringBuilder((text.length() * (listSize - i)) / listSize); while(tok.hasMoreTokens()) { buf.append(tok.nextToken()); diff --git a/src/java/org/apache/poi/ss/formula/CellEvaluationFrame.java b/src/java/org/apache/poi/ss/formula/CellEvaluationFrame.java index 46ab79b10f..b9c7efc678 100644 --- a/src/java/org/apache/poi/ss/formula/CellEvaluationFrame.java +++ b/src/java/org/apache/poi/ss/formula/CellEvaluationFrame.java @@ -40,7 +40,7 @@ final class CellEvaluationFrame { } public String toString() { - StringBuffer sb = new StringBuffer(64); + StringBuilder sb = new StringBuilder(64); sb.append(getClass().getName()).append(" ["); sb.append("]"); return sb.toString(); diff --git a/src/java/org/apache/poi/ss/formula/FormulaUsedBlankCellSet.java b/src/java/org/apache/poi/ss/formula/FormulaUsedBlankCellSet.java index 0bb94659ee..005c91dfac 100644 --- a/src/java/org/apache/poi/ss/formula/FormulaUsedBlankCellSet.java +++ b/src/java/org/apache/poi/ss/formula/FormulaUsedBlankCellSet.java @@ -158,7 +158,7 @@ final class FormulaUsedBlankCellSet { } @Override public String toString() { - StringBuffer sb = new StringBuffer(64); + StringBuilder sb = new StringBuilder(64); CellReference crA = new CellReference(_firstRowIndex, _firstColumnIndex, false, false); CellReference crB = new CellReference(_lastRowIndex, _lastColumnIndex, false, false); sb.append(getClass().getName()); diff --git a/src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java b/src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java index 79dd23b92a..b39c322331 100644 --- a/src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java +++ b/src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java @@ -71,7 +71,7 @@ public class ErrorConstant { } public String toString() { - StringBuffer sb = new StringBuffer(64); + StringBuilder sb = new StringBuilder(64); sb.append(getClass().getName()).append(" ["); sb.append(getText()); sb.append("]"); diff --git a/src/java/org/apache/poi/util/HexRead.java b/src/java/org/apache/poi/util/HexRead.java index 0acaef6e27..a7bec002f9 100644 --- a/src/java/org/apache/poi/util/HexRead.java +++ b/src/java/org/apache/poi/util/HexRead.java @@ -55,7 +55,7 @@ public class HexRead { */ public static byte[] readData(InputStream stream, String section ) throws IOException { try { - StringBuffer sectionText = new StringBuffer(); + StringBuilder sectionText = new StringBuilder(); boolean inSection = false; int c = stream.read(); while ( c != -1 ) { @@ -66,12 +66,12 @@ public class HexRead { case '\n': case '\r': inSection = false; - sectionText = new StringBuffer(); + sectionText = new StringBuilder(); break; case ']': inSection = false; if ( sectionText.toString().equals( section ) ) return readData( stream, '[' ); - sectionText = new StringBuffer(); + sectionText = new StringBuilder(); break; default: if ( inSection ) sectionText.append( (char) c ); diff --git a/src/scratchpad/src/org/apache/poi/hpbf/extractor/PublisherTextExtractor.java b/src/scratchpad/src/org/apache/poi/hpbf/extractor/PublisherTextExtractor.java index ec1dc82b75..27f62aeeec 100644 --- a/src/scratchpad/src/org/apache/poi/hpbf/extractor/PublisherTextExtractor.java +++ b/src/scratchpad/src/org/apache/poi/hpbf/extractor/PublisherTextExtractor.java @@ -61,7 +61,7 @@ public final class PublisherTextExtractor extends POIOLE2TextExtractor { public String getText() { - StringBuffer text = new StringBuffer(); + StringBuilder text = new StringBuilder(); // Get the text from the Quill Contents QCBit[] bits = doc.getQuillContents().getBits(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java index 372c52d9ad..c0d13c0e64 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java @@ -369,13 +369,11 @@ public final class StyleTextPropAtom extends RecordAtom { /** - * Dump the record content into StringBuffer - * * @return the string representation of the record data */ @Override public String toString(){ - StringBuffer out = new StringBuffer(); + StringBuilder out = new StringBuilder(); out.append("StyleTextPropAtom:\n"); if (!initialised) { diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 9d9c277def..46056ff82e 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -359,16 +359,6 @@ public final class TestBugs extends BaseTestBugzillaIssues { assertEquals(a.getRichStringCellValue().getString(), b.getRichStringCellValue().getString()); } - /*private static String unicodeString(HSSFCell cell) { - String ss = cell.getRichStringCellValue().getString(); - char s[] = ss.toCharArray(); - StringBuffer sb = new StringBuffer(); - for (int x=0;x _rowData; - private final StringBuffer _textNodeBuffer; + private final StringBuilder _textNodeBuffer; private final List _rowNoteFlags; private boolean _cellHasNote; @@ -268,7 +268,7 @@ public final class ExcelFileFormatDocFunctionExtractor { _elemNameStack = new Stack<>(); _isInsideTable = false; _rowData = new ArrayList<>(); - _textNodeBuffer = new StringBuffer(); + _textNodeBuffer = new StringBuilder(); _rowNoteFlags = new ArrayList<>(); } -- 2.39.5