poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1744004 - in /poi/trunk/src: integrationtest/org/apache/poi/stress/XSSFFileHandler.java ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
Date Mon, 16 May 2016 10:01:37 GMT
Author: kiwiwings
Date: Mon May 16 10:01:36 2016
New Revision: 1744004

URL: http://svn.apache.org/viewvc?rev=1744004&view=rev
Log:
Reduce calls to utf-related methods - the integration test took ages because of poc-shared-strings.xlsx

Modified:
    poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java

Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java?rev=1744004&r1=1744003&r2=1744004&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java Mon May 16 10:01:36
2016
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertNot
 import java.io.*;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Locale;
 import java.util.Set;
 
 import javax.xml.parsers.ParserConfigurationException;
@@ -135,16 +136,13 @@ public class XSSFFileHandler extends Spr
         EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/sample-beta.xlsx");
     }
 
+    @SuppressWarnings("resource")
     @Override
     public void handleAdditional(File file) throws Exception {
         // redirect stdout as the examples often write lots of text
         PrintStream oldOut = System.out;
         try {
-            System.setOut(new PrintStream(new OutputStream() {
-                @Override
-                public void write(int b) throws IOException {
-                }
-            }));
+            System.setOut(new NullPrintStream());
             FromHowTo.main(new String[]{file.getAbsolutePath()});
             XLSX2CSV.main(new String[]{file.getAbsolutePath()});
 
@@ -195,4 +193,45 @@ public class XSSFFileHandler extends Spr
     public void testAdditional() throws Exception {
         handleAdditional(new File("test-data/spreadsheet/poc-xmlbomb.xlsx"));
     }
+    
+    // need to override all methods to omit calls to UTF-handling methods 
+    static class NullPrintStream extends PrintStream {
+        @SuppressWarnings("resource")
+        NullPrintStream() {
+            super(new OutputStream() {
+                public void write(int b) {}
+                public void write(byte[] b) {}
+                public void write(byte[] b, int off, int len) {}
+            });
+        }
+        public void write(int b) {}
+        public void write(byte[] buf, int off, int len) {}
+        public void print(boolean b) {}
+        public void print(char c) {}
+        public void print(int i) {}
+        public void print(long l) {}
+        public void print(float f) {}
+        public void print(double d) {}
+        public void print(char[] s) {}
+        public void print(String s) {}
+        public void print(Object obj) {}
+        public void println() {}
+        public void println(boolean x) {}
+        public void println(char x) {}
+        public void println(int x) {}
+        public void println(long x) {}
+        public void println(float x) {}
+        public void println(double x) {}
+        public void println(char[] x) {}
+        public void println(String x) {}
+        public void println(Object x) {}
+        public PrintStream printf(String format, Object... args) { return this; }
+        public PrintStream printf(Locale l, String format, Object... args) { return this;
}
+        public PrintStream format(String format, Object... args) { return this; }
+        public PrintStream format(Locale l, String format, Object... args) { return this;
}
+        public PrintStream append(CharSequence csq) { return this; }
+        public PrintStream append(CharSequence csq, int start, int end) { return this; }
+        public PrintStream append(char c) { return this; }
+        public void write(byte[] b) {}
+    }
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java?rev=1744004&r1=1744003&r2=1744004&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java Mon May
16 10:01:36 2016
@@ -73,9 +73,6 @@ import org.openxmlformats.schemas.spread
  *     cell2.setCellValue(s2);
  * </pre>
  * </blockquote>
- *
- *
- * @author Yegor Kozlov
  */
 public class XSSFRichTextString implements RichTextString {
     private static final Pattern utfPtrn = Pattern.compile("_x([0-9A-F]{4})_");
@@ -497,7 +494,9 @@ public class XSSFRichTextString implemen
      * @return  the decoded string
      */
     static String utfDecode(String value){
-        if(value == null) return null;
+        if(value == null || !value.contains("_x")) {
+            return value;
+        }
         
         StringBuilder buf = new StringBuilder();
         Matcher m = utfPtrn.matcher(value);



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


Mime
View raw message