This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch 1.x in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git
commit 1a83dfc3599c3d17853bef43f2695ebf5afebfe6 Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Sat May 3 16:25:52 2025 -0400 Internal refactoring --- .../commons/fileupload/disk/DiskFileItem.java | 67 ++++++++++++---------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java b/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java index b8b0ac3f..e11b17c2 100644 --- a/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java +++ b/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java @@ -60,6 +60,11 @@ import org.apache.commons.io.output.DeferredFileOutputStream; */ public class DiskFileItem implements FileItem { + /** + * Counter used in unique identifier generation. + */ + private static final AtomicInteger COUNTER = new AtomicInteger(0); + /** * Default content charset to be used when no explicit charset * parameter is provided by the sender. Media subtypes of the @@ -74,11 +79,6 @@ public class DiskFileItem implements FileItem { private static final String UID = UUID.randomUUID().toString().replace('-', '_'); - /** - * Counter used in unique identifier generation. - */ - private static final AtomicInteger COUNTER = new AtomicInteger(0); - /** * Returns an identifier that is unique within the class loader used to * load this class, but does not have random-like appearance. @@ -99,9 +99,9 @@ public class DiskFileItem implements FileItem { } /** - * The name of the form field as provided by the browser. + * Cached contents of the file. */ - private String fieldName; + private byte[] cachedContent; /** * The content type passed by the browser, or {@code null} if @@ -110,57 +110,57 @@ public class DiskFileItem implements FileItem { private final String contentType; /** - * Whether or not this item is a simple form field. + * Default content charset to be used when no explicit charset + * parameter is provided by the sender. */ - private boolean isFormField; + private String defaultCharset = DEFAULT_CHARSET; /** - * The original file name in the user's file system. + * Output stream for this item. */ - private final String fileName; + private transient DeferredFileOutputStream dfos; /** - * The size of the item, in bytes. This is used to cache the size when a - * file item is moved from its original location. + * The name of the form field as provided by the browser. */ - private long size = -1; + private String fieldName; /** - * The threshold above which uploads will be stored on disk. + * The original file name in the user's file system. */ - private final int sizeThreshold; + private final String fileName; /** - * The directory in which uploaded files will be stored, if stored on disk. + * The file items headers. */ - private final File repository; + private FileItemHeaders headers; /** - * Cached contents of the file. + * Whether or not this item is a simple form field. */ - private byte[] cachedContent; + private boolean isFormField; /** - * Output stream for this item. + * The directory in which uploaded files will be stored, if stored on disk. */ - private transient DeferredFileOutputStream dfos; + private final File repository; /** - * The temporary file to use. + * The size of the item, in bytes. This is used to cache the size when a + * file item is moved from its original location. */ - private transient File tempFile; + private long size = -1; /** - * The file items headers. + * The threshold above which uploads will be stored on disk. */ - private FileItemHeaders headers; + private final int sizeThreshold; /** - * Default content charset to be used when no explicit charset - * parameter is provided by the sender. + * The temporary file to use. */ - private String defaultCharset = DEFAULT_CHARSET; + private transient File tempFile; /** * Constructs a new {@code DiskFileItem} instance. @@ -190,6 +190,13 @@ public class DiskFileItem implements FileItem { this.repository = repository; } + /** + * Clears the cache. + */ + private void clear() { + cachedContent = null; // NOPMD + } + /** * Deletes the underlying storage for a file item, including deleting any * associated temporary disk file. Although this storage will be deleted @@ -199,7 +206,7 @@ public class DiskFileItem implements FileItem { */ @Override public void delete() { - cachedContent = null; + clear(); final File outputFile = getStoreLocation(); if (outputFile != null && !isInMemory() && outputFile.exists()) { outputFile.delete();