]> source.dussan.org Git - poi.git/commitdiff
avoid creating unnecessary temp files, tighten up usage of temp files in unit tests
authorYegor Kozlov <yegor@apache.org>
Thu, 14 Jan 2010 19:23:13 +0000 (19:23 +0000)
committerYegor Kozlov <yegor@apache.org>
Thu, 14 Jan 2010 19:23:13 +0000 (19:23 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@899364 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
src/ooxml/testcases/org/apache/poi/xssf/TestWorkbookProtection.java
src/ooxml/testcases/org/apache/poi/xwpf/TestDocumentProtection.java
src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java

index e05e57ec116a2b6876748e1ec2e30cb9c8f0c62b..20aeadb50ffc38adffffe95b538fcee540155ba9 100644 (file)
@@ -266,7 +266,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
      */
     protected static OPCPackage newPackage() {
         try {
-            OPCPackage pkg = OPCPackage.create(PackageHelper.createTempFile());
+            OPCPackage pkg = OPCPackage.create(new ByteArrayOutputStream());
             // Main part
             PackagePartName corePartName = PackagingURIHelper.createPartName(XSSFRelation.WORKBOOK.getDefaultFileName());
             // Create main part relationship
index 20004bd368988d8de02123efb63d52e06fa60d3f..2959317bfbbf1c237ff4c78afdd37254b46ffe15 100644 (file)
@@ -16,6 +16,7 @@
 ==================================================================== */
 package org.apache.poi.xwpf.usermodel;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -195,7 +196,7 @@ public class XWPFDocument extends POIXMLDocument {
      */
     protected static OPCPackage newPackage() {
         try {
-            OPCPackage pkg = OPCPackage.create(PackageHelper.createTempFile());
+            OPCPackage pkg = OPCPackage.create(new ByteArrayOutputStream());
             // Main part
             PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
             // Create main part relationship
index fc8c159e53ee72e453a87473106fddbac7df965b..642fe30748ec2653d06d01930d30f5e61837fbf3 100644 (file)
@@ -23,6 +23,7 @@ import java.io.FileOutputStream;
 
 import junit.framework.TestCase;
 
+import org.apache.poi.util.TempFile;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 public class TestWorkbookProtection extends TestCase {
@@ -95,7 +96,7 @@ public class TestWorkbookProtection extends TestCase {
 
                wb.lockRevision();
 
-               File tempFile = File.createTempFile("workbookProtection", ".xlsx");
+               File tempFile = TempFile.createTempFile("workbookProtection", ".xlsx");
                FileOutputStream out = new FileOutputStream(tempFile);
                wb.write(out);
                out.close();
index 1d96f6d589145535655c639de76a2c46f3a4e82c..4a06622912333a42ebf13cd8e145aa9aa644a62e 100644 (file)
@@ -25,6 +25,7 @@ import java.io.IOException;
 
 import junit.framework.TestCase;
 
+import org.apache.poi.util.TempFile;
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.apache.poi.xwpf.usermodel.XWPFParagraph;
 import org.apache.poi.xwpf.usermodel.XWPFRun;
@@ -126,7 +127,7 @@ public class TestDocumentProtection extends TestCase {
         r1.setText("Lorem ipsum dolor sit amet.");
         doc.enforceCommentsProtection();
 
-        File tempFile = File.createTempFile("documentProtectionFile", ".docx");
+        File tempFile = TempFile.createTempFile("documentProtectionFile", ".docx");
         FileOutputStream out = new FileOutputStream(tempFile);
 
         doc.write(out);
index 8c95fdb7bfbe8f40dd8dca11ec43174d0cb1cad6..049f98d56716122209db6b52095b1b0822ca2aa5 100644 (file)
@@ -54,6 +54,7 @@ import org.apache.poi.poifs.filesystem.DocumentEntry;
 import org.apache.poi.poifs.filesystem.DocumentInputStream;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.POIDataSamples;
+import org.apache.poi.util.TempFile;
 
 /**
  * <p>Tests HPSF's high-level writing functionality for the well-known property
@@ -374,7 +375,7 @@ public class TestWriteWellKnown extends TestCase {
 
         /* Write the POI filesystem to a (temporary) file <em>doc2</em>
          * and close the latter. */
-        final File doc2 = File.createTempFile("POI_HPSF_Test.", ".tmp");
+        final File doc2 = TempFile.createTempFile("POI_HPSF_Test.", ".tmp");
         doc2.deleteOnExit();
         OutputStream out = new FileOutputStream(doc2);
         poifs.writeFilesystem(out);
@@ -503,7 +504,7 @@ public class TestWriteWellKnown extends TestCase {
         /*
          * <li><p>Write the POI filesystem to a (temporary) file <em>doc3</em>
          * and close the latter. */
-        final File doc3 = File.createTempFile("POI_HPSF_Test.", ".tmp");
+        final File doc3 = TempFile.createTempFile("POI_HPSF_Test.", ".tmp");
         doc3.deleteOnExit();
         out = new FileOutputStream(doc3);
         poifs.writeFilesystem(out);