You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/06/22 11:24:15 UTC

[commons-fileupload] branch master updated: Make FileItem.delete() throw IOException like Part.delete()

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 9591bb8  Make FileItem.delete() throw IOException like Part.delete()
9591bb8 is described below

commit 9591bb80089f087497c21275590ee4ba5075d677
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Jun 22 07:24:10 2023 -0400

    Make FileItem.delete() throw IOException like Part.delete()
---
 .../java/org/apache/commons/fileupload2/core/FileItem.java  |  4 +++-
 .../apache/commons/fileupload2/core/disk/DiskFileItem.java  | 13 ++++---------
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileItem.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileItem.java
index e8d1f84..f064d9c 100644
--- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileItem.java
+++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileItem.java
@@ -46,8 +46,10 @@ public interface FileItem extends FileItemHeadersProvider {
      * Deletes the underlying storage for a file item, including deleting any associated temporary disk file. Although this storage will be deleted
      * automatically when the {@code FileItem} instance is garbage collected, this method can be used to ensure that this is done at an earlier time, thus
      * preserving system resources.
+     *
+     * @throws IOException if an error occurs.
      */
-    void delete();
+    void delete() throws IOException;
 
     /**
      * Gets the contents of the file item as a byte array.
diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/disk/DiskFileItem.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/disk/DiskFileItem.java
index b01b6e6..a380e8d 100644
--- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/disk/DiskFileItem.java
+++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/disk/DiskFileItem.java
@@ -73,7 +73,6 @@ public final class DiskFileItem implements FileItem {
      * </p>
      *
      * <pre>{@code
-     * <pre>{@code
      * final FileItem fileItem = fileItemFactory.fileItemBuilder()
      *   .setFieldName("FieldName")
      *   .setContentType("ContentType")
@@ -83,8 +82,6 @@ public final class DiskFileItem implements FileItem {
      *   .get();
      * }
      * </pre>
-     * }
-     * </pre>
      */
     public static class Builder extends FileItemBuilder<DiskFileItem, Builder> {
 
@@ -283,17 +280,15 @@ public final class DiskFileItem implements FileItem {
     /**
      * Deletes the underlying storage for a file item, including deleting any associated temporary disk file. This method can be used to ensure that this is
      * done at an earlier time, thus preserving system resources.
+     *
+     * @throws IOException if an error occurs.
      */
     @Override
-    public void delete() {
+    public void delete() throws IOException {
         cachedContent = null;
         final Path outputFile = getStoreLocation();
         if (outputFile != null && !isInMemory() && Files.exists(outputFile)) {
-            try {
-                Files.delete(outputFile);
-            } catch (final IOException e) {
-                throw new UncheckedIOException(outputFile.toString(), e);
-            }
+            Files.delete(outputFile);
         }
     }