avoid creating unnecessary temp files, tighten up usage of temp files in unit tests
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@899364 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a9e8084bb7
commit
4be190d69d
@ -266,7 +266,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
*/
|
*/
|
||||||
protected static OPCPackage newPackage() {
|
protected static OPCPackage newPackage() {
|
||||||
try {
|
try {
|
||||||
OPCPackage pkg = OPCPackage.create(PackageHelper.createTempFile());
|
OPCPackage pkg = OPCPackage.create(new ByteArrayOutputStream());
|
||||||
// Main part
|
// Main part
|
||||||
PackagePartName corePartName = PackagingURIHelper.createPartName(XSSFRelation.WORKBOOK.getDefaultFileName());
|
PackagePartName corePartName = PackagingURIHelper.createPartName(XSSFRelation.WORKBOOK.getDefaultFileName());
|
||||||
// Create main part relationship
|
// Create main part relationship
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xwpf.usermodel;
|
package org.apache.poi.xwpf.usermodel;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@ -195,7 +196,7 @@ public class XWPFDocument extends POIXMLDocument {
|
|||||||
*/
|
*/
|
||||||
protected static OPCPackage newPackage() {
|
protected static OPCPackage newPackage() {
|
||||||
try {
|
try {
|
||||||
OPCPackage pkg = OPCPackage.create(PackageHelper.createTempFile());
|
OPCPackage pkg = OPCPackage.create(new ByteArrayOutputStream());
|
||||||
// Main part
|
// Main part
|
||||||
PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
|
PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
|
||||||
// Create main part relationship
|
// Create main part relationship
|
||||||
|
@ -23,6 +23,7 @@ import java.io.FileOutputStream;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.poi.util.TempFile;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
|
||||||
public class TestWorkbookProtection extends TestCase {
|
public class TestWorkbookProtection extends TestCase {
|
||||||
@ -95,7 +96,7 @@ public class TestWorkbookProtection extends TestCase {
|
|||||||
|
|
||||||
wb.lockRevision();
|
wb.lockRevision();
|
||||||
|
|
||||||
File tempFile = File.createTempFile("workbookProtection", ".xlsx");
|
File tempFile = TempFile.createTempFile("workbookProtection", ".xlsx");
|
||||||
FileOutputStream out = new FileOutputStream(tempFile);
|
FileOutputStream out = new FileOutputStream(tempFile);
|
||||||
wb.write(out);
|
wb.write(out);
|
||||||
out.close();
|
out.close();
|
||||||
|
@ -25,6 +25,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.poi.util.TempFile;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
||||||
@ -126,7 +127,7 @@ public class TestDocumentProtection extends TestCase {
|
|||||||
r1.setText("Lorem ipsum dolor sit amet.");
|
r1.setText("Lorem ipsum dolor sit amet.");
|
||||||
doc.enforceCommentsProtection();
|
doc.enforceCommentsProtection();
|
||||||
|
|
||||||
File tempFile = File.createTempFile("documentProtectionFile", ".docx");
|
File tempFile = TempFile.createTempFile("documentProtectionFile", ".docx");
|
||||||
FileOutputStream out = new FileOutputStream(tempFile);
|
FileOutputStream out = new FileOutputStream(tempFile);
|
||||||
|
|
||||||
doc.write(out);
|
doc.write(out);
|
||||||
|
@ -54,6 +54,7 @@ import org.apache.poi.poifs.filesystem.DocumentEntry;
|
|||||||
import org.apache.poi.poifs.filesystem.DocumentInputStream;
|
import org.apache.poi.poifs.filesystem.DocumentInputStream;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
|
import org.apache.poi.util.TempFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Tests HPSF's high-level writing functionality for the well-known property
|
* <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>
|
/* Write the POI filesystem to a (temporary) file <em>doc2</em>
|
||||||
* and close the latter. */
|
* and close the latter. */
|
||||||
final File doc2 = File.createTempFile("POI_HPSF_Test.", ".tmp");
|
final File doc2 = TempFile.createTempFile("POI_HPSF_Test.", ".tmp");
|
||||||
doc2.deleteOnExit();
|
doc2.deleteOnExit();
|
||||||
OutputStream out = new FileOutputStream(doc2);
|
OutputStream out = new FileOutputStream(doc2);
|
||||||
poifs.writeFilesystem(out);
|
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>
|
* <li><p>Write the POI filesystem to a (temporary) file <em>doc3</em>
|
||||||
* and close the latter. */
|
* and close the latter. */
|
||||||
final File doc3 = File.createTempFile("POI_HPSF_Test.", ".tmp");
|
final File doc3 = TempFile.createTempFile("POI_HPSF_Test.", ".tmp");
|
||||||
doc3.deleteOnExit();
|
doc3.deleteOnExit();
|
||||||
out = new FileOutputStream(doc3);
|
out = new FileOutputStream(doc3);
|
||||||
poifs.writeFilesystem(out);
|
poifs.writeFilesystem(out);
|
||||||
|
Loading…
Reference in New Issue
Block a user