aboutsummaryrefslogtreecommitdiffstats
path: root/poi-ooxml/src
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2023-09-14 15:49:10 +0000
committerPJ Fanning <fanningpj@apache.org>2023-09-14 15:49:10 +0000
commit4b520ff7c5859cf18ea7cc9a74524f381d4624c3 (patch)
tree24db8759d40a2935c35699cebabe87d9137aff5b /poi-ooxml/src
parent4afcb281cef11d7943e5c4ca4324098f7eac9b42 (diff)
downloadpoi-4b520ff7c5859cf18ea7cc9a74524f381d4624c3.tar.gz
poi-4b520ff7c5859cf18ea7cc9a74524f381d4624c3.zip
use more nio file support
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1912316 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml/src')
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java8
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java11
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/TempFilePackagePart.java5
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java3
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipArchiveFakeEntry.java3
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java7
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java4
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xssf/XSSFTestDataSamples.java8
8 files changed, 25 insertions, 24 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java
index 35f3c10c01..2c79feea4e 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java
@@ -25,13 +25,13 @@ import static org.apache.poi.openxml4j.opc.PackagingURIHelper.RELATIONSHIP_PART_
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
@@ -506,7 +506,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
}
String name = path.substring(path.lastIndexOf(File.separatorChar) + 1);
- try (FileInputStream is = new FileInputStream(path)) {
+ try (InputStream is = Files.newInputStream(Paths.get(path))) {
addThumbnail(name, is);
}
}
@@ -1483,7 +1483,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
}
// Do the save
- try (FileOutputStream fos = new FileOutputStream(targetFile)) {
+ try (OutputStream fos = Files.newOutputStream(targetFile.toPath())) {
this.save(fos);
}
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java
index cc714e9465..21894df270 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java
@@ -21,11 +21,10 @@ import static org.apache.poi.openxml4j.opc.ContentTypes.RELATIONSHIPS_PART;
import static org.apache.poi.openxml4j.opc.internal.ContentTypeManager.CONTENT_TYPES_PART_NAME;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.file.Files;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
@@ -179,12 +178,12 @@ public final class ZipPackage extends OPCPackage {
}
private static ZipEntrySource openZipEntrySourceStream(File file) throws InvalidOperationException {
- final FileInputStream fis;
+ final InputStream fis;
// Acquire a resource that is needed to read the next level of openZipEntrySourceStream
try {
// open the file input stream
- fis = new FileInputStream(file); // NOSONAR
- } catch (final FileNotFoundException e) {
+ fis = Files.newInputStream(file.toPath());
+ } catch (final IOException e) {
// If the source cannot be acquired, abort (no resources to free at this level)
throw new InvalidOperationException("Can't open the specified file input stream from file: '" + file + "'", e);
}
@@ -204,7 +203,7 @@ public final class ZipPackage extends OPCPackage {
}
}
- private static ZipEntrySource openZipEntrySourceStream(FileInputStream fis) throws InvalidOperationException {
+ private static ZipEntrySource openZipEntrySourceStream(InputStream fis) throws InvalidOperationException {
final ZipArchiveThresholdInputStream zis;
// Acquire a resource that is needed to read the next level of openZipEntrySourceStream
try {
diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/TempFilePackagePart.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/TempFilePackagePart.java
index d1a3e3fd80..600851722a 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/TempFilePackagePart.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/TempFilePackagePart.java
@@ -30,6 +30,7 @@ import org.apache.poi.util.IOUtils;
import org.apache.poi.util.TempFile;
import java.io.*;
+import java.nio.file.Files;
/**
* (Experimental) Temp File version of a package part.
@@ -89,12 +90,12 @@ public final class TempFilePackagePart extends PackagePart {
@Override
protected InputStream getInputStreamImpl() throws IOException {
- return new FileInputStream(tempFile);
+ return Files.newInputStream(tempFile.toPath());
}
@Override
protected OutputStream getOutputStreamImpl() throws IOException {
- return new FileOutputStream(tempFile);
+ return Files.newOutputStream(tempFile.toPath());
}
@Override
diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java
index 674850f6e1..26f3cffae1 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java
@@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
+import java.nio.file.Files;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
@@ -197,7 +198,7 @@ public final class ZipHelper {
}
// Peek at the first few bytes to sanity check
- try (FileInputStream input = new FileInputStream(file)) {
+ try (InputStream input = Files.newInputStream(file.toPath())) {
verifyZipHeader(input);
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipArchiveFakeEntry.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipArchiveFakeEntry.java
index 7a74f07472..edb8817bed 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipArchiveFakeEntry.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipArchiveFakeEntry.java
@@ -18,6 +18,7 @@
package org.apache.poi.openxml4j.util;
import java.io.*;
+import java.nio.file.Files;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
@@ -99,7 +100,7 @@ import org.apache.poi.util.TempFile;
}
} else if (tempFile != null) {
try {
- return new FileInputStream(tempFile);
+ return Files.newInputStream(tempFile.toPath());
} catch (FileNotFoundException e) {
throw new IOException("temp file " + tempFile.getAbsolutePath() + " is missing");
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java
index 45b9947981..d5cc96585d 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/EncryptedTempData.java
@@ -20,11 +20,10 @@
package org.apache.poi.poifs.crypt.temp;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.file.Files;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
@@ -73,7 +72,7 @@ public class EncryptedTempData {
*/
public OutputStream getOutputStream() throws IOException {
Cipher ciEnc = CryptoFunctions.getCipher(skeySpec, cipherAlgorithm, ChainingMode.cbc, ivBytes, Cipher.ENCRYPT_MODE, PADDING);
- outputStream = new CountingOutputStream(new CipherOutputStream(new FileOutputStream(tempFile), ciEnc));
+ outputStream = new CountingOutputStream(new CipherOutputStream(Files.newOutputStream(tempFile.toPath()), ciEnc));
return outputStream;
}
@@ -85,7 +84,7 @@ public class EncryptedTempData {
*/
public InputStream getInputStream() throws IOException {
Cipher ciDec = CryptoFunctions.getCipher(skeySpec, cipherAlgorithm, ChainingMode.cbc, ivBytes, Cipher.DECRYPT_MODE, PADDING);
- return new CipherInputStream(new FileInputStream(tempFile), ciDec);
+ return new CipherInputStream(Files.newInputStream(tempFile.toPath()), ciDec);
}
/**
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
index 40441588a4..38562f5a58 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
@@ -21,10 +21,10 @@ import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
import java.awt.Dimension;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -607,7 +607,7 @@ public class XMLSlideShow extends POIXMLDocument
@Override
public XSLFPictureData addPicture(File pict, PictureType format) throws IOException {
byte[] data = IOUtils.safelyAllocate(pict.length(), MAX_RECORD_LENGTH);
- try (InputStream is = new FileInputStream(pict)) {
+ try (InputStream is = Files.newInputStream(pict.toPath())) {
IOUtils.readFully(is, data);
}
return addPicture(data, format);
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/XSSFTestDataSamples.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/XSSFTestDataSamples.java
index 882ac23078..362b7039c8 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xssf/XSSFTestDataSamples.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/XSSFTestDataSamples.java
@@ -18,10 +18,10 @@
package org.apache.poi.xssf;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.hssf.HSSFTestDataSamples;
@@ -76,7 +76,7 @@ public class XSSFTestDataSamples {
}
private static <R extends Workbook> void writeOut(R wb, File file) throws IOException {
- try (FileOutputStream out = new FileOutputStream(file)) {
+ try (OutputStream out = Files.newOutputStream(file.toPath())) {
wb.write(out);
}
}
@@ -197,7 +197,7 @@ public class XSSFTestDataSamples {
* @throws IOException If reading the file fails
*/
public static XSSFWorkbook readBack(File file) throws IOException {
- try (InputStream in = new FileInputStream(file)) {
+ try (InputStream in = Files.newInputStream(file.toPath())) {
return new XSSFWorkbook(in);
}
}