This is an automated email from the ASF dual-hosted git repository.
ggregory 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 8139581 Reuse Files.readAllBytes()
8139581 is described below
commit 81395819e68af46016ee0bbe74c5d11a6fd4a163
Author: Gary Gregory <[email protected]>
AuthorDate: Thu May 25 09:28:35 2023 -0400
Reuse Files.readAllBytes()
---
.../org/apache/commons/fileupload2/disk/DiskFileItem.java | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git
a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
index ee44756..3072203 100644
---
a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
+++
b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
@@ -35,7 +35,7 @@ import org.apache.commons.fileupload2.FileUploadException;
import org.apache.commons.fileupload2.InvalidFileNameException;
import org.apache.commons.fileupload2.ParameterParser;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.function.Uncheck;
import org.apache.commons.io.output.DeferredFileOutputStream;
/**
@@ -222,7 +222,7 @@ public class DiskFileItem implements FileItem {
*
* @return The contents of the file as an array of bytes or {@code null}
if the data cannot be read.
* @throws UncheckedIOException if an I/O error occurs.
- * @throws ArithmeticException if the file {@code size} overflows an int.
+ * @throws OutOfMemoryError if an array of the required size cannot be
allocated, for example the file is larger that {@code 2GB}
*/
@Override
public byte[] get() throws UncheckedIOException {
@@ -232,15 +232,7 @@ public class DiskFileItem implements FileItem {
}
return cachedContent != null ? cachedContent.clone() : new byte[0];
}
-
- final byte[] fileData = new byte[Math.toIntExact(getSize())];
-
- try (InputStream fis = Files.newInputStream(dfos.getFile().toPath())) {
- IOUtils.readFully(fis, fileData);
- } catch (final IOException e) {
- throw new UncheckedIOException(e);
- }
- return fileData;
+ return Uncheck.get(() -> Files.readAllBytes(dfos.getFile().toPath()));
}
/**