Skip to content
Permalink
Browse files
Merge pull request #59 from arturobernalg/feature/FILEUPLOAD-311
FILEUPLOAD-311 - Replace construction of FileInputStream and FileOutputStream objects with Files NIO APIs.
  • Loading branch information
jochenw committed Apr 24, 2021
2 parents 289acf5 + 4539ecb commit b15a80643cc22978b3a4492747b4f7479e1d6c42
Showing 1 changed file with 5 additions and 6 deletions.
@@ -20,12 +20,11 @@

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 DiskFileItem(final String fieldName,
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 byte[] get() {
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 String getString() {
@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 {

0 comments on commit b15a806

Please sign in to comment.