From d35aba8b169a0185773aede3139d0e7fa9448285 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Mon, 16 May 2016 10:01:36 +0000 Subject: [PATCH] Reduce calls to utf-related methods - the integration test took ages because of poc-shared-strings.xlsx git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1744004 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/stress/XSSFFileHandler.java | 49 +++++++++++++++++-- .../xssf/usermodel/XSSFRichTextString.java | 7 ++- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java b/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java index 65e539635c..97d2f5f6f5 100644 --- a/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java +++ b/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java @@ -22,6 +22,7 @@ import static org.junit.Assert.assertNotNull; 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 SpreadsheetHandler { 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 SpreadsheetHandler { 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) {} + } } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java index 30dcbb8bf1..19176392d1 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java @@ -73,9 +73,6 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXstring; * cell2.setCellValue(s2); * * - * - * - * @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 implements RichTextString { * @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); -- 2.39.5