poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ser...@apache.org
Subject svn commit: r1155208 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hwpf/ src/org/apache/poi/hwpf/dev/ src/org/apache/poi/hwpf/extractor/ src/org/apache/poi/hwpf/model/ testcases/org/apache/poi/hwpf/model/
Date Tue, 09 Aug 2011 05:00:09 GMT
Author: sergey
Date: Tue Aug  9 05:00:09 2011
New Revision: 1155208

URL: http://svn.apache.org/viewvc?rev=1155208&view=rev
Log:
replace StringBuffer with StringBuilder in TextPiece

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/extractor/Word6Extractor.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java?rev=1155208&r1=1155207&r2=1155208&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java Tue Aug  9 05:00:09
2011
@@ -74,7 +74,7 @@ public class HWPFOldDocument extends HWP
             tpt = cft.getTextPieceTable();
             
             for(TextPiece tp : tpt.getTextPieces()) {
-                text.append( tp.getStringBuffer() );
+                text.append( tp.getStringBuilder() );
             }
         } else {
             // TODO Discover if these older documents can ever hold Unicode Strings?
@@ -94,7 +94,7 @@ public class HWPFOldDocument extends HWP
             );
             tpt.add(tp);
             
-            text.append(tp.getStringBuffer());
+            text.append(tp.getStringBuilder());
         }
         
         _text = tpt.getText();

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java?rev=1155208&r1=1155207&r2=1155208&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java Tue Aug  9 05:00:09
2011
@@ -562,7 +562,7 @@ public final class HWPFLister
 
             if ( withText )
             {
-                System.out.println( "\t" + textPiece.getStringBuffer() );
+                System.out.println( "\t" + textPiece.getStringBuilder() );
             }
         }
     }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/extractor/Word6Extractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/extractor/Word6Extractor.java?rev=1155208&r1=1155207&r2=1155208&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/extractor/Word6Extractor.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/extractor/Word6Extractor.java Tue Aug
 9 05:00:09 2011
@@ -84,7 +84,7 @@ public final class Word6Extractor extend
             // Fall back to ripping out the text pieces
 	        ret = new String[doc.getTextTable().getTextPieces().size()];
 	        for(int i=0; i<ret.length; i++) {
-	            ret[i] = doc.getTextTable().getTextPieces().get(i).getStringBuffer().toString();
+	            ret[i] = doc.getTextTable().getTextPieces().get(i).getStringBuilder().toString();
 	            
 	            // Fix the line endings
 	            ret[i].replaceAll("\r", "\ufffe");

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java?rev=1155208&r1=1155207&r2=1155208&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java Tue Aug  9 05:00:09
2011
@@ -68,7 +68,7 @@ public final class TextPiece extends Pro
 	  _pd = pd;
 
 	  // Validate
-	  int textLength = ((StringBuffer)_buf).length();
+	  int textLength = ((CharSequence)_buf).length();
 	  if(end-start != textLength) {
 		  throw new IllegalStateException("Told we're for characters " + start + " -> " + end
+ ", but actually covers " + textLength + " characters!");
 	  }
@@ -78,9 +78,9 @@ public final class TextPiece extends Pro
   }
 
   /**
-   * Create the StringBuffer from the text and unicode flag
+   * Create the StringBuilder from the text and unicode flag
    */
-  private static StringBuffer buildInitSB(byte[] text, PieceDescriptor pd) {
+  private static StringBuilder buildInitSB(byte[] text, PieceDescriptor pd) {
 	  String str;
 	  try {
 		  if(pd.isUnicode()) {
@@ -91,7 +91,7 @@ public final class TextPiece extends Pro
 	  } catch(UnsupportedEncodingException e) {
 		  throw new RuntimeException("Your Java is broken! It doesn't know about basic, required
character encodings!");
 	  }
-	  return new StringBuffer(str);
+	  return new StringBuilder(str);
   }
 
   /**
@@ -107,15 +107,21 @@ public final class TextPiece extends Pro
      return _pd;
    }
 
+   @Deprecated
    public StringBuffer getStringBuffer()
    {
-     return (StringBuffer)_buf;
+     return new StringBuffer(getStringBuilder());
+   }
+
+   public StringBuilder getStringBuilder()
+   {
+     return (StringBuilder)_buf;
    }
 
    public byte[] getRawBytes()
    {
      try {
-       return ((StringBuffer)_buf).toString().getBytes(_usesUnicode ?
+       return ((CharSequence)_buf).toString().getBytes(_usesUnicode ?
            "UTF-16LE" : "Cp1252");
      } catch (UnsupportedEncodingException ignore) {
 		  throw new RuntimeException("Your Java is broken! It doesn't know about basic, required
character encodings!");
@@ -130,7 +136,7 @@ public final class TextPiece extends Pro
     */
    public String substring(int start, int end)
    {
-	   StringBuffer buf = (StringBuffer)_buf;
+       StringBuilder buf = (StringBuilder)_buf;
 
 	   // Validate
 	   if(start < 0) {
@@ -167,7 +173,7 @@ public final class TextPiece extends Pro
 
 		   int bufStart = overlapStart - myStart;
 		   int bufEnd = overlapEnd - myStart;
-		   ((StringBuffer)_buf).delete(bufStart, bufEnd);
+		   ((StringBuilder)_buf).delete(bufStart, bufEnd);
 	   }
 
 	   // We need to invoke this even if text from this piece is not being
@@ -197,7 +203,7 @@ public final class TextPiece extends Pro
      if (limitsAreEqual(o))
      {
        TextPiece tp = (TextPiece)o;
-       return getStringBuffer().toString().equals(tp.getStringBuffer().toString()) &&
+       return getStringBuilder().toString().equals(tp.getStringBuilder().toString()) &&
               tp._usesUnicode == _usesUnicode && _pd.equals(tp._pd);
      }
      return false;

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java?rev=1155208&r1=1155207&r2=1155208&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java Tue Aug  9
05:00:09 2011
@@ -264,7 +264,7 @@ public class TextPieceTable implements C
         StringBuilder docText = new StringBuilder();
         for ( TextPiece textPiece : _textPieces )
         {
-            String toAppend = textPiece.getStringBuffer().toString();
+            String toAppend = textPiece.getStringBuilder().toString();
             int toAppendLength = toAppend.length();
 
             if ( toAppendLength != textPiece.getEnd() - textPiece.getStart() )

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java?rev=1155208&r1=1155207&r2=1155208&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java Tue
Aug  9 05:00:09 2011
@@ -70,13 +70,13 @@ public final class TestTextPieceTable ex
 
 		// All ascii, so stored in one big lump
 		assertEquals(1, tbl.getTextPieces().size());
-		TextPiece tp = (TextPiece)tbl.getTextPieces().get(0);
+		TextPiece tp = tbl.getTextPieces().get(0);
 
 		assertEquals(0, tp.getStart());
 		assertEquals(339, tp.getEnd());
 		assertEquals(339, tp.characterLength());
 		assertEquals(339, tp.bytesLength());
-		assertTrue(tp.getStringBuffer().toString().startsWith("This is a sample word document"));
+		assertTrue(tp.getStringBuilder().toString().startsWith("This is a sample word document"));
 
 
 		// Save and re-load
@@ -84,13 +84,13 @@ public final class TestTextPieceTable ex
 		tbl = docB.getTextTable();
 
 		assertEquals(1, tbl.getTextPieces().size());
-		tp = (TextPiece)tbl.getTextPieces().get(0);
+		tp = tbl.getTextPieces().get(0);
 
 		assertEquals(0, tp.getStart());
 		assertEquals(339, tp.getEnd());
 		assertEquals(339, tp.characterLength());
 		assertEquals(339, tp.bytesLength());
-		assertTrue(tp.getStringBuffer().toString().startsWith("This is a sample word document"));
+		assertTrue(tp.getStringBuilder().toString().startsWith("This is a sample word document"));
 	}
 
 	/**



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message