aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--poi-examples/src/main/java/org/apache/poi/examples/ss/ConditionalFormats.java6
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/ooxml/dev/OOXMLPrettyPrint.java4
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java7
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xdgf/util/HierarchyPrinter.java9
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xdgf/util/VsdxToPng.java10
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xslf/util/DummyFormat.java5
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xslf/util/PPTX2PNG.java5
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xslf/util/SVGFormat.java4
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java4
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hmef/dev/HMEFDumper.java5
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hmef/extractor/HMEFContentsExtractor.java12
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hpbf/dev/PLCDumper.java5
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java6
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hslf/extractor/ImageExtractor.java7
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java4
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hssf/converter/AbstractExcelUtils.java5
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hwpf/converter/AbstractWordUtils.java4
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java4
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java1
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/crypt/agile/AgileEncryptor.java4
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java8
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/dev/POIFSLister.java6
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroExtractor.java7
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java4
-rw-r--r--poi/src/main/java/org/apache/poi/util/FontMetricsDumper.java5
-rw-r--r--poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java5
-rw-r--r--poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java5
-rw-r--r--poi/src/main/java/org/apache/poi/util/IOUtils.java4
-rw-r--r--poi/src/test/java/org/apache/poi/ss/formula/function/ExcelCetabFunctionExtractor.java5
-rw-r--r--poi/src/test/java/org/apache/poi/ss/util/NumberComparingSpreadsheetGenerator.java5
30 files changed, 94 insertions, 71 deletions
diff --git a/poi-examples/src/main/java/org/apache/poi/examples/ss/ConditionalFormats.java b/poi-examples/src/main/java/org/apache/poi/examples/ss/ConditionalFormats.java
index db65f76787..a0a8177e87 100644
--- a/poi-examples/src/main/java/org/apache/poi/examples/ss/ConditionalFormats.java
+++ b/poi-examples/src/main/java/org/apache/poi/examples/ss/ConditionalFormats.java
@@ -19,8 +19,10 @@
package org.apache.poi.examples.ss;
-import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -93,7 +95,7 @@ public final class ConditionalFormats {
if (wb instanceof XSSFWorkbook) {
file += "x";
}
- try (FileOutputStream out = new FileOutputStream(file)) {
+ try (OutputStream out = Files.newOutputStream(Paths.get(file))) {
wb.write(out);
}
System.out.println("Generated: " + file);
diff --git a/poi-ooxml/src/main/java/org/apache/poi/ooxml/dev/OOXMLPrettyPrint.java b/poi-ooxml/src/main/java/org/apache/poi/ooxml/dev/OOXMLPrettyPrint.java
index 7a5fb93bb3..00ded3fb2a 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/ooxml/dev/OOXMLPrettyPrint.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/ooxml/dev/OOXMLPrettyPrint.java
@@ -17,6 +17,7 @@
package org.apache.poi.ooxml.dev;
import java.io.*;
+import java.nio.file.Files;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@@ -82,7 +83,8 @@ public class OOXMLPrettyPrint {
System.out.println("Reading zip-file " + file + " and writing pretty-printed XML to " + outFile);
try (ZipSecureFile zipFile = ZipHelper.openZipFile(file)) {
- try (ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outFile)))) {
+ try (ZipOutputStream out = new ZipOutputStream(
+ new BufferedOutputStream(Files.newOutputStream(outFile.toPath())))) {
new OOXMLPrettyPrint().handle(zipFile, out);
}
} finally {
diff --git a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java
index a6e3286b51..b8e3bcba9d 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/temp/AesZipFileZipEntrySource.java
@@ -20,9 +20,10 @@
package org.apache.poi.poifs.crypt.temp;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
import java.util.Enumeration;
import javax.crypto.Cipher;
@@ -130,8 +131,8 @@ public final class AesZipFileZipEntrySource implements ZipEntrySource {
Cipher ciEnc = CryptoFunctions.getCipher(skeySpec, CipherAlgorithm.aes128, ChainingMode.cbc, ivBytes, Cipher.ENCRYPT_MODE, PADDING);
try (ZipArchiveInputStream zis = new ZipArchiveInputStream(is);
- FileOutputStream fos = new FileOutputStream(tmpFile);
- ZipArchiveOutputStream zos = new ZipArchiveOutputStream(fos)) {
+ OutputStream fos = Files.newOutputStream(tmpFile.toPath());
+ ZipArchiveOutputStream zos = new ZipArchiveOutputStream(fos)) {
ZipArchiveEntry ze;
while ((ze = zis.getNextZipEntry()) != null) {
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/util/HierarchyPrinter.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/util/HierarchyPrinter.java
index bba3433850..b3a8a47b8e 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/util/HierarchyPrinter.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/util/HierarchyPrinter.java
@@ -19,14 +19,15 @@ package org.apache.poi.xdgf.util;
import java.awt.geom.AffineTransform;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import org.apache.poi.xdgf.usermodel.XDGFPage;
import org.apache.poi.xdgf.usermodel.XDGFShape;
@@ -46,7 +47,7 @@ public class HierarchyPrinter {
+ Util.sanitizeFilename(page.getName()) + ".txt");
try (
- OutputStream os = new FileOutputStream(pageFile);
+ OutputStream os = Files.newOutputStream(pageFile.toPath());
PrintStream pos = new PrintStream(os, false, StandardCharsets.UTF_8.name())
) {
printHierarchy(page, pos);
@@ -91,7 +92,7 @@ public class HierarchyPrinter {
String inFilename = args[0];
String outDir = args[1];
- try (FileInputStream is = new FileInputStream(inFilename)) {
+ try (InputStream is = Files.newInputStream(Paths.get(inFilename))) {
XmlVisioDocument doc = new XmlVisioDocument(is);
printHierarchy(doc, outDir);
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/util/VsdxToPng.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/util/VsdxToPng.java
index e8c96c3355..8d2aa31555 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/util/VsdxToPng.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/util/VsdxToPng.java
@@ -22,9 +22,11 @@ import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
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 java.nio.file.Paths;
import javax.imageio.ImageIO;
@@ -94,7 +96,7 @@ public class VsdxToPng {
graphics.dispose();
- try (FileOutputStream out = new FileOutputStream(outFile)) {
+ try (OutputStream out = Files.newOutputStream(outFile.toPath())) {
ImageIO.write(img, "png", out);
}
}
@@ -127,7 +129,7 @@ public class VsdxToPng {
renderer = new ShapeDebuggerRenderer();
}
- try (FileInputStream is = new FileInputStream(inFilename)) {
+ try (InputStream is = Files.newInputStream(Paths.get(inFilename))) {
XmlVisioDocument doc = new XmlVisioDocument(is);
renderToPng(doc, pngDir, 2000 / 11.0, renderer);
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/util/DummyFormat.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/util/DummyFormat.java
index 0a995ed498..63166ef855 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/util/DummyFormat.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/util/DummyFormat.java
@@ -19,11 +19,12 @@ package org.apache.poi.xslf.util;
import java.awt.Graphics2D;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
@@ -49,7 +50,7 @@ public class DummyFormat implements OutputFormat {
@Override
public void writeSlide(MFProxy proxy, File outFile) throws IOException {
- try (FileOutputStream fos = new FileOutputStream(outFile)) {
+ try (OutputStream fos = Files.newOutputStream(outFile.toPath())) {
bos.writeTo(fos);
bos.reset();
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/util/PPTX2PNG.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/util/PPTX2PNG.java
index a589855795..0dcbf813f5 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/util/PPTX2PNG.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/util/PPTX2PNG.java
@@ -24,10 +24,11 @@ import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Dimension2D;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.nio.charset.Charset;
+import java.nio.file.Files;
import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
@@ -426,7 +427,7 @@ public final class PPTX2PNG {
// do some sanitizing for creative filenames ...
filename = new File(filename == null ? "dummy.dat" : filename).getName();
filename = calcOutFile(proxy, slideNo).replaceFirst("\\.\\w+$", "")+"_"+filename;
- try (FileOutputStream fos = new FileOutputStream(new File(outdir, filename))) {
+ try (OutputStream fos = Files.newOutputStream(new File(outdir, filename).toPath())) {
fos.write(ep.getData().get());
}
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/util/SVGFormat.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/util/SVGFormat.java
index 3122855bde..3d8d119810 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/util/SVGFormat.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/util/SVGFormat.java
@@ -22,10 +22,10 @@ package org.apache.poi.xslf.util;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import org.apache.batik.dom.GenericDOMImplementation;
import org.apache.batik.svggen.SVGGraphics2D;
@@ -62,7 +62,7 @@ public class SVGFormat implements OutputFormat {
public void writeSlide(MFProxy proxy, File outFile) throws IOException {
// Batik DEFAULT_XML_ENCODING is ISO-8859-1 ... srsly?!
// Unicode entities aren't encoded, so use UTF-8
- try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(outFile.getCanonicalPath()), StandardCharsets.UTF_8)) {
+ try (OutputStreamWriter writer = new OutputStreamWriter(Files.newOutputStream(outFile.toPath()), StandardCharsets.UTF_8)) {
svgGenerator.stream(writer, true);
}
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
index d8fe3c16f7..4483995cfb 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
@@ -18,7 +18,6 @@
package org.apache.poi.xssf.streaming;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -27,6 +26,7 @@ import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
@@ -941,7 +941,7 @@ public class SXSSFWorkbook implements Workbook {
File tmplFile = TempFile.createTempFile("poi-sxssf-template", ".xlsx");
boolean deleted;
try {
- try (FileOutputStream os = new FileOutputStream(tmplFile)) {
+ try (OutputStream os = Files.newOutputStream(tmplFile.toPath())) {
_wb.write(os);
}
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hmef/dev/HMEFDumper.java b/poi-scratchpad/src/main/java/org/apache/poi/hmef/dev/HMEFDumper.java
index 72f40b65f9..5e2517f193 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hmef/dev/HMEFDumper.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hmef/dev/HMEFDumper.java
@@ -17,9 +17,10 @@
package org.apache.poi.hmef.dev;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.List;
import org.apache.poi.hmef.HMEFMessage;
@@ -67,7 +68,7 @@ public final class HMEFDumper {
continue;
}
- try (InputStream stream = new FileInputStream(arg)) {
+ try (InputStream stream = Files.newInputStream(Paths.get(arg))) {
HMEFDumper dumper = new HMEFDumper(stream);
dumper.setTruncatePropertyData(truncatePropData);
dumper.dump();
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hmef/extractor/HMEFContentsExtractor.java b/poi-scratchpad/src/main/java/org/apache/poi/hmef/extractor/HMEFContentsExtractor.java
index aacfb1a053..59cbe79e91 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hmef/extractor/HMEFContentsExtractor.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hmef/extractor/HMEFContentsExtractor.java
@@ -18,11 +18,10 @@
package org.apache.poi.hmef.extractor;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.file.Files;
import org.apache.poi.hmef.Attachment;
import org.apache.poi.hmef.HMEFMessage;
@@ -70,8 +69,9 @@ public final class HMEFContentsExtractor {
}
private final HMEFMessage message;
- public HMEFContentsExtractor(File filename) throws IOException {
- this(new HMEFMessage(new FileInputStream(filename)));
+
+ public HMEFContentsExtractor(File file) throws IOException {
+ this(new HMEFMessage(Files.newInputStream(file.toPath())));
}
public HMEFContentsExtractor(HMEFMessage message) {
this.message = message;
@@ -94,7 +94,7 @@ public final class HMEFContentsExtractor {
dest = new File(name + ".txt");
}
- try (OutputStream fout = new FileOutputStream(dest)) {
+ try (OutputStream fout = Files.newOutputStream(dest.toPath())) {
if (body instanceof MAPIStringAttribute) {
// Save in a predictable encoding, not raw bytes
String text = ((MAPIStringAttribute) body).getDataString();
@@ -153,7 +153,7 @@ public final class HMEFContentsExtractor {
// Save it
File file = new File(dir, filename);
- try (OutputStream fout = new FileOutputStream(file)) {
+ try (OutputStream fout = Files.newOutputStream(file.toPath())) {
fout.write(att.getContents());
}
}
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hpbf/dev/PLCDumper.java b/poi-scratchpad/src/main/java/org/apache/poi/hpbf/dev/PLCDumper.java
index 3c222d51b2..74dc8edbe3 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hpbf/dev/PLCDumper.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hpbf/dev/PLCDumper.java
@@ -17,9 +17,10 @@
package org.apache.poi.hpbf.dev;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import org.apache.poi.hpbf.HPBFDocument;
import org.apache.poi.hpbf.model.QuillContents;
@@ -54,7 +55,7 @@ public final class PLCDumper {
System.exit(1);
}
- try (FileInputStream fis = new FileInputStream(args[0])) {
+ try (InputStream fis = Files.newInputStream(Paths.get(args[0]))) {
PLCDumper dump = new PLCDumper(fis);
System.out.println("Dumping " + args[0]);
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java
index e27f5e3b93..f6b523fcc3 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/PPTXMLDump.java
@@ -19,12 +19,14 @@ package org.apache.poi.hslf.dev;
import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.Arrays;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
@@ -214,7 +216,7 @@ public final class PPTXMLDump {
System.out.println("Dumping " + arg);
if (outFile) {
- FileOutputStream fos = new FileOutputStream(ppt.getName() + ".xml");
+ OutputStream fos = Files.newOutputStream(Paths.get(ppt.getName() + ".xml"));
OutputStreamWriter out = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
dump.dump(out);
out.close();
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/extractor/ImageExtractor.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/extractor/ImageExtractor.java
index 926aada0ec..298d349674 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/extractor/ImageExtractor.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/extractor/ImageExtractor.java
@@ -17,8 +17,10 @@
package org.apache.poi.hslf.extractor;
-import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import org.apache.poi.hslf.usermodel.HSLFPictureData;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
@@ -44,7 +46,8 @@ public final class ImageExtractor {
byte[] data = pict.getData();
PictureType type = pict.getType();
- try (FileOutputStream out = new FileOutputStream("pict_" + i++ + type.extension)) {
+ try (OutputStream out = Files.newOutputStream(
+ Paths.get("pict_" + i++ + type.extension))) {
out.write(data);
}
}
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
index 15476e48f3..8fd7a1d40a 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
@@ -22,10 +22,10 @@ import static org.apache.logging.log4j.util.Unbox.box;
import java.awt.Dimension;
import java.io.Closeable;
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;
@@ -877,7 +877,7 @@ public final class HSLFSlideShow extends POIDocument implements SlideShow<HSLFSh
throw new IllegalArgumentException("Unsupported picture format: " + format);
}
byte[] data = IOUtils.safelyAllocate(pict.length(), MAX_RECORD_LENGTH);
- try (FileInputStream is = new FileInputStream(pict)) {
+ try (InputStream is = Files.newInputStream(pict.toPath())) {
IOUtils.readFully(is, data);
}
return addPicture(data, format);
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hssf/converter/AbstractExcelUtils.java b/poi-scratchpad/src/main/java/org/apache/poi/hssf/converter/AbstractExcelUtils.java
index 6ae0da8e01..88498ea39e 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hssf/converter/AbstractExcelUtils.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hssf/converter/AbstractExcelUtils.java
@@ -17,8 +17,9 @@
package org.apache.poi.hssf.converter;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
import java.util.Arrays;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -181,7 +182,7 @@ class AbstractExcelUtils {
}
public static HSSFWorkbook loadXls(File xlsFile) throws IOException {
- try (final FileInputStream inputStream = new FileInputStream(xlsFile)) {
+ try (final InputStream inputStream = Files.newInputStream(xlsFile.toPath())) {
return new HSSFWorkbook(inputStream);
}
}
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/converter/AbstractWordUtils.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/converter/AbstractWordUtils.java
index 048a288d61..7f6a3e0d24 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/converter/AbstractWordUtils.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/converter/AbstractWordUtils.java
@@ -17,9 +17,9 @@
package org.apache.poi.hwpf.converter;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -458,7 +458,7 @@ public class AbstractWordUtils
public static HWPFDocumentCore loadDoc( File docFile ) throws IOException
{
- try (FileInputStream istream = new FileInputStream(docFile)) {
+ try (InputStream istream = Files.newInputStream(docFile.toPath())) {
return loadDoc(istream);
}
}
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java
index 214af0afa1..3c79174417 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java
@@ -18,9 +18,9 @@
package org.apache.poi.hwpf.dev;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -67,7 +67,7 @@ import org.apache.poi.util.LittleEndian;
@Beta
public final class HWPFLister {
private static HWPFDocumentCore loadDoc( File docFile ) throws IOException {
- try (final FileInputStream istream = new FileInputStream( docFile )) {
+ try (final InputStream istream = Files.newInputStream(docFile.toPath())) {
return loadDoc( istream );
}
}
diff --git a/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java b/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
index dc05c63ec5..80b715a59b 100644
--- a/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
+++ b/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
@@ -23,7 +23,6 @@ import static org.apache.poi.hssf.model.InternalWorkbook.WORKBOOK_DIR_ENTRY_NAME
import java.io.BufferedInputStream;
import java.io.Closeable;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/agile/AgileEncryptor.java b/poi/src/main/java/org/apache/poi/poifs/crypt/agile/AgileEncryptor.java
index 73ed284721..17a03d8ebe 100644
--- a/poi/src/main/java/org/apache/poi/poifs/crypt/agile/AgileEncryptor.java
+++ b/poi/src/main/java/org/apache/poi/poifs/crypt/agile/AgileEncryptor.java
@@ -31,10 +31,10 @@ import static org.apache.poi.poifs.crypt.agile.AgileDecryptor.kIntegrityValueBlo
import static org.apache.poi.poifs.crypt.agile.AgileDecryptor.kVerifierInputBlock;
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.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.security.SecureRandom;
@@ -237,7 +237,7 @@ public class AgileEncryptor extends Encryptor {
LittleEndian.putLong(buf, 0, oleStreamSize);
integrityMD.update(buf, 0, LittleEndianConsts.LONG_SIZE);
- try (InputStream fis = new FileInputStream(tmpFile)) {
+ try (InputStream fis = Files.newInputStream(tmpFile.toPath())) {
int readBytes;
while ((readBytes = fis.read(buf)) != -1) {
integrityMD.update(buf, 0, readBytes);
diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java b/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java
index a5f2559965..8eb813ba61 100644
--- a/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java
+++ b/poi/src/main/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java
@@ -21,11 +21,11 @@ import static org.apache.poi.poifs.crypt.DataSpaceMapUtils.createEncryptionEntry
import static org.apache.poi.poifs.crypt.standard.StandardDecryptor.generateSecretKey;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.file.Files;
import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.security.SecureRandom;
@@ -145,7 +145,7 @@ public class StandardEncryptor extends Encryptor {
// field of the EncryptedPackage field specifies the number of bytes of
// unencrypted data as specified in section 2.3.4.4.
super(
- new CipherOutputStream(new FileOutputStream(fileOut), getCipher(getSecretKey(), "PKCS5Padding"))
+ new CipherOutputStream(Files.newOutputStream(fileOut.toPath()), getCipher(getSecretKey(), "PKCS5Padding"))
);
this.deleteFile = deleteFile;
this.fileOut = fileOut;
@@ -197,7 +197,7 @@ public class StandardEncryptor extends Encryptor {
// value, depending on the block size of the chosen encryption algorithm
leos.writeLong(countBytes);
- try (FileInputStream fis = new FileInputStream(fileOut)) {
+ try (InputStream fis = Files.newInputStream(fileOut.toPath())) {
IOUtils.copy(fis, leos);
}
if (!fileOut.delete()) {
diff --git a/poi/src/main/java/org/apache/poi/poifs/dev/POIFSLister.java b/poi/src/main/java/org/apache/poi/poifs/dev/POIFSLister.java
index f9696bccfb..8ae5d6e894 100644
--- a/poi/src/main/java/org/apache/poi/poifs/dev/POIFSLister.java
+++ b/poi/src/main/java/org/apache/poi/poifs/dev/POIFSLister.java
@@ -18,8 +18,10 @@
package org.apache.poi.poifs.dev;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.Iterator;
import org.apache.poi.poifs.filesystem.DirectoryNode;
@@ -68,7 +70,7 @@ public class POIFSLister {
}
public static void viewFileOld(final String filename, boolean withSizes) throws IOException {
- try (FileInputStream fis = new FileInputStream(filename);
+ try (InputStream fis = Files.newInputStream(Paths.get(filename));
POIFSFileSystem fs = new POIFSFileSystem(fis)) {
displayDirectory(fs.getRoot(), "", withSizes);
}
diff --git a/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroExtractor.java b/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroExtractor.java
index c4ff962a94..c0db47e5fb 100644
--- a/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroExtractor.java
+++ b/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroExtractor.java
@@ -19,9 +19,10 @@ package org.apache.poi.poifs.macros;
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import java.io.OutputStreamWriter;
+import java.nio.file.Files;
import java.util.Map;
import java.util.Map.Entry;
@@ -95,8 +96,8 @@ public class VBAMacroExtractor {
System.out.println(moduleCode);
} else {
File out = new File(outputDir, moduleName + extension);
- try (FileOutputStream fout = new FileOutputStream(out);
- OutputStreamWriter fwriter = new OutputStreamWriter(fout, StringUtil.UTF8)) {
+ try (OutputStream fout = Files.newOutputStream(out.toPath());
+ OutputStreamWriter fwriter = new OutputStreamWriter(fout, StringUtil.UTF8)) {
fwriter.write(moduleCode);
}
System.out.println("Extracted " + out);
diff --git a/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java b/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java
index c89b650452..944c05bbd1 100644
--- a/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java
+++ b/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java
@@ -24,12 +24,12 @@ import static org.apache.poi.util.StringUtil.startsWithIgnoreCase;
import java.io.Closeable;
import java.io.EOFException;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -93,7 +93,7 @@ public class VBAMacroReader implements Closeable {
try {
this.fs = new POIFSFileSystem(file);
} catch (OfficeXmlFileException e) {
- openOOXML(new FileInputStream(file));
+ openOOXML(Files.newInputStream(file.toPath()));
}
}
public VBAMacroReader(POIFSFileSystem fs) {
diff --git a/poi/src/main/java/org/apache/poi/util/FontMetricsDumper.java b/poi/src/main/java/org/apache/poi/util/FontMetricsDumper.java
index 321f0d5ea9..5078436bc2 100644
--- a/poi/src/main/java/org/apache/poi/util/FontMetricsDumper.java
+++ b/poi/src/main/java/org/apache/poi/util/FontMetricsDumper.java
@@ -22,9 +22,10 @@ import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.Properties;
@SuppressWarnings("deprecation")
@@ -66,7 +67,7 @@ public class FontMetricsDumper {
props.setProperty("font." + fontName + ".widths", widths.toString());
}
- try (OutputStream fileOut = new FileOutputStream("font_metrics.properties")) {
+ try (OutputStream fileOut = Files.newOutputStream(Paths.get("font_metrics.properties"))) {
props.store(fileOut, "Font Metrics");
}
}
diff --git a/poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java b/poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java
index 7b24b774f6..4aa0bd56bb 100644
--- a/poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java
+++ b/poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java
@@ -34,7 +34,6 @@ import java.awt.image.IndexColorModel;
import java.awt.image.PackedColorModel;
import java.io.Closeable;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.Flushable;
import java.io.IOException;
import java.io.OutputStream;
@@ -43,6 +42,7 @@ import java.io.PrintWriter;
import java.io.Writer;
import java.lang.reflect.Array;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
@@ -116,7 +116,8 @@ public class GenericRecordJsonWriter implements Closeable {
protected int childIndex = 0;
public GenericRecordJsonWriter(File fileName) throws IOException {
- OutputStream os = ("null".equals(fileName.getName())) ? NullOutputStream.INSTANCE : new FileOutputStream(fileName);
+ OutputStream os = ("null".equals(fileName.getName())) ?
+ NullOutputStream.INSTANCE : Files.newOutputStream(fileName.toPath());
aw = new AppendableWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));
fw = new PrintWriter(aw);
}
diff --git a/poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java b/poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java
index ba098965d3..fe8bc58dc5 100644
--- a/poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java
+++ b/poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java
@@ -29,13 +29,13 @@ import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.Closeable;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
@@ -108,7 +108,8 @@ public class GenericRecordXmlWriter implements Closeable {
private boolean attributePhase = true;
public GenericRecordXmlWriter(File fileName) throws IOException {
- OutputStream os = ("null".equals(fileName.getName())) ? NullOutputStream.INSTANCE : new FileOutputStream(fileName);
+ OutputStream os = ("null".equals(fileName.getName())) ?
+ NullOutputStream.INSTANCE : Files.newOutputStream(fileName.toPath());
fw = new PrintWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));
}
diff --git a/poi/src/main/java/org/apache/poi/util/IOUtils.java b/poi/src/main/java/org/apache/poi/util/IOUtils.java
index 51281d4bba..4fa3484af8 100644
--- a/poi/src/main/java/org/apache/poi/util/IOUtils.java
+++ b/poi/src/main/java/org/apache/poi/util/IOUtils.java
@@ -20,13 +20,13 @@ package org.apache.poi.util;
import java.io.Closeable;
import java.io.EOFException;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PushbackInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
+import java.nio.file.Files;
import java.util.Arrays;
import java.util.Locale;
import java.util.zip.CRC32;
@@ -436,7 +436,7 @@ public final class IOUtils {
if (!(destDirectory.exists() || destDirectory.mkdirs())) {
throw new IllegalStateException("Can't create destination directory: "+destDirectory);
}
- try (OutputStream destStream = new FileOutputStream(destFile)) {
+ try (OutputStream destStream = Files.newOutputStream(destFile.toPath())) {
return IOUtils.copy(srcStream, destStream);
}
}
diff --git a/poi/src/test/java/org/apache/poi/ss/formula/function/ExcelCetabFunctionExtractor.java b/poi/src/test/java/org/apache/poi/ss/formula/function/ExcelCetabFunctionExtractor.java
index 215f4e4cfd..87c0dcd1f3 100644
--- a/poi/src/test/java/org/apache/poi/ss/formula/function/ExcelCetabFunctionExtractor.java
+++ b/poi/src/test/java/org/apache/poi/ss/formula/function/ExcelCetabFunctionExtractor.java
@@ -19,7 +19,6 @@ package org.apache.poi.ss.formula.function;
import java.io.BufferedReader;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -322,8 +321,8 @@ public final class ExcelCetabFunctionExtractor {
}
private static void processFile(InputStream input, File outFile) throws IOException {
- try (OutputStream os = new SimpleAsciiOutputStream(new FileOutputStream(outFile));
- PrintStream ps = new PrintStream(os, true, StandardCharsets.UTF_8.name())) {
+ try (OutputStream os = new SimpleAsciiOutputStream(Files.newOutputStream(outFile.toPath()));
+ PrintStream ps = new PrintStream(os, true, StandardCharsets.UTF_8.name())) {
outputLicenseHeader(ps);
Class<?> genClass = ExcelCetabFunctionExtractor.class;
diff --git a/poi/src/test/java/org/apache/poi/ss/util/NumberComparingSpreadsheetGenerator.java b/poi/src/test/java/org/apache/poi/ss/util/NumberComparingSpreadsheetGenerator.java
index 8c241a6464..301a7e3019 100644
--- a/poi/src/test/java/org/apache/poi/ss/util/NumberComparingSpreadsheetGenerator.java
+++ b/poi/src/test/java/org/apache/poi/ss/util/NumberComparingSpreadsheetGenerator.java
@@ -18,8 +18,9 @@
package org.apache.poi.ss.util;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
@@ -135,7 +136,7 @@ public class NumberComparingSpreadsheetGenerator {
}
File outputFile = new File("ExcelNumberCompare.xls");
- try (FileOutputStream os = new FileOutputStream(outputFile)) {
+ try (OutputStream os = Files.newOutputStream(outputFile.toPath())) {
wb.write(os);
}
System.out.println("Finished writing '" + outputFile.getAbsolutePath() + "'");