From 2a982f62ec48a8445e7355fbe6901f4d0c63712e Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Fri, 29 Nov 2019 23:57:35 +0000 Subject: [PATCH] Replace StringBuffer with StringBuilder git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1870600 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/extractor/OldExcelExtractor.java | 10 ++-- .../poi/hssf/record/PageBreakRecord.java | 2 +- .../poi/hssf/usermodel/HSSFPalette.java | 11 +--- .../apache/poi/poifs/dev/POIFSViewEngine.java | 4 +- .../org/apache/poi/poifs/dev/POIFSViewer.java | 2 +- .../poifs/filesystem/DocumentDescriptor.java | 2 +- .../poifs/filesystem/POIFSDocumentPath.java | 2 +- .../poi/ss/formula/SheetIdentifier.java | 11 ++-- .../poi/ss/formula/SheetRangeIdentifier.java | 2 +- .../poi/ss/formula/functions/Countif.java | 9 +--- .../poi/util/GenericRecordJsonWriter.java | 30 +++++------ .../poi/util/GenericRecordXmlWriter.java | 26 +++++----- .../poi/hmef/attribute/TNEFProperty.java | 12 +---- .../org/apache/poi/hpbf/dev/HPBFDumper.java | 2 +- .../QuickButCruddyTextExtractor.java | 2 +- .../poi/hslf/record/AnimationInfoAtom.java | 33 ++++++------ .../apache/poi/hslf/record/ExMediaAtom.java | 12 ++--- .../apache/poi/hslf/record/ExOleObjAtom.java | 13 ++--- .../poi/hslf/record/HeadersFootersAtom.java | 21 ++++---- .../apache/poi/hslf/record/TextBytesAtom.java | 7 +-- .../apache/poi/hslf/record/TextCharsAtom.java | 7 +-- .../apache/poi/hsmf/datatypes/ByteChunk.java | 2 +- .../poi/hsmf/datatypes/MAPIProperty.java | 12 +---- .../hsmf/extractor/OutlookTextExtactor.java | 4 +- .../poi/hwpf/converter/AbstractWordUtils.java | 14 ++++-- .../poi/hwpf/extractor/Word6Extractor.java | 5 +- .../poi/hwpf/extractor/WordExtractor.java | 6 +-- .../poi/hwpf/model/EscherRecordHolder.java | 2 +- .../org/apache/poi/hwpf/model/FSPATable.java | 19 +++---- .../poi/hwpf/model/types/FLDAbstractType.java | 50 ++++++------------- .../poi/hwpf/model/types/TLPAbstractType.java | 41 +++++---------- .../apache/poi/hwpf/usermodel/BorderCode.java | 37 ++++---------- .../poi/hssf/record/TestTextObjectRecord.java | 3 +- 33 files changed, 153 insertions(+), 262 deletions(-) diff --git a/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java b/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java index e056e49513..9356209316 100644 --- a/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java +++ b/src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java @@ -40,7 +40,11 @@ import org.apache.poi.hssf.record.OldSheetRecord; import org.apache.poi.hssf.record.OldStringRecord; import org.apache.poi.hssf.record.RKRecord; import org.apache.poi.hssf.record.RecordInputStream; -import org.apache.poi.poifs.filesystem.*; +import org.apache.poi.poifs.filesystem.DirectoryNode; +import org.apache.poi.poifs.filesystem.DocumentNode; +import org.apache.poi.poifs.filesystem.FileMagic; +import org.apache.poi.poifs.filesystem.NotOLE2FileException; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.util.IOUtils; @@ -219,7 +223,7 @@ public class OldExcelExtractor implements Closeable { * @return the text contents of the file */ public String getText() { - StringBuffer text = new StringBuffer(); + StringBuilder text = new StringBuilder(); // To track formats and encodings CodepageRecord codepage = null; @@ -306,7 +310,7 @@ public class OldExcelExtractor implements Closeable { } } - protected void handleNumericCell(StringBuffer text, double value) { + protected void handleNumericCell(StringBuilder text, double value) { // TODO Need to fetch / use format strings text.append(value); text.append('\n'); diff --git a/src/java/org/apache/poi/hssf/record/PageBreakRecord.java b/src/java/org/apache/poi/hssf/record/PageBreakRecord.java index 9e053918bd..a1d86247dc 100644 --- a/src/java/org/apache/poi/hssf/record/PageBreakRecord.java +++ b/src/java/org/apache/poi/hssf/record/PageBreakRecord.java @@ -119,7 +119,7 @@ public abstract class PageBreakRecord extends StandardRecord { } public String toString() { - StringBuffer retval = new StringBuffer(); + StringBuilder retval = new StringBuilder(); String label; String mainLabel; diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java index 7aeabe92c4..b74bf1b570 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java @@ -212,15 +212,8 @@ public final class HSSFPalette { } @Override - public String getHexString() - { - StringBuffer sb = new StringBuffer(); - sb.append(getGnumericPart(_red)); - sb.append(':'); - sb.append(getGnumericPart(_green)); - sb.append(':'); - sb.append(getGnumericPart(_blue)); - return sb.toString(); + public String getHexString() { + return getGnumericPart(_red) + ":" + getGnumericPart(_green) + ":" + getGnumericPart(_blue); } private String getGnumericPart(byte color) diff --git a/src/java/org/apache/poi/poifs/dev/POIFSViewEngine.java b/src/java/org/apache/poi/poifs/dev/POIFSViewEngine.java index dc4dd547cc..8db1bf3129 100644 --- a/src/java/org/apache/poi/poifs/dev/POIFSViewEngine.java +++ b/src/java/org/apache/poi/poifs/dev/POIFSViewEngine.java @@ -101,8 +101,8 @@ public class POIFSViewEngine private static String indent(final int indentLevel, final String indentString, final String data) { - StringBuffer finalBuffer = new StringBuffer(); - StringBuffer indentPrefix = new StringBuffer(); + StringBuilder finalBuffer = new StringBuilder(); + StringBuilder indentPrefix = new StringBuilder(); for (int j = 0; j < indentLevel; j++) { diff --git a/src/java/org/apache/poi/poifs/dev/POIFSViewer.java b/src/java/org/apache/poi/poifs/dev/POIFSViewer.java index 18095397f6..0be693444f 100644 --- a/src/java/org/apache/poi/poifs/dev/POIFSViewer.java +++ b/src/java/org/apache/poi/poifs/dev/POIFSViewer.java @@ -55,7 +55,7 @@ public final class POIFSViewer { private static void viewFile(String filename, boolean printName) { if (printName) { - StringBuffer flowerbox = new StringBuffer(); + StringBuilder flowerbox = new StringBuilder(); flowerbox.append("."); for (int j = 0; j < filename.length(); j++) { diff --git a/src/java/org/apache/poi/poifs/filesystem/DocumentDescriptor.java b/src/java/org/apache/poi/poifs/filesystem/DocumentDescriptor.java index 3038224214..0c1b2c8177 100644 --- a/src/java/org/apache/poi/poifs/filesystem/DocumentDescriptor.java +++ b/src/java/org/apache/poi/poifs/filesystem/DocumentDescriptor.java @@ -104,7 +104,7 @@ public class DocumentDescriptor public String toString() { - StringBuffer buffer = new StringBuffer(40 * (path.length() + 1)); + StringBuilder buffer = new StringBuilder(40 * (path.length() + 1)); for (int j = 0; j < path.length(); j++) { diff --git a/src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java b/src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java index 80db4b3c48..d32214e024 100644 --- a/src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java +++ b/src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java @@ -284,7 +284,7 @@ public class POIFSDocumentPath public String toString() { - final StringBuffer b = new StringBuffer(); + final StringBuilder b = new StringBuilder(); final int l = length(); b.append(File.separatorChar); diff --git a/src/java/org/apache/poi/ss/formula/SheetIdentifier.java b/src/java/org/apache/poi/ss/formula/SheetIdentifier.java index 71c7cd0f0c..51c0852b30 100644 --- a/src/java/org/apache/poi/ss/formula/SheetIdentifier.java +++ b/src/java/org/apache/poi/ss/formula/SheetIdentifier.java @@ -31,7 +31,7 @@ public class SheetIdentifier { public NameIdentifier getSheetIdentifier() { return _sheetIdentifier; } - protected void asFormulaString(StringBuffer sb) { + protected void asFormulaString(StringBuilder sb) { if (_bookName != null) { sb.append(" [").append(_sheetIdentifier.getName()).append("]"); } @@ -42,16 +42,11 @@ public class SheetIdentifier { } } public String asFormulaString() { - StringBuffer sb = new StringBuffer(32); + StringBuilder sb = new StringBuilder(32); asFormulaString(sb); return sb.toString(); } public String toString() { - StringBuffer sb = new StringBuffer(64); - sb.append(getClass().getName()); - sb.append(" ["); - asFormulaString(sb); - sb.append("]"); - return sb.toString(); + return getClass().getName() + " [" + asFormulaString() + "]"; } } \ No newline at end of file diff --git a/src/java/org/apache/poi/ss/formula/SheetRangeIdentifier.java b/src/java/org/apache/poi/ss/formula/SheetRangeIdentifier.java index c0b851ed57..8cb5b3201a 100644 --- a/src/java/org/apache/poi/ss/formula/SheetRangeIdentifier.java +++ b/src/java/org/apache/poi/ss/formula/SheetRangeIdentifier.java @@ -30,7 +30,7 @@ public class SheetRangeIdentifier extends SheetIdentifier { public NameIdentifier getLastSheetIdentifier() { return _lastSheetIdentifier; } - protected void asFormulaString(StringBuffer sb) { + protected void asFormulaString(StringBuilder sb) { super.asFormulaString(sb); sb.append(':'); if (_lastSheetIdentifier.isQuoted()) { diff --git a/src/java/org/apache/poi/ss/formula/functions/Countif.java b/src/java/org/apache/poi/ss/formula/functions/Countif.java index 4ae0874eb0..1f37d2e433 100644 --- a/src/java/org/apache/poi/ss/formula/functions/Countif.java +++ b/src/java/org/apache/poi/ss/formula/functions/Countif.java @@ -165,12 +165,7 @@ public final class Countif extends Fixed2ArgFunction { } @Override public final String toString() { - StringBuffer sb = new StringBuffer(64); - sb.append(getClass().getName()).append(" ["); - sb.append(_operator.getRepresentation()); - sb.append(getValueText()); - sb.append("]"); - return sb.toString(); + return getClass().getName() + " [" + _operator.getRepresentation() + getValueText() + "]"; } protected abstract String getValueText(); } @@ -386,7 +381,7 @@ public final class Countif extends Fixed2ArgFunction { */ public static Pattern getWildCardPattern(String value) { int len = value.length(); - StringBuffer sb = new StringBuffer(len); + StringBuilder sb = new StringBuilder(len); boolean hasWildCard = false; for(int i=0; i"); - final Matcher m = ESC_CHARS.matcher(o.toString()); - final StringBuffer sb = new StringBuffer(); + final String str = o.toString(); + final Matcher m = ESC_CHARS.matcher(str); + int pos = 0; while (m.find()) { - String repl; + fw.write(str, pos, m.start()); String match = m.group(); switch (match) { case "<": - repl = "<"; + fw.write("<"); break; case ">": - repl = ">"; + fw.write(">"); break; case "&": - repl = "&"; + fw.write("&"); break; case "\'": - repl = "'"; + fw.write("'"); break; case "\"": - repl = """; + fw.write("""); break; default: - repl = "&#x" + Long.toHexString(match.codePointAt(0)) + ";"; + fw.write("&#x"); + fw.write(Long.toHexString(match.codePointAt(0))); + fw.write(";"); break; } - m.appendReplacement(sb, repl); + pos = m.end(); } - m.appendTail(sb); - fw.write(sb.toString()); + fw.append(str, pos, str.length()); closeName(name+">"); return true; } diff --git a/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFProperty.java b/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFProperty.java index 9fafcf0dce..e90c910470 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFProperty.java +++ b/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFProperty.java @@ -201,16 +201,6 @@ public final class TNEFProperty { } public String toString() { - StringBuffer str = new StringBuffer(); - str.append(name); - str.append(" ["); - str.append(id); - str.append("]"); - if(mapiProperty != null) { - str.append(" ("); - str.append(mapiProperty); - str.append(")"); - } - return str.toString(); + return name + " [" + id + "]" + (mapiProperty == null ? "" : " (" + mapiProperty + ")"); } } diff --git a/src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java b/src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java index 0a96a54843..c31ee059be 100644 --- a/src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java +++ b/src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java @@ -61,7 +61,7 @@ public final class HPBFDumper { * two chars */ private String dumpBytes(byte[] data, int offset, int len) { - StringBuffer ret = new StringBuffer(); + StringBuilder ret = new StringBuilder(); for(int i=0; i textV = getTextAsVector(); for(String text : textV) { ret.append(text); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java index b7636d2da0..2f1306a3f8 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java @@ -282,24 +282,23 @@ public final class AnimationInfoAtom extends RecordAtom { } public String toString(){ - StringBuffer buf = new StringBuffer(); - buf.append("AnimationInfoAtom\n"); - buf.append("\tDimColor: " + getDimColor() + "\n"); int mask = getMask(); - buf.append("\tMask: " + mask + ", 0x"+Integer.toHexString(mask)+"\n"); - buf.append("\t Reverse: " + getFlag(Reverse)+"\n"); - buf.append("\t Automatic: " + getFlag(Automatic)+"\n"); - buf.append("\t Sound: " + getFlag(Sound)+"\n"); - buf.append("\t StopSound: " + getFlag(StopSound)+"\n"); - buf.append("\t Play: " + getFlag(Play)+"\n"); - buf.append("\t Synchronous: " + getFlag(Synchronous)+"\n"); - buf.append("\t Hide: " + getFlag(Hide)+"\n"); - buf.append("\t AnimateBg: " + getFlag(AnimateBg)+"\n"); - buf.append("\tSoundIdRef: " + getSoundIdRef() + "\n"); - buf.append("\tDelayTime: " + getDelayTime() + "\n"); - buf.append("\tOrderID: " + getOrderID() + "\n"); - buf.append("\tSlideCount: " + getSlideCount() + "\n"); - return buf.toString(); + return + "AnimationInfoAtom\n"+ + "\tDimColor: " + getDimColor() + "\n" + + "\tMask: " + mask + ", 0x"+Integer.toHexString(mask)+"\n" + + "\t Reverse: " + getFlag(Reverse)+"\n" + + "\t Automatic: " + getFlag(Automatic)+"\n" + + "\t Sound: " + getFlag(Sound)+"\n" + + "\t StopSound: " + getFlag(StopSound)+"\n" + + "\t Play: " + getFlag(Play)+"\n" + + "\t Synchronous: " + getFlag(Synchronous)+"\n" + + "\t Hide: " + getFlag(Hide)+"\n" + + "\t AnimateBg: " + getFlag(AnimateBg)+"\n" + + "\tSoundIdRef: " + getSoundIdRef() + "\n" + + "\tDelayTime: " + getDelayTime() + "\n" + + "\tOrderID: " + getOrderID() + "\n" + + "\tSlideCount: " + getSlideCount() + "\n"; } @Override diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExMediaAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExMediaAtom.java index 97e2594ad1..b8db11ad78 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExMediaAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExMediaAtom.java @@ -24,6 +24,7 @@ import java.io.OutputStream; import java.util.Map; import java.util.function.Supplier; +import org.apache.poi.util.GenericRecordJsonWriter; import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; @@ -169,15 +170,8 @@ public final class ExMediaAtom extends RecordAtom setMask(mask); } - public String toString(){ - StringBuffer buf = new StringBuffer(); - buf.append("ExMediaAtom\n"); - buf.append("\tObjectId: " + getObjectId() + "\n"); - buf.append("\tMask : " + getMask() + "\n"); - buf.append("\t fLoop : " + getFlag(fLoop) + "\n"); - buf.append("\t fRewind : " + getFlag(fRewind) + "\n"); - buf.append("\t fNarration : " + getFlag(fNarration) + "\n"); - return buf.toString(); + public String toString() { + return GenericRecordJsonWriter.marshal(this); } @Override diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjAtom.java index 0b0b66ebab..b8c77a747c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjAtom.java @@ -25,6 +25,7 @@ import java.io.OutputStream; import java.util.Map; import java.util.function.Supplier; +import org.apache.poi.util.GenericRecordJsonWriter; import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; @@ -341,16 +342,8 @@ public class ExOleObjAtom extends RecordAtom { out.write(_data); } - public String toString(){ - StringBuffer buf = new StringBuffer(); - buf.append("ExOleObjAtom\n"); - buf.append(" drawAspect: " + getDrawAspect() + "\n"); - buf.append(" type: " + getType() + "\n"); - buf.append(" objID: " + getObjID() + "\n"); - buf.append(" subType: " + getSubType() + "\n"); - buf.append(" objStgDataRef: " + getObjStgDataRef() + "\n"); - buf.append(" options: " + getOptions() + "\n"); - return buf.toString(); + public String toString() { + return GenericRecordJsonWriter.marshal(this); } @Override diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersAtom.java index ee6e645ee1..f175848ff1 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersAtom.java @@ -246,17 +246,16 @@ public final class HeadersFootersAtom extends RecordAtom { } public String toString(){ - StringBuffer buf = new StringBuffer(); - buf.append("HeadersFootersAtom\n"); - buf.append("\tFormatId: " + getFormatId() + "\n"); - buf.append("\tMask : " + getMask() + "\n"); - buf.append("\t fHasDate : " + getFlag(fHasDate) + "\n"); - buf.append("\t fHasTodayDate : " + getFlag(fHasTodayDate) + "\n"); - buf.append("\t fHasUserDate : " + getFlag(fHasUserDate) + "\n"); - buf.append("\t fHasSlideNumber : " + getFlag(fHasSlideNumber) + "\n"); - buf.append("\t fHasHeader : " + getFlag(fHasHeader) + "\n"); - buf.append("\t fHasFooter : " + getFlag(fHasFooter) + "\n"); - return buf.toString(); + return + "HeadersFootersAtom\n" + + "\tFormatId: " + getFormatId() + "\n" + + "\tMask : " + getMask() + "\n" + + "\t fHasDate : " + getFlag(fHasDate) + "\n" + + "\t fHasTodayDate : " + getFlag(fHasTodayDate) + "\n" + + "\t fHasUserDate : " + getFlag(fHasUserDate) + "\n" + + "\t fHasSlideNumber : " + getFlag(fHasSlideNumber) + "\n" + + "\t fHasHeader : " + getFlag(fHasHeader) + "\n" + + "\t fHasFooter : " + getFlag(fHasFooter) + "\n"; } @Override diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java index e5f8d4f4dc..cd84b7b8da 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java @@ -22,8 +22,8 @@ import java.io.OutputStream; import java.util.Map; import java.util.function.Supplier; +import org.apache.poi.util.GenericRecordJsonWriter; import org.apache.poi.util.GenericRecordUtil; -import org.apache.poi.util.HexDump; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.StringUtil; @@ -114,10 +114,7 @@ public final class TextBytesAtom extends RecordAtom { */ @Override public String toString() { - StringBuffer out = new StringBuffer(); - out.append( "TextBytesAtom:\n"); - out.append( HexDump.dump(_text, 0, 0) ); - return out.toString(); + return GenericRecordJsonWriter.marshal(this); } @Override diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java index 0e8b95b3ab..078f1d9ef7 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java @@ -22,8 +22,8 @@ import java.io.OutputStream; import java.util.Map; import java.util.function.Supplier; +import org.apache.poi.util.GenericRecordJsonWriter; import org.apache.poi.util.GenericRecordUtil; -import org.apache.poi.util.HexDump; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.StringUtil; @@ -110,10 +110,7 @@ public final class TextCharsAtom extends RecordAtom { */ @Override public String toString() { - StringBuffer out = new StringBuffer(); - out.append( "TextCharsAtom:\n"); - out.append( HexDump.dump(_text, 0, 0) ); - return out.toString(); + return GenericRecordJsonWriter.marshal(this); } @Override diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java index 57f56ab29d..ab5ca3a84e 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java @@ -81,7 +81,7 @@ public class ByteChunk extends Chunk { return "(Null Byte Array)"; } - StringBuffer text = new StringBuffer(); + StringBuilder text = new StringBuilder(); text.append("Bytes len=").append(value.length); text.append(" ["); diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MAPIProperty.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MAPIProperty.java index ba54f70101..28c3b8c00c 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MAPIProperty.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MAPIProperty.java @@ -1075,17 +1075,7 @@ public class MAPIProperty { @Override public String toString() { - StringBuffer str = new StringBuffer(); - str.append(name); - str.append(" ["); - str.append(id); - str.append("]"); - if (mapiProperty != null) { - str.append(" ("); - str.append(mapiProperty); - str.append(")"); - } - return str.toString(); + return name + " [" + id + "]" + (mapiProperty == null ? "" : " (" + mapiProperty + ")"); } public static MAPIProperty get(int id) { diff --git a/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java b/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java index 0d820b8dc2..f205dbffa2 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java @@ -73,7 +73,7 @@ public class OutlookTextExtactor extends POIOLE2TextExtractor { */ public String getText() { MAPIMessage msg = (MAPIMessage)document; - StringBuffer s = new StringBuffer(); + StringBuilder s = new StringBuilder(); // See if we can get a suitable encoding for any // non unicode text in the file @@ -158,7 +158,7 @@ public class OutlookTextExtactor extends POIOLE2TextExtractor { * of emails, and does its best to return something like * "Nick ; Jim " */ - protected void handleEmails(StringBuffer s, String type, String displayText, StringsIterator emails) { + protected void handleEmails(StringBuilder s, String type, String displayText, StringsIterator emails) { if(displayText == null || displayText.length() == 0) { return; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java index 6c17397289..0e3c8695ab 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java @@ -20,7 +20,11 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.*; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.TreeSet; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFDocumentCore; @@ -227,7 +231,7 @@ public class AbstractWordUtils public static String getBulletText( NumberingState numberingState, HWPFList list, char level ) { - StringBuffer bulletBuffer = new StringBuffer(); + StringBuilder bulletBuffer = new StringBuilder(); char[] xst = list.getNumberText( level ).toCharArray(); for ( char element : xst ) { @@ -240,17 +244,17 @@ public class AbstractWordUtils if ( !list.isStartAtOverriden( element ) && numberingState.levels.containsKey( key ) ) { - num = numberingState.levels.get( key ).intValue(); + num = numberingState.levels.get( key ); if ( level == element ) { num++; - numberingState.levels.put( key, Integer.valueOf( num ) ); + numberingState.levels.put( key, num ); } } else { num = list.getStartAt( element ); - numberingState.levels.put( key, Integer.valueOf( num ) ); + numberingState.levels.put( key, num ); } if ( level == element ) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/extractor/Word6Extractor.java b/src/scratchpad/src/org/apache/poi/hwpf/extractor/Word6Extractor.java index 6a770bf15c..1d509dd1c6 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/extractor/Word6Extractor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/extractor/Word6Extractor.java @@ -20,10 +20,9 @@ package org.apache.poi.hwpf.extractor; import java.io.IOException; import java.io.InputStream; -import org.apache.poi.hwpf.converter.WordToTextConverter; - import org.apache.poi.extractor.POIOLE2TextExtractor; import org.apache.poi.hwpf.HWPFOldDocument; +import org.apache.poi.hwpf.converter.WordToTextConverter; import org.apache.poi.hwpf.usermodel.Range; import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.POIFSFileSystem; @@ -123,7 +122,7 @@ public final class Word6Extractor extends POIOLE2TextExtractor { catch ( Exception exc ) { // fall-back - StringBuffer text = new StringBuffer(); + StringBuilder text = new StringBuilder(); for ( String t : getParagraphText() ) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordExtractor.java b/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordExtractor.java index eadc454d8b..62c106ef3e 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordExtractor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordExtractor.java @@ -159,7 +159,7 @@ public final class WordExtractor extends POIOLE2TextExtractor { /** * Add the header/footer text, if it's not empty */ - private void appendHeaderFooter( String text, StringBuffer out ) { + private void appendHeaderFooter( String text, StringBuilder out ) { if ( text == null || text.length() == 0 ) return; @@ -186,7 +186,7 @@ public final class WordExtractor extends POIOLE2TextExtractor { public String getHeaderText() { HeaderStories hs = new HeaderStories( doc ); - StringBuffer ret = new StringBuffer(); + StringBuilder ret = new StringBuilder(); if ( hs.getFirstHeader() != null ) { appendHeaderFooter( hs.getFirstHeader(), ret ); } @@ -208,7 +208,7 @@ public final class WordExtractor extends POIOLE2TextExtractor { public String getFooterText() { HeaderStories hs = new HeaderStories( doc ); - StringBuffer ret = new StringBuffer(); + StringBuilder ret = new StringBuilder(); if ( hs.getFirstFooter() != null ) { appendHeaderFooter( hs.getFirstFooter(), ret ); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/EscherRecordHolder.java b/src/scratchpad/src/org/apache/poi/hwpf/model/EscherRecordHolder.java index 8ab7781464..df62b420ad 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/EscherRecordHolder.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/EscherRecordHolder.java @@ -63,7 +63,7 @@ public final class EscherRecordHolder { } public String toString() { - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); if (escherRecords.size() == 0) { buffer.append("No Escher Records Decoded").append("\n"); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java index 19256607a2..76873574ed 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java @@ -87,25 +87,18 @@ public final class FSPATable return result.toArray(new FSPA[0]); } - public String toString() - { - StringBuffer buf = new StringBuffer(); - buf.append( "[FPSA PLC size=" ).append( _byStart.size() ) - .append( "]\n" ); + public String toString() { + StringBuilder buf = new StringBuilder(); + buf.append( "[FPSA PLC size=" ).append( _byStart.size() ).append( "]\n" ); - for ( Map.Entry entry : _byStart - .entrySet() ) - { + for ( Map.Entry entry : _byStart.entrySet() ) { Integer i = entry.getKey(); buf.append( " " ).append(i).append( " => \t" ); - try - { + try { FSPA fspa = getFspaFromCp( i.intValue() ); buf.append(fspa); - } - catch ( Exception exc ) - { + } catch ( Exception exc ) { buf.append( exc.getMessage() ); } buf.append( "\n" ); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/FLDAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/FLDAbstractType.java index 04adf1a429..3da59198d9 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/FLDAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/FLDAbstractType.java @@ -66,40 +66,22 @@ public abstract class FLDAbstractType data[0x1 + offset] = field_2_flt; } - public String toString() - { - StringBuffer buffer = new StringBuffer(); - - buffer.append( "[FLD]\n" ); - - buffer.append( " .chHolder = " ); - buffer.append( " (" ).append( getChHolder() ).append( " )\n" ); - buffer.append( " .ch = " ) - .append( getCh() ).append( '\n' ); - buffer.append( " .reserved = " ) - .append( getReserved() ).append( '\n' ); - - buffer.append( " .flt = " ); - buffer.append( " (" ).append( getFlt() ).append( " )\n" ); - buffer.append( " .fDiffer = " ) - .append( isFDiffer() ).append( '\n' ); - buffer.append( " .fZombieEmbed = " ) - .append( isFZombieEmbed() ).append( '\n' ); - buffer.append( " .fResultDirty = " ) - .append( isFResultDirty() ).append( '\n' ); - buffer.append( " .fResultEdited = " ) - .append( isFResultEdited() ).append( '\n' ); - buffer.append( " .fLocked = " ) - .append( isFLocked() ).append( '\n' ); - buffer.append( " .fPrivateResult = " ) - .append( isFPrivateResult() ).append( '\n' ); - buffer.append( " .fNested = " ) - .append( isFNested() ).append( '\n' ); - buffer.append( " .fHasSep = " ) - .append( isFHasSep() ).append( '\n' ); - - buffer.append( "[/FLD]\n" ); - return buffer.toString(); + public String toString() { + return + "[FLD]\n" + + " .chHolder = (" + getChHolder() + " )\n" + + " .ch = " + getCh() + "\n" + + " .reserved = " + getReserved() + "\n" + + " .flt = (" + getFlt() + " )\n" + + " .fDiffer = " + isFDiffer() + "\n" + + " .fZombieEmbed = " + isFZombieEmbed() + "\n" + + " .fResultDirty = " + isFResultDirty() + "\n" + + " .fResultEdited = " + isFResultEdited() + "\n" + + " .fLocked = " + isFLocked() + "\n" + + " .fPrivateResult = " + isFPrivateResult() + "\n" + + " .fNested = " + isFNested() + "\n" + + " .fHasSep = " + isFHasSep() + "\n" + + "[/FLD]\n"; } /** diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/TLPAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/TLPAbstractType.java index 0e6ad3a88f..08a2caceef 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/TLPAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/TLPAbstractType.java @@ -64,34 +64,19 @@ public abstract class TLPAbstractType data[0x2 + offset] = field_2_tlp_flags; } - public String toString() - { - StringBuffer buffer = new StringBuffer(); - - buffer.append( "[TLP]\n" ); - - buffer.append( " .itl = " ); - buffer.append( " (" ).append( getItl() ).append( " )\n" ); - - buffer.append( " .tlp_flags = " ); - buffer.append( " (" ).append( getTlp_flags() ).append( " )\n" ); - buffer.append( " .fBorders = " ) - .append( isFBorders() ).append( '\n' ); - buffer.append( " .fShading = " ) - .append( isFShading() ).append( '\n' ); - buffer.append( " .fFont = " ) - .append( isFFont() ).append( '\n' ); - buffer.append( " .fColor = " ) - .append( isFColor() ).append( '\n' ); - buffer.append( " .fBestFit = " ) - .append( isFBestFit() ).append( '\n' ); - buffer.append( " .fHdrRows = " ) - .append( isFHdrRows() ).append( '\n' ); - buffer.append( " .fLastRow = " ) - .append( isFLastRow() ).append( '\n' ); - - buffer.append( "[/TLP]\n" ); - return buffer.toString(); + public String toString() { + return + "[TLP]\n" + + " .itl = (" + getItl() + " )\n" + + " .tlp_flags = (" + getTlp_flags() + " )\n" + + " .fBorders = " + isFBorders() + "\n" + + " .fShading = " + isFShading() + "\n" + + " .fFont = " + isFFont() + "\n" + + " .fColor = " + isFColor() + "\n" + + " .fBestFit = " + isFBestFit() + "\n" + + " .fHdrRows = " + isFHdrRows() + "\n" + + " .fLastRow = " + isFLastRow() + "\n" + + "[/TLP]\n"; } /** diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java index 0f5a949957..595dd532a6 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java @@ -210,34 +210,15 @@ public final class BorderCode implements Cloneable { } @Override - public String toString() - { - if ( isEmpty() ) - return "[BRC] EMPTY"; - - StringBuffer buffer = new StringBuffer(); - - buffer.append( "[BRC]\n" ); - - buffer.append( " .dptLineWidth = " ); - buffer.append( " (" ).append( getLineWidth() ).append( " )\n" ); - - buffer.append( " .brcType = " ); - buffer.append( " (" ).append( getBorderType() ).append( " )\n" ); - - buffer.append( " .ico = " ); - buffer.append( " (" ).append( getColor() ).append( " )\n" ); - - buffer.append( " .dptSpace = " ); - buffer.append( " (" ).append( getSpace() ).append( " )\n" ); - - buffer.append( " .fShadow = " ); - buffer.append( " (" ).append( isShadow() ).append( " )\n" ); - - buffer.append( " .fFrame = " ); - buffer.append( " (" ).append( isFrame() ).append( " )\n" ); - - return buffer.toString(); + public String toString() { + return isEmpty() ? "[BRC] EMPTY" : + "[BRC]\n" + + " .dptLineWidth = (" + getLineWidth() + " )\n" + + " .brcType = (" + getBorderType() + " )\n" + + " .ico = (" + getColor() + " )\n" + + " .dptSpace = (" + getSpace() + " )\n" + + " .fShadow = (" + isShadow() + " )\n" + + " .fFrame = (" + isFrame() + " )\n"; } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java b/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java index 330e93df92..a6bcf3e607 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertArrayEquals; import java.io.ByteArrayInputStream; import junit.framework.TestCase; - import org.apache.poi.hssf.usermodel.HSSFRichTextString; import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.formula.ptg.RefPtg; @@ -109,7 +108,7 @@ public final class TestTextObjectRecord extends TestCase { public void testLongRecords() { int[] lengths = {1024, 2048, 4096, 8192, 16384}; //test against strings of different length for (int length : lengths) { - StringBuffer buff = new StringBuffer(length); + StringBuilder buff = new StringBuilder(length); for (int j = 0; j < length; j++) { buff.append("x"); } -- 2.39.5