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/14 12:40:10 UTC

[commons-fileupload] branch master updated (e6e31e5 -> 9b260e5)

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 e6e31e5  Fix POM
     new 1afd758  Remove FileItemInputIterator.getFileItems():
     new 3705bb1  Catch no longer needed
     new 9b260e5  Use Charset

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:
 .../org/apache/commons/fileupload2/FileItem.java     |  7 +++----
 .../commons/fileupload2/FileItemInputIterator.java   |  3 ---
 .../fileupload2/FileItemInputIteratorImpl.java       | 20 --------------------
 .../commons/fileupload2/disk/DiskFileItem.java       | 19 +++++--------------
 4 files changed, 8 insertions(+), 41 deletions(-)


[commons-fileupload] 02/03: Catch no longer needed

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 3705bb102c238c2d3ff747cefdea15645d4f4626
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jun 13 08:20:58 2023 -0400

    Catch no longer needed
---
 .../java/org/apache/commons/fileupload2/disk/DiskFileItem.java     | 7 +------
 1 file changed, 1 insertion(+), 6 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 baa968b..de01372 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
@@ -24,7 +24,6 @@ import java.io.UncheckedIOException;
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
-import java.nio.charset.UnsupportedCharsetException;
 import java.nio.file.CopyOption;
 import java.nio.file.Files;
 import java.nio.file.InvalidPathException;
@@ -459,11 +458,7 @@ public final class DiskFileItem implements FileItem {
      */
     @Override
     public String getString() {
-        try {
-            return new String(get(), getCharset());
-        } catch (final UnsupportedCharsetException e) {
-            return "";
-        }
+        return new String(get(), getCharset());
     }
 
     /**


[commons-fileupload] 03/03: Use Charset

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 9b260e54f17d0fe290ded84628788f6c72ff6519
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Jun 14 08:40:05 2023 -0400

    Use Charset
---
 .../main/java/org/apache/commons/fileupload2/FileItem.java   |  7 +++----
 .../org/apache/commons/fileupload2/disk/DiskFileItem.java    | 12 ++++--------
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItem.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItem.java
index 414a02d..a6f6c95 100644
--- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItem.java
+++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItem.java
@@ -20,7 +20,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.UncheckedIOException;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
 import java.nio.file.InvalidPathException;
 import java.nio.file.Path;
 
@@ -118,14 +118,13 @@ public interface FileItem extends FileItemHeadersProvider {
     /**
      * Gets the contents of the file item as a String, using the specified encoding. This method uses {@link #get()} to retrieve the contents of the item.
      *
-     * @param encoding The character encoding to use.
+     * @param toCharset The character encoding to use.
      *
      * @return The contents of the item, as a string.
      *
-     * @throws UnsupportedEncodingException if the requested character encoding is not available.
      * @throws IOException                  if an I/O error occurs
      */
-    String getString(String encoding) throws UnsupportedEncodingException, IOException;
+    String getString(Charset toCharset) throws IOException;
 
     /**
      * Tests whether or not a {@code FileItem} instance represents a simple form field.
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 de01372..df8e688 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
@@ -21,7 +21,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.UncheckedIOException;
-import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.CopyOption;
@@ -243,7 +242,7 @@ public final class DiskFileItem implements FileItem {
     /**
      * The temporary file to use.
      */
-    private Path tempFile;
+    private final Path tempFile;
 
     /**
      * The file items headers.
@@ -277,6 +276,7 @@ public final class DiskFileItem implements FileItem {
         this.fileItemHeaders = fileItemHeaders;
         this.threshold = threshold;
         this.repository = repository != null ? repository : PathUtils.getTempDirectory();
+        this.tempFile = this.repository.resolve(String.format("upload_%s_%s.tmp", UID, getUniqueId()));
     }
 
     /**
@@ -466,11 +466,10 @@ public final class DiskFileItem implements FileItem {
      *
      * @param charset The charset to use.
      * @return The contents of the file, as a string.
-     * @throws UnsupportedEncodingException if the requested character encoding is not available.
      */
     @Override
-    public String getString(final String charset) throws UnsupportedEncodingException, IOException {
-        return new String(get(), charset);
+    public String getString(final Charset charset) throws IOException {
+        return new String(get(), Charsets.toCharset(charset, charsetDefault));
     }
 
     /**
@@ -483,9 +482,6 @@ public final class DiskFileItem implements FileItem {
      * @return The {@link java.io.File File} to be used for temporary storage.
      */
     protected Path getTempFile() {
-        if (tempFile == null) {
-            tempFile = repository.resolve(String.format("upload_%s_%s.tmp", UID, getUniqueId()));
-        }
         return tempFile;
     }
 


[commons-fileupload] 01/03: Remove FileItemInputIterator.getFileItems():

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 1afd75887889db97d0c342c0ae1c481a37faf75e
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jun 13 08:19:42 2023 -0400

    Remove FileItemInputIterator.getFileItems():
    
    - Redundant with AbstractFileUpload.parseRequest(RequestContext)
    - It is broken (does not read contents)
    - Never tested (trying to add new tests revealed the above)
---
 .../commons/fileupload2/FileItemInputIterator.java   |  3 ---
 .../fileupload2/FileItemInputIteratorImpl.java       | 20 --------------------
 2 files changed, 23 deletions(-)

diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemInputIterator.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemInputIterator.java
index 34d4e73..76497d1 100644
--- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemInputIterator.java
+++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemInputIterator.java
@@ -17,7 +17,6 @@
 package org.apache.commons.fileupload2;
 
 import java.io.IOException;
-import java.util.List;
 
 import javax.naming.SizeLimitExceededException;
 
@@ -28,8 +27,6 @@ import org.apache.commons.io.function.IOIterator;
  */
 public interface FileItemInputIterator extends IOIterator<FileItemInput> {
 
-    List<FileItem> getFileItems() throws FileUploadException, IOException;
-
     /**
      * Gets the maximum size of a single file. An {@link FileUploadByteCountLimitException} will be thrown, if there is an uploaded file, which is exceeding
      * this value. By default, this value will be copied from the {@link AbstractFileUpload#getFileSizeMax() FileUploadBase} object, however, the user may
diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemInputIteratorImpl.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemInputIteratorImpl.java
index e58671b..213067c 100644
--- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemInputIteratorImpl.java
+++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemInputIteratorImpl.java
@@ -19,9 +19,7 @@ package org.apache.commons.fileupload2;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.Charset;
-import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Locale;
 import java.util.NoSuchElementException;
 import java.util.Objects;
@@ -194,24 +192,6 @@ class FileItemInputIteratorImpl implements FileItemInputIterator {
         }
     }
 
-    @Override
-    public List<FileItem> getFileItems() throws FileUploadException, IOException {
-        final List<FileItem> items = new ArrayList<>();
-        while (hasNext()) {
-            final FileItemInput fis = next();
-            // @formatter:off
-            final FileItem fileItem = fileUpload.getFileItemFactory().fileItemBuilder()
-                    .setFieldName(fis.getFieldName())
-                    .setContentType(fis.getContentType())
-                    .setFormField(fis.isFormField())
-                    .setFileName(fis.getName())
-                    .get();
-            // @formatter:on
-            items.add(fileItem);
-        }
-        return items;
-    }
-
     @Override
     public long getFileSizeMax() {
         return fileSizeMax;