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 <garydgreg...@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; }