]> source.dussan.org Git - poi.git/commitdiff
Replace StringBuffer with StringBuilder
authorAndreas Beeker <kiwiwings@apache.org>
Fri, 29 Nov 2019 23:57:35 +0000 (23:57 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Fri, 29 Nov 2019 23:57:35 +0000 (23:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1870600 13f79535-47bb-0310-9956-ffa450edef68

33 files changed:
src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
src/java/org/apache/poi/hssf/record/PageBreakRecord.java
src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java
src/java/org/apache/poi/poifs/dev/POIFSViewEngine.java
src/java/org/apache/poi/poifs/dev/POIFSViewer.java
src/java/org/apache/poi/poifs/filesystem/DocumentDescriptor.java
src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java
src/java/org/apache/poi/ss/formula/SheetIdentifier.java
src/java/org/apache/poi/ss/formula/SheetRangeIdentifier.java
src/java/org/apache/poi/ss/formula/functions/Countif.java
src/java/org/apache/poi/util/GenericRecordJsonWriter.java
src/java/org/apache/poi/util/GenericRecordXmlWriter.java
src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFProperty.java
src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java
src/scratchpad/src/org/apache/poi/hslf/extractor/QuickButCruddyTextExtractor.java
src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java
src/scratchpad/src/org/apache/poi/hslf/record/ExMediaAtom.java
src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjAtom.java
src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersAtom.java
src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java
src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java
src/scratchpad/src/org/apache/poi/hsmf/datatypes/ByteChunk.java
src/scratchpad/src/org/apache/poi/hsmf/datatypes/MAPIProperty.java
src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtactor.java
src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java
src/scratchpad/src/org/apache/poi/hwpf/extractor/Word6Extractor.java
src/scratchpad/src/org/apache/poi/hwpf/extractor/WordExtractor.java
src/scratchpad/src/org/apache/poi/hwpf/model/EscherRecordHolder.java
src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java
src/scratchpad/src/org/apache/poi/hwpf/model/types/FLDAbstractType.java
src/scratchpad/src/org/apache/poi/hwpf/model/types/TLPAbstractType.java
src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java
src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java

index e056e495136abd6c4765c7eec65426e2ed7d8930..93562093164585238142964ad6ae8ca756efcb39 100644 (file)
@@ -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');
index 9e053918bd90960529aa517939a1be403a153a5b..a1d86247dccc7f825075989eb4b49d14eb5014a1 100644 (file)
@@ -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;
index 7aeabe92c4a5f87eb24bc673980f6693eb82a42e..b74bf1b570fc93910996cf20ad8d031defbb3a13 100644 (file)
@@ -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)
index dc4dd547ccebab4fddef085671c2607a93e41d72..8db1bf312977f3d6b5cf09d4dc4430983e181de4 100644 (file)
@@ -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++)
         {
index 18095397f68d6880bae90d5c75ab0b04e3354b20..0be693444fe0f375f52bcc10a29cb3714a7a5ad5 100644 (file)
@@ -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++) {
index 30382242144dcf564d2ba130576071937548bb99..0c1b2c817781db436ec74f137552500d4889db02 100644 (file)
@@ -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++)
         {
index 80db4b3c487cb24c259d1dce09e99d3874dead51..d32214e024ff253fda55655856984b0afe5475c1 100644 (file)
@@ -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);
index 71c7cd0f0c88b4d5b51e268f7ed1cbce70d59cda..51c0852b3053f7900efbea34fe64d9f3d79be605 100644 (file)
@@ -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
index c0b851ed57d7a58434f8bcc25e77dc86bf86ad94..8cb5b3201a0259ab14e7ec27857d908d766ea35e 100644 (file)
@@ -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()) {
index 4ae0874eb00fd93cc0aae47d2ae5ff9c19a83285..1f37d2e433a9eda3d6fc36c110dccdd8fe81bdc7 100644 (file)
@@ -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<len; i++) {
                 char ch = value.charAt(i);
index f8a0c85a4e98275dbc3425144b031c656e95c646..1be40701ad430ca69b4e33286bedcddda7cf45da 100644 (file)
@@ -404,42 +404,42 @@ public class GenericRecordJsonWriter implements Closeable {
         printName(name);
         fw.write('"');
 
-        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.append(str, pos, m.start());
             String match = m.group();
             switch (match) {
                 case "\n":
-                    repl = "\\\\n";
+                    fw.write("\\\\n");
                     break;
                 case "\r":
-                    repl = "\\\\r";
+                    fw.write("\\\\r");
                     break;
                 case "\t":
-                    repl = "\\\\t";
+                    fw.write("\\\\t");
                     break;
                 case "\b":
-                    repl = "\\\\b";
+                    fw.write("\\\\b");
                     break;
                 case "\f":
-                    repl = "\\\\f";
+                    fw.write("\\\\f");
                     break;
                 case "\\":
-                    repl = "\\\\\\\\";
+                    fw.write("\\\\\\\\");
                     break;
                 case "\"":
-                    repl = "\\\\\"";
+                    fw.write("\\\\\"");
                     break;
                 default:
-                    repl = "\\\\u" + trimHex(match.charAt(0), 4);
+                    fw.write("\\\\u");
+                    fw.write(trimHex(match.charAt(0), 4));
                     break;
             }
-            m.appendReplacement(sb, repl);
+            pos = m.end();
         }
-        m.appendTail(sb);
-        fw.write(sb.toString());
-
+        fw.append(str, pos, str.length());
         fw.write('"');
         return true;
     }
index c5c7877f04052623d1702acb1c25e70ba64845ab..c5a949cc6383eef89319a2174ac2eb7909300e1c 100644 (file)
@@ -462,35 +462,37 @@ public class GenericRecordXmlWriter implements Closeable {
 
     protected boolean printObject(String name, Object o) {
         openName(name+">");
-        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 = "&lt;";
+                    fw.write("&lt;");
                     break;
                 case ">":
-                    repl = "&gt;";
+                    fw.write("&gt;");
                     break;
                 case "&":
-                    repl = "&amp;";
+                    fw.write("&amp;");
                     break;
                 case "\'":
-                    repl = "&apos;";
+                    fw.write("&apos;");
                     break;
                 case "\"":
-                    repl = "&quot;";
+                    fw.write("&quot;");
                     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;
     }
index 9fafcf0dce23ce0f91e7a817b1cc39503a2bae63..e90c91047057ba48c82fb10488b41f3451b4a8cd 100644 (file)
@@ -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 + ")");
    }
 }
index 0a96a54843fc3c520695852ce41235a2b3540641..c31ee059beedd694dff3417569cfe2dcf668ddba 100644 (file)
@@ -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<len; i++) {
                        int j = i + offset;
                        int b = data[j];
index d53f0db56c7185c61d371dd8df364a53259a9216..9005e65fbd119238522d0fdccccc0b1ba1b2a8d1 100644 (file)
@@ -121,7 +121,7 @@ public final class QuickButCruddyTextExtractor {
         * Fetches the ALL the text of the powerpoint file, as a single string
         */
        public String getTextAsString() {
-               StringBuffer ret = new StringBuffer();
+               StringBuilder ret = new StringBuilder();
                List<String> textV = getTextAsVector();
                for(String text : textV) {
                        ret.append(text);
index b7636d2da0b9877770588f05ee88f02fdf05f48b..2f1306a3f8432680dd78f9800043ed1c19f3d36c 100644 (file)
@@ -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
index 97e2594ad10d024a08d01dfb537256b78b05aa78..b8db11ad7820a11ea9ba4d6735c0413b031744a8 100644 (file)
@@ -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
index 0b0b66ebab79864a929ffa89316589b75b2e0e80..b8c77a747ca64dd5609dea2535482eeb2a8732c8 100644 (file)
@@ -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
index ee6e645ee1587b6c5afdfc538bc72e49e6ad3544..f175848ff1d42d86e74a6a2d0176286d69ff61b0 100644 (file)
@@ -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
index e5f8d4f4dcd0f95c6857360798a18c6fa9134c7a..cd84b7b8daf96ab8cd7c87c73e6ba1f404610159 100644 (file)
@@ -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
index 0e8b95b3ab58a75b8e0399ba8d25301afaa1dead..078f1d9ef72e9628c8b7c07ada729b17bf6a5807 100644 (file)
@@ -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
index 57f56ab29dbb6fd6d1642fabcd2456f87d115cc8..ab5ca3a84e3f91d33b374d2d8a2a5d2be5de1b3a 100644 (file)
@@ -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(" [");
 
index ba54f70101821135467d98cdced47837147eb916..28c3b8c00c5801cf51bdc188363b3468451c841a 100644 (file)
@@ -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) {
index 0d820b8dc2aa77e3505ee130e91c2a16026b4253..f205dbffa2148cfab40dfcf48d592f4e4baab434 100644 (file)
@@ -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 <nick@example.com>; Jim <jim@example.com>"
     */
-   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;
       }
index 6c1739728969d2990a37fee00cb6532180d059c7..0e3c8695ab9cc20003ecfea959ee8a727e10cad2 100644 (file)
@@ -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 )
index 6a770bf15cf25cfff7d211e3c6b8b2ab9c39be05..1d509dd1c6304f6466883cad6090daa2467ebbc3 100644 (file)
@@ -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() )
             {
index eadc454d8b3215f041141ed06bb1116ce742699c..62c106ef3e7777fd00f17765c052e2f9f6c507bb 100644 (file)
@@ -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 );
         }
index 8ab7781464cbc32f4bf0e51caabdb4661fb8ff04..df62b420ad8c7d89e1968dfb3a4e681ca85b5fac 100644 (file)
@@ -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");
index 19256607a20eb391a362da0d680ebad05cc2a901..76873574ed570469f579b894d158227a0bf0da0b 100644 (file)
@@ -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<Integer, GenericPropertyNode> entry : _byStart
-                .entrySet() )
-        {
+        for ( Map.Entry<Integer, GenericPropertyNode> 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" );
index 04adf1a429aa6aad8b0d3d7ee90f51ddd2fbf37d..3da59198d948681f833065437f499ba53e10d679 100644 (file)
@@ -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";
     }
 
     /**
index 0e6ad3a88ffc225ae48058b7743accf6cc2532af..08a2caceefb572f3060987c89ff05015bc45eb5b 100644 (file)
@@ -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";
     }
 
     /**
index 0f5a949957f880605519bab4d4ed4e57624f17d0..595dd532a61e74a78f3d7a480f147525f3e1edfd 100644 (file)
@@ -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";
     }
 
 }
index 330e93df9220f8f34b72df2e7b8f2b5e3ac1cd0c..a6bcf3e607389855a8045750c6cb20f70ba75351 100644 (file)
@@ -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");
             }