You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by jo...@apache.org on 2021/04/24 07:54:49 UTC
[commons-fileupload] branch master updated: FILEUPLOAD-311 -
Replace construction of FileInputStream and FileOutputStream objects with
Files NIO APIs.
This is an automated email from the ASF dual-hosted git repository.
jochen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git
The following commit(s) were added to refs/heads/master by this push:
new 4539ecb FILEUPLOAD-311 - Replace construction of FileInputStream and FileOutputStream objects with Files NIO APIs.
new b15a806 Merge pull request #59 from arturobernalg/feature/FILEUPLOAD-311
4539ecb is described below
commit 4539ecbd688a419cc17b5d8a77999ca7c825a007
Author: Arturo Bernal <ar...@gmail.com>
AuthorDate: Thu Apr 22 18:21:35 2021 +0200
FILEUPLOAD-311 - Replace construction of FileInputStream and FileOutputStream objects with Files NIO APIs.
---
.../org/apache/commons/fileupload2/disk/DiskFileItem.java | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java b/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
index c173dc6..1e5da6e 100644
--- a/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
+++ b/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
@@ -20,12 +20,11 @@ import static java.lang.String.format;
import java.io.ByteArrayInputStream;
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.io.UnsupportedEncodingException;
+import java.nio.file.Files;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
@@ -203,7 +202,7 @@ public class DiskFileItem
public InputStream getInputStream()
throws IOException {
if (!isInMemory()) {
- return new FileInputStream(dfos.getFile());
+ return Files.newInputStream(dfos.getFile().toPath());
}
if (cachedContent == null) {
@@ -310,7 +309,7 @@ public class DiskFileItem
InputStream fis = null;
try {
- fis = new FileInputStream(dfos.getFile());
+ fis = Files.newInputStream(dfos.getFile().toPath());
IOUtils.readFully(fis, fileData);
} catch (final IOException e) {
fileData = null;
@@ -385,9 +384,9 @@ public class DiskFileItem
@Override
public void write(final File file) throws Exception {
if (isInMemory()) {
- FileOutputStream fout = null;
+ OutputStream fout = null;
try {
- fout = new FileOutputStream(file);
+ fout = Files.newOutputStream(file.toPath());
fout.write(get());
fout.close();
} finally {