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/11 14:20:55 UTC

[commons-fileupload] branch master updated (8a0c4e1 -> b0bc562)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git


    from 8a0c4e1  Make DiskFileItemFactory fluent and immutable
     new 834ca00  Clean up test exceptions
     new e3f0f19  More accurate API name
     new b0bc562  ItemSkippedException now extends FileUploadException

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../commons/fileupload2/AbstractFileUpload.java    |  2 +-
 .../apache/commons/fileupload2/FileItemStream.java | 35 ++++++++++++++--------
 .../commons/fileupload2/FileItemStreamImpl.java    | 28 ++++++++---------
 .../commons/fileupload2/MultipartStream.java       |  2 +-
 .../fileupload2/AbstractFileUploadTest.java        | 24 +++++++++++----
 .../fileupload2/AbstractProgressListenerTest.java  |  4 ++-
 .../commons/fileupload2/AbstractSizesTest.java     | 18 +++++++----
 .../commons/fileupload2/AbstractStreamingTest.java | 18 ++++++++---
 .../disk/DiskFileItemSerializeTest.java            | 14 +++++++--
 .../jakarta/JakartaMockHttpServletRequest.java     |  2 +-
 10 files changed, 98 insertions(+), 49 deletions(-)


[commons-fileupload] 01/03: Clean up test exceptions

Posted by gg...@apache.org.
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

commit 834ca001a5f6e37ee9e373fc0f44aa9c9b0508cf
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jun 11 10:15:45 2023 -0400

    Clean up test exceptions
    
    Javadoc
---
 .../fileupload2/AbstractFileUploadTest.java        | 24 ++++++++++++++++------
 .../fileupload2/AbstractProgressListenerTest.java  |  2 ++
 .../commons/fileupload2/AbstractSizesTest.java     | 14 +++++++++----
 .../commons/fileupload2/AbstractStreamingTest.java | 18 ++++++++++++----
 .../disk/DiskFileItemSerializeTest.java            | 14 +++++++++++--
 .../jakarta/JakartaMockHttpServletRequest.java     |  2 +-
 6 files changed, 57 insertions(+), 17 deletions(-)

diff --git a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractFileUploadTest.java b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractFileUploadTest.java
index 2d79d24..4077abb 100644
--- a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractFileUploadTest.java
+++ b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractFileUploadTest.java
@@ -52,9 +52,11 @@ public abstract class AbstractFileUploadTest<T extends FileUpload<?>> extends Ab
 
     /**
      * Tests <a href="https://issues.apache.org/jira/browse/FILEUPLOAD-239">FILEUPLOAD-239</a>
+     *
+     * @throws IOException         Test failure.
      */
     @Test
-    public void testContentTypeAttachment() throws IOException, FileUploadException {
+    public void testContentTypeAttachment() throws IOException {
         // @formatter:off
         final List<FileItem> fileItems = parseUpload(upload,
                 "-----1234\r\n" +
@@ -90,6 +92,8 @@ public abstract class AbstractFileUploadTest<T extends FileUpload<?>> extends Ab
 
     /**
      * This is what the browser does if you submit the form without choosing a file.
+     *
+     * @throws FileUploadException Test failure.
      */
     @Test
     public void testEmptyFile() throws FileUploadException {
@@ -110,7 +114,7 @@ public abstract class AbstractFileUploadTest<T extends FileUpload<?>> extends Ab
     }
 
     @Test
-    public void testFilenameCaseSensitivity() throws IOException, FileUploadException {
+    public void testFilenameCaseSensitivity() throws IOException {
         // @formatter:off
         final List<FileItem> fileItems = parseUpload(upload,
                                                "-----1234\r\n" +
@@ -130,7 +134,7 @@ public abstract class AbstractFileUploadTest<T extends FileUpload<?>> extends Ab
     }
 
     @Test
-    public void testFileUpload() throws IOException, FileUploadException {
+    public void testFileUpload() throws IOException {
         // @formatter:off
         final List<FileItem> fileItems = parseUpload(upload,
                                                "-----1234\r\n" +
@@ -181,9 +185,11 @@ public abstract class AbstractFileUploadTest<T extends FileUpload<?>> extends Ab
 
     /**
      * Test case for <a href="https://issues.apache.org/jira/browse/FILEUPLOAD-130">
+     *
+     * @throws IOException Test failure.
      */
     @Test
-    public void testFileUpload130() throws Exception {
+    public void testFileUpload130() throws IOException {
         final String[] headerNames = { "SomeHeader", "OtherHeader", "YetAnotherHeader", "WhatAHeader" };
         final String[] headerValues = { "present", "Is there", "Here", "Is That" };
         // @formatter:off
@@ -232,9 +238,11 @@ public abstract class AbstractFileUploadTest<T extends FileUpload<?>> extends Ab
 
     /**
      * Test for <a href="https://issues.apache.org/jira/browse/FILEUPLOAD-62">FILEUPLOAD-62</a>
+     *
+     * @throws IOException Test failure.
      */
     @Test
-    public void testFILEUPLOAD62() throws Exception {
+    public void testFILEUPLOAD62() throws IOException {
         // @formatter:off
         final String contentType = "multipart/form-data; boundary=AaB03x";
         final String request =
@@ -278,9 +286,11 @@ public abstract class AbstractFileUploadTest<T extends FileUpload<?>> extends Ab
 
     /**
      * Test for <a href="https://issues.apache.org/jira/browse/FILEUPLOAD-111">FILEUPLOAD-111</a>
+     *
+     * @throws IOException Test failure.
      */
     @Test
-    public void testFoldedHeaders() throws IOException, FileUploadException {
+    public void testFoldedHeaders() throws IOException {
         // @formatter:off
         final List<FileItem> fileItems = parseUpload(upload, "-----1234\r\n" +
                 "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" +
@@ -332,6 +342,8 @@ public abstract class AbstractFileUploadTest<T extends FileUpload<?>> extends Ab
     /**
      * Internet Explorer 5 for the Mac has a bug where the carriage return is missing on any boundary line immediately preceding an input with type=image.
      * (type=submit does not have the bug.)
+     *
+     * @throws FileUploadException Test failure.
      */
     @Test
     public void testIE5MacBug() throws FileUploadException {
diff --git a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractProgressListenerTest.java b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractProgressListenerTest.java
index 37b03aa..6931268 100644
--- a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractProgressListenerTest.java
+++ b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractProgressListenerTest.java
@@ -96,6 +96,8 @@ public abstract class AbstractProgressListenerTest<F extends FileUpload<R>, R> e
 
     /**
      * Parse a very long file upload by using a progress listener.
+     *
+     * @throws IOException Test failure.
      */
     @Test
     public void testProgressListener() throws IOException {
diff --git a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractSizesTest.java b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractSizesTest.java
index ab24491..e6f7f80 100644
--- a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractSizesTest.java
+++ b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractSizesTest.java
@@ -40,9 +40,11 @@ public abstract class AbstractSizesTest<F extends FileUpload<R>, R> extends Abst
 
     /**
      * Checks, whether limiting the file size works.
+     *
+     * @throws IOException Test failure.
      */
     @Test
-    public void testFileSizeLimit() throws IOException, FileUploadException {
+    public void testFileSizeLimit() throws IOException {
         // @formatter:off
         final String request =
             "-----1234\r\n" +
@@ -83,9 +85,11 @@ public abstract class AbstractSizesTest<F extends FileUpload<R>, R> extends Abst
 
     /**
      * Checks, whether a faked Content-Length header is detected.
+     *
+     * @throws IOException Test failure.
      */
     @Test
-    public void testFileSizeLimitWithFakedContentLength() throws IOException, FileUploadException {
+    public void testFileSizeLimitWithFakedContentLength() throws IOException {
         // @formatter:off
         final String request =
             "-----1234\r\n" +
@@ -139,9 +143,11 @@ public abstract class AbstractSizesTest<F extends FileUpload<R>, R> extends Abst
 
     /**
      * Checks whether maxSize works.
+     *
+     * @throws IOException Test failure.
      */
     @Test
-    public void testMaxSizeLimit() throws IOException, FileUploadException {
+    public void testMaxSizeLimit() throws IOException {
         // @formatter:off
         final String request =
             "-----1234\r\n" +
@@ -174,7 +180,7 @@ public abstract class AbstractSizesTest<F extends FileUpload<R>, R> extends Abst
     }
 
     @Test
-    public void testMaxSizeLimitUnknownContentLength() throws IOException, FileUploadException {
+    public void testMaxSizeLimitUnknownContentLength() throws IOException {
         // @formatter:off
         final String request =
             "-----1234\r\n" +
diff --git a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractStreamingTest.java b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractStreamingTest.java
index 5259897..ffbdcd0 100644
--- a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractStreamingTest.java
+++ b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractStreamingTest.java
@@ -115,9 +115,11 @@ public abstract class AbstractStreamingTest<F extends FileUpload<R>, R, C extend
 
     /**
      * Tests a file upload with varying file sizes.
+     *
+     * @throws IOException Test failure.
      */
     @Test
-    public void testFileUpload() throws IOException, FileUploadException {
+    public void testFileUpload() throws IOException {
         final byte[] request = newRequest();
         final List<FileItem> fileItems = parseUpload(request);
         final Iterator<FileItem> fileIter = fileItems.iterator();
@@ -140,9 +142,11 @@ public abstract class AbstractStreamingTest<F extends FileUpload<R>, R, C extend
 
     /**
      * Test for FILEUPLOAD-135
+     *
+     * @throws IOException Test failure.
      */
     @Test
-    public void testFILEUPLOAD135() throws IOException, FileUploadException {
+    public void testFILEUPLOAD135() throws IOException {
         final byte[] request = newShortRequest();
         final ByteArrayInputStream bais = new ByteArrayInputStream(request);
         final List<FileItem> fileItems = parseUpload(new InputStream() {
@@ -171,9 +175,11 @@ public abstract class AbstractStreamingTest<F extends FileUpload<R>, R, C extend
 
     /**
      * Tests, whether an invalid request throws a proper exception.
+     *
+     * @throws IOException Test failure.
      */
     @Test
-    public void testFileUploadException() throws IOException, FileUploadException {
+    public void testFileUploadException() throws IOException {
         final byte[] request = newRequest();
         final byte[] invalidRequest = new byte[request.length - 11];
         System.arraycopy(request, 0, invalidRequest, 0, request.length - 11);
@@ -187,9 +193,11 @@ public abstract class AbstractStreamingTest<F extends FileUpload<R>, R, C extend
 
     /**
      * Tests, whether an {@link InvalidPathException} is thrown.
+     *
+     * @throws IOException Test failure.
      */
     @Test
-    public void testInvalidFileNameException() throws Exception {
+    public void testInvalidFileNameException() throws IOException {
         final String fileName = "foo.exe\u0000.png";
         // @formatter:off
         final String request =
@@ -240,6 +248,8 @@ public abstract class AbstractStreamingTest<F extends FileUpload<R>, R, C extend
 
     /**
      * Tests, whether an IOException is properly delegated.
+     *
+     * @throws IOException Test failure.
      */
     @Test
     public void testIOException() throws IOException {
diff --git a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/disk/DiskFileItemSerializeTest.java b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/disk/DiskFileItemSerializeTest.java
index 28e56a1..0ccf5e2 100644
--- a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/disk/DiskFileItemSerializeTest.java
+++ b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/disk/DiskFileItemSerializeTest.java
@@ -155,6 +155,8 @@ public class DiskFileItemSerializeTest {
 
     /**
      * Test creation of a field for which the amount of data falls above the configured threshold.
+     *
+     * @throws IOException Test failure.
      */
     @Test
     public void testAboveThreshold() throws IOException {
@@ -173,6 +175,8 @@ public class DiskFileItemSerializeTest {
 
     /**
      * Test creation of a field for which the amount of data falls below the configured threshold.
+     *
+     * @throws IOException Test failure.
      */
     @Test
     public void testBelowThreshold() throws IOException {
@@ -196,7 +200,7 @@ public class DiskFileItemSerializeTest {
     /**
      * Helper method to test creation of a field when a repository is used.
      */
-    public void testInMemoryObject(final byte[] testFieldValueBytes, final Path repository) throws IOException {
+    private void testInMemoryObject(final byte[] testFieldValueBytes, final Path repository) throws IOException {
         final FileItem item = createFileItem(testFieldValueBytes, repository);
 
         // Check state is as expected
@@ -209,6 +213,8 @@ public class DiskFileItemSerializeTest {
 
     /**
      * Test deserialization fails when repository is not valid.
+     *
+     * @throws IOException Test failure.
      */
     @Test
     public void testInvalidRepository() throws IOException {
@@ -221,6 +227,8 @@ public class DiskFileItemSerializeTest {
 
     /**
      * Test creation of a field for which the amount of data equals the configured threshold.
+     *
+     * @throws IOException Test failure.
      */
     @Test
     public void testThreshold() throws IOException {
@@ -231,6 +239,8 @@ public class DiskFileItemSerializeTest {
 
     /**
      * Test serialization and deserialization when repository is not null.
+     *
+     * @throws IOException Test failure.
      */
     @Test
     public void testValidRepository() throws IOException {
@@ -242,7 +252,7 @@ public class DiskFileItemSerializeTest {
     /**
      * Helper method to test writing item contents to a file.
      */
-    public void testWritingToFile(final FileItem item, final byte[] testFieldValueBytes) throws IOException {
+    private void testWritingToFile(final FileItem item, final byte[] testFieldValueBytes) throws IOException {
         final Path temp = Files.createTempFile("fileupload", null);
         // Note that the file exists and is initially empty;
         // write() must be able to handle that.
diff --git a/commons-fileupload2-jakarta/src/test/java/org/apache/commons/fileupload2/jakarta/JakartaMockHttpServletRequest.java b/commons-fileupload2-jakarta/src/test/java/org/apache/commons/fileupload2/jakarta/JakartaMockHttpServletRequest.java
index 723d3d9..48372fd 100644
--- a/commons-fileupload2-jakarta/src/test/java/org/apache/commons/fileupload2/jakarta/JakartaMockHttpServletRequest.java
+++ b/commons-fileupload2-jakarta/src/test/java/org/apache/commons/fileupload2/jakarta/JakartaMockHttpServletRequest.java
@@ -59,7 +59,7 @@ public class JakartaMockHttpServletRequest implements HttpServletRequest {
         /**
          * Creates a new instance, which returns the given streams data.
          */
-        public MyServletInputStream(final InputStream inputStream, final int readLimit) {
+        MyServletInputStream(final InputStream inputStream, final int readLimit) {
             this.inputStream = inputStream;
             this.readLimit = readLimit;
         }


[commons-fileupload] 02/03: More accurate API name

Posted by gg...@apache.org.
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

commit e3f0f19ad1d8ee7c0c527bf885ade9bf1e65bd8a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jun 11 10:18:39 2023 -0400

    More accurate API name
---
 .../commons/fileupload2/AbstractFileUpload.java    |  2 +-
 .../apache/commons/fileupload2/FileItemStream.java | 24 +++++++++----------
 .../commons/fileupload2/FileItemStreamImpl.java    | 28 +++++++++++-----------
 .../fileupload2/AbstractProgressListenerTest.java  |  2 +-
 .../commons/fileupload2/AbstractSizesTest.java     |  4 ++--
 5 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/AbstractFileUpload.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/AbstractFileUpload.java
index b7d25af..9909d3f 100644
--- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/AbstractFileUpload.java
+++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/AbstractFileUpload.java
@@ -423,7 +423,7 @@ public abstract class AbstractFileUpload {
                 final FileItem fileItem = fileItemFactory.createFileItem(fileItemStream.getFieldName(), fileItemStream.getContentType(),
                         fileItemStream.isFormField(), fileName, fileItemStream.getHeaders());
                 itemList.add(fileItem);
-                try (InputStream inputStream = fileItemStream.openStream();
+                try (InputStream inputStream = fileItemStream.getInputStream();
                         OutputStream outputStream = fileItem.getOutputStream()) {
                     IOUtils.copyLarge(inputStream, outputStream, buffer);
                 } catch (final FileUploadException e) {
diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStream.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStream.java
index e3ec176..a706099 100644
--- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStream.java
+++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStream.java
@@ -22,7 +22,7 @@ import java.io.InputStream;
 /**
  * Provides access to a file or form item that was received within a {@code multipart/form-data} POST request.
  * <p>
- * The items contents are retrieved by calling {@link #openStream()}.
+ * The items contents are retrieved by calling {@link #getInputStream()}.
  * </p>
  * <p>
  * Instances of this class are created by accessing the iterator, returned by {@link AbstractFileUpload#getItemIterator(RequestContext)}.
@@ -36,7 +36,7 @@ public interface FileItemStream extends FileItemHeadersSupport {
 
     /**
      * This exception is thrown, if an attempt is made to read data from the {@link InputStream}, which has been returned by
-     * {@link FileItemStream#openStream()}, after {@link java.util.Iterator#hasNext()} has been invoked on the iterator, which created the
+     * {@link FileItemStream#getInputStream()}, after {@link java.util.Iterator#hasNext()} has been invoked on the iterator, which created the
      * {@link FileItemStream}.
      */
     class ItemSkippedException extends IOException {
@@ -62,6 +62,16 @@ public interface FileItemStream extends FileItemHeadersSupport {
      */
     String getFieldName();
 
+    /**
+     * Opens an {@link InputStream}, which allows to read the items contents.
+     *
+     * @return The input stream, from which the items data may be read.
+     * @throws IllegalStateException The method was already invoked on this item. It is not possible to recreate the data stream.
+     * @throws IOException           An I/O error occurred.
+     * @see ItemSkippedException
+     */
+    InputStream getInputStream() throws IOException;
+
     /**
      * Gets the original file name in the client's file system, as provided by the browser (or other client software). In most cases, this will be the base file
      * name, without path information. However, some clients, such as the Opera browser, do include path information.
@@ -77,14 +87,4 @@ public interface FileItemStream extends FileItemHeadersSupport {
      */
     boolean isFormField();
 
-    /**
-     * Opens an {@link InputStream}, which allows to read the items contents.
-     *
-     * @return The input stream, from which the items data may be read.
-     * @throws IllegalStateException The method was already invoked on this item. It is not possible to recreate the data stream.
-     * @throws IOException           An I/O error occurred.
-     * @see ItemSkippedException
-     */
-    InputStream openStream() throws IOException;
-
 }
diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStreamImpl.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStreamImpl.java
index 4b7096c..0357d77 100644
--- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStreamImpl.java
+++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStreamImpl.java
@@ -152,6 +152,20 @@ class FileItemStreamImpl implements FileItemStream {
         return headers;
     }
 
+    /**
+     * Gets the input stream, which may be used to read the items contents.
+     *
+     * @return Opened input stream.
+     * @throws IOException An I/O error occurred.
+     */
+    @Override
+    public InputStream getInputStream() throws IOException {
+        if (inputStreamClosed) {
+            throw new FileItemStream.ItemSkippedException();
+        }
+        return inputStream;
+    }
+
     /**
      * Gets the file name.
      *
@@ -174,20 +188,6 @@ class FileItemStreamImpl implements FileItemStream {
         return formField;
     }
 
-    /**
-     * Gets the input stream, which may be used to read the items contents.
-     *
-     * @return Opened input stream.
-     * @throws IOException An I/O error occurred.
-     */
-    @Override
-    public InputStream openStream() throws IOException {
-        if (inputStreamClosed) {
-            throw new FileItemStream.ItemSkippedException();
-        }
-        return inputStream;
-    }
-
     /**
      * Sets the file item headers.
      *
diff --git a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractProgressListenerTest.java b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractProgressListenerTest.java
index 6931268..c66f470 100644
--- a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractProgressListenerTest.java
+++ b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractProgressListenerTest.java
@@ -76,7 +76,7 @@ public abstract class AbstractProgressListenerTest<F extends FileUpload<R>, R> e
         for (int i = 0; i < itemCount; i++) {
             final int idxI = i;
             final FileItemStream fileItemStream = iter.next();
-            try (final InputStream inputStream = fileItemStream.openStream()) {
+            try (final InputStream inputStream = fileItemStream.getInputStream()) {
                 for (int j = 0; j < 16_384 + i; j++) {
                     final int idxJ = j;
                     //
diff --git a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractSizesTest.java b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractSizesTest.java
index e6f7f80..995b4ab 100644
--- a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractSizesTest.java
+++ b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractSizesTest.java
@@ -219,7 +219,7 @@ public abstract class AbstractSizesTest<F extends FileUpload<R>, R> extends Abst
 
         {
             try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                    final InputStream stream = item.openStream()) {
+                    final InputStream stream = item.getInputStream()) {
                 IOUtils.copy(stream, baos);
             }
 
@@ -232,7 +232,7 @@ public abstract class AbstractSizesTest<F extends FileUpload<R>, R> extends Abst
         assertThrows(FileUploadException.class, () -> {
             final FileItemStream item2 = it.next();
             try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                    final InputStream stream = item2.openStream()) {
+                    final InputStream stream = item2.getInputStream()) {
                 IOUtils.copy(stream, baos);
             }
         });


[commons-fileupload] 03/03: ItemSkippedException now extends FileUploadException

Posted by gg...@apache.org.
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

commit b0bc5628e5532c08460f65655421388b1c47ad82
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jun 11 10:20:50 2023 -0400

    ItemSkippedException now extends FileUploadException
---
 .../java/org/apache/commons/fileupload2/FileItemStream.java   | 11 ++++++++++-
 .../java/org/apache/commons/fileupload2/MultipartStream.java  |  2 +-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStream.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStream.java
index a706099..9f460a9 100644
--- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStream.java
+++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStream.java
@@ -39,7 +39,16 @@ public interface FileItemStream extends FileItemHeadersSupport {
      * {@link FileItemStream#getInputStream()}, after {@link java.util.Iterator#hasNext()} has been invoked on the iterator, which created the
      * {@link FileItemStream}.
      */
-    class ItemSkippedException extends IOException {
+    class ItemSkippedException extends FileUploadException {
+
+        /**
+         * Constructs an instance with a given detail message.
+         *
+         * @param message The detail message (which is saved for later retrieval by the {@link #getMessage()} method)
+         */
+        ItemSkippedException(final String message) {
+            super(message);
+        }
 
         /**
          * The exceptions serial version UID, which is being used when serializing an exception instance.
diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/MultipartStream.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/MultipartStream.java
index c003d24..c25bea8 100644
--- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/MultipartStream.java
+++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/MultipartStream.java
@@ -231,7 +231,7 @@ public final class MultipartStream {
 
         private void checkOpen() throws ItemSkippedException {
             if (closed) {
-                throw new FileItemStream.ItemSkippedException();
+                throw new FileItemStream.ItemSkippedException("checkOpen");
             }
         }