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 8306f58  Abstract out FileUpload for subclasses
8306f58 is described below

commit 8306f585cca8ba874bd9cb87c883e55706246108
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Mon May 22 12:44:05 2023 -0400

    Abstract out FileUpload for subclasses
---
 .../org/apache/commons/fileupload2/FileUpload.java | 43 +++++++++++++++++++---
 .../jakarta/JakartaServletFileUpload.java          |  5 ++-
 .../fileupload2/javax/ServletFileUpload.java       |  5 ++-
 .../fileupload2/portlet/PortletFileUpload.java     |  5 ++-
 4 files changed, 49 insertions(+), 9 deletions(-)

diff --git 
a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileUpload.java
 
b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileUpload.java
index c177765..ce45d75 100644
--- 
a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileUpload.java
+++ 
b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileUpload.java
@@ -16,22 +16,23 @@
  */
 package org.apache.commons.fileupload2;
 
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
 /**
- * <p>
  * High level API for processing file uploads.
- * </p>
- *
  * <p>
  * This class handles multiple files per single HTML widget, sent using {@code 
multipart/mixed} encoding type, as specified by
  * <a href="http://www.ietf.org/rfc/rfc1867.txt";>RFC 1867</a>. Use {@link 
#parseRequest(RequestContext)} to acquire a list of
- * {@link org.apache.commons.fileupload2.FileItem FileItems} associated with a 
given HTML widget.
+ * {@link org.apache.commons.fileupload2.FileItem} associated with a given 
HTML widget.
  * </p>
- *
  * <p>
  * How the data for individual parts is stored is determined by the factory 
used to create them; a given part may be in memory, on disk, or somewhere else.
  * </p>
+ * @param <T> the context type
  */
-public class FileUpload extends AbstractFileUpload {
+public abstract class FileUpload<T> extends AbstractFileUpload {
 
     /**
      * The factory to use to create new form items.
@@ -78,4 +79,34 @@ public class FileUpload extends AbstractFileUpload {
         this.fileItemFactory = factory;
     }
 
+    /**
+     * Gets a file item iterator.
+     *
+     * @param request The servlet request to be parsed.
+     * @return An iterator to instances of {@code FileItemStream} parsed from 
the request, in the order that they were transmitted.
+     * @throws FileUploadException if there are problems reading/parsing the 
request or storing files.
+     * @throws IOException         An I/O error occurred. This may be a 
network error while communicating with the client or a problem while storing the
+     *                             uploaded content.
+     */
+    public abstract FileItemIterator getItemIterator(T request) throws 
FileUploadException, IOException;
+
+    /**
+     * Parses an <a href="http://www.ietf.org/rfc/rfc1867.txt";>RFC 1867</a> 
compliant {@code multipart/form-data} stream.
+     *
+     * @param request The servlet request to be parsed.
+     * @return A map of {@code FileItem} instances parsed from the request.
+     * @throws FileUploadException if there are problems reading/parsing the 
request or storing files.
+     * @since 1.3
+     */
+    public abstract Map<String, List<FileItem>> parseParameterMap(T request) 
throws FileUploadException;
+
+    /**
+     * Parses an <a href="http://www.ietf.org/rfc/rfc1867.txt";>RFC 1867</a> 
compliant {@code multipart/form-data} stream.
+     *
+     * @param request The servlet request to be parsed.
+     * @return A list of {@code FileItem} instances parsed from the request, 
in the order that they were transmitted.
+     * @throws FileUploadException if there are problems reading/parsing the 
request or storing files.
+     */
+    public abstract List<FileItem> parseRequest(T request) throws 
FileUploadException;
+
 }
diff --git 
a/commons-fileupload2-jakarta/src/main/java/org/apache/commons/fileupload2/jakarta/JakartaServletFileUpload.java
 
b/commons-fileupload2-jakarta/src/main/java/org/apache/commons/fileupload2/jakarta/JakartaServletFileUpload.java
index 2a37b0f..0df0a71 100644
--- 
a/commons-fileupload2-jakarta/src/main/java/org/apache/commons/fileupload2/jakarta/JakartaServletFileUpload.java
+++ 
b/commons-fileupload2-jakarta/src/main/java/org/apache/commons/fileupload2/jakarta/JakartaServletFileUpload.java
@@ -40,7 +40,7 @@ import jakarta.servlet.http.HttpServletRequest;
  * How the data for individual parts is stored is determined by the factory 
used to create them; a given part may be in memory, on disk, or somewhere else.
  * </p>
  */
-public class JakartaServletFileUpload extends FileUpload {
+public class JakartaServletFileUpload extends FileUpload<HttpServletRequest> {
 
     /**
      * Constant for HTTP POST method.
@@ -86,6 +86,7 @@ public class JakartaServletFileUpload extends FileUpload {
      * @throws IOException         An I/O error occurred. This may be a 
network error while communicating with the client or a problem while storing the
      *                             uploaded content.
      */
+    @Override
     public FileItemIterator getItemIterator(final HttpServletRequest request) 
throws FileUploadException, IOException {
         return super.getItemIterator(new 
JakartaServletRequestContext(request));
     }
@@ -99,6 +100,7 @@ public class JakartaServletFileUpload extends FileUpload {
      *
      * @since 1.3
      */
+    @Override
     public Map<String, List<FileItem>> parseParameterMap(final 
HttpServletRequest request) throws FileUploadException {
         return parseParameterMap(new JakartaServletRequestContext(request));
     }
@@ -110,6 +112,7 @@ public class JakartaServletFileUpload extends FileUpload {
      * @return A list of {@code FileItem} instances parsed from the request, 
in the order that they were transmitted.
      * @throws FileUploadException if there are problems reading/parsing the 
request or storing files.
      */
+    @Override
     public List<FileItem> parseRequest(final HttpServletRequest request) 
throws FileUploadException {
         return parseRequest(new JakartaServletRequestContext(request));
     }
diff --git 
a/commons-fileupload2-javax/src/main/java/org/apache/commons/fileupload2/javax/ServletFileUpload.java
 
b/commons-fileupload2-javax/src/main/java/org/apache/commons/fileupload2/javax/ServletFileUpload.java
index 9287593..4293b1f 100644
--- 
a/commons-fileupload2-javax/src/main/java/org/apache/commons/fileupload2/javax/ServletFileUpload.java
+++ 
b/commons-fileupload2-javax/src/main/java/org/apache/commons/fileupload2/javax/ServletFileUpload.java
@@ -40,7 +40,7 @@ import org.apache.commons.fileupload2.FileUploadException;
  * How the data for individual parts is stored is determined by the factory 
used to create them; a given part may be in memory, on disk, or somewhere else.
  * </p>
  */
-public class ServletFileUpload extends FileUpload {
+public class ServletFileUpload extends FileUpload<HttpServletRequest> {
 
     /**
      * Constant for HTTP POST method.
@@ -86,6 +86,7 @@ public class ServletFileUpload extends FileUpload {
      * @throws IOException         An I/O error occurred. This may be a 
network error while communicating with the client or a problem while storing the
      *                             uploaded content.
      */
+    @Override
     public FileItemIterator getItemIterator(final HttpServletRequest request) 
throws FileUploadException, IOException {
         return super.getItemIterator(new ServletRequestContext(request));
     }
@@ -98,6 +99,7 @@ public class ServletFileUpload extends FileUpload {
      * @throws FileUploadException if there are problems reading/parsing the 
request or storing files.
      * @since 1.3
      */
+    @Override
     public Map<String, List<FileItem>> parseParameterMap(final 
HttpServletRequest request) throws FileUploadException {
         return parseParameterMap(new ServletRequestContext(request));
     }
@@ -109,6 +111,7 @@ public class ServletFileUpload extends FileUpload {
      * @return A list of {@code FileItem} instances parsed from the request, 
in the order that they were transmitted.
      * @throws FileUploadException if there are problems reading/parsing the 
request or storing files.
      */
+    @Override
     public List<FileItem> parseRequest(final HttpServletRequest request) 
throws FileUploadException {
         return parseRequest(new ServletRequestContext(request));
     }
diff --git 
a/commons-fileupload2-portlet/src/main/java/org/apache/commons/fileupload2/portlet/PortletFileUpload.java
 
b/commons-fileupload2-portlet/src/main/java/org/apache/commons/fileupload2/portlet/PortletFileUpload.java
index 2384792..c20faf3 100644
--- 
a/commons-fileupload2-portlet/src/main/java/org/apache/commons/fileupload2/portlet/PortletFileUpload.java
+++ 
b/commons-fileupload2-portlet/src/main/java/org/apache/commons/fileupload2/portlet/PortletFileUpload.java
@@ -43,7 +43,7 @@ import org.apache.commons.fileupload2.FileUploadException;
  *
  * @since 1.1
  */
-public class PortletFileUpload extends FileUpload {
+public class PortletFileUpload extends FileUpload<ActionRequest> {
 
     /**
      * Tests whether the request contains multipart content.
@@ -83,6 +83,7 @@ public class PortletFileUpload extends FileUpload {
      * @throws IOException         An I/O error occurred. This may be a 
network error while communicating with the client or a problem while storing the
      *                             uploaded content.
      */
+    @Override
     public FileItemIterator getItemIterator(final ActionRequest request) 
throws FileUploadException, IOException {
         return super.getItemIterator(new PortletRequestContext(request));
     }
@@ -95,6 +96,7 @@ public class PortletFileUpload extends FileUpload {
      * @throws FileUploadException if there are problems reading/parsing the 
request or storing files.
      * @since 1.3
      */
+    @Override
     public Map<String, List<FileItem>> parseParameterMap(final ActionRequest 
request) throws FileUploadException {
         return parseParameterMap(new PortletRequestContext(request));
     }
@@ -106,6 +108,7 @@ public class PortletFileUpload extends FileUpload {
      * @return A list of {@code FileItem} instances parsed from the request, 
in the order that they were transmitted.
      * @throws FileUploadException if there are problems reading/parsing the 
request or storing files.
      */
+    @Override
     public List<FileItem> parseRequest(final ActionRequest request) throws 
FileUploadException {
         return parseRequest(new PortletRequestContext(request));
     }

Reply via email to