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/04/07 23:17:05 UTC

[commons-fileupload] 02/02: Don't import String.format() statically

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 0b4516e1fa7f52831a4cfd6aa62b3c583afe5609
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Apr 7 19:17:02 2023 -0400

    Don't import String.format() statically
---
 .../java/org/apache/commons/fileupload2/AbstractFileUpload.java  | 3 +--
 .../java/org/apache/commons/fileupload2/MultipartStream.java     | 4 ++--
 .../java/org/apache/commons/fileupload2/disk/DiskFileItem.java   | 8 +++-----
 .../apache/commons/fileupload2/impl/FileItemIteratorImpl.java    | 9 ++++-----
 .../org/apache/commons/fileupload2/impl/FileItemStreamImpl.java  | 9 ++++-----
 5 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/src/main/java/org/apache/commons/fileupload2/AbstractFileUpload.java b/src/main/java/org/apache/commons/fileupload2/AbstractFileUpload.java
index 46bc68e..4340bae 100644
--- a/src/main/java/org/apache/commons/fileupload2/AbstractFileUpload.java
+++ b/src/main/java/org/apache/commons/fileupload2/AbstractFileUpload.java
@@ -16,7 +16,6 @@
  */
 package org.apache.commons.fileupload2;
 
-import static java.lang.String.format;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -471,7 +470,7 @@ public abstract class AbstractFileUpload {
                 } catch (final FileUploadException e) {
                     throw e;
                 } catch (final IOException e) {
-                    throw new FileUploadException(format("Processing of %s request failed. %s", MULTIPART_FORM_DATA, e.getMessage()), e);
+                    throw new FileUploadException(String.format("Processing of %s request failed. %s", MULTIPART_FORM_DATA, e.getMessage()), e);
                 }
                 fileItem.setHeaders(item.getHeaders());
             }
diff --git a/src/main/java/org/apache/commons/fileupload2/MultipartStream.java b/src/main/java/org/apache/commons/fileupload2/MultipartStream.java
index a9b56af..9d9613a 100644
--- a/src/main/java/org/apache/commons/fileupload2/MultipartStream.java
+++ b/src/main/java/org/apache/commons/fileupload2/MultipartStream.java
@@ -16,7 +16,6 @@
  */
 package org.apache.commons.fileupload2;
 
-import static java.lang.String.format;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -819,7 +818,8 @@ public class MultipartStream {
                 throw new MalformedStreamException("Stream ended unexpectedly", e);
             }
             if (++size > HEADER_PART_SIZE_MAX) {
-                throw new MalformedStreamException(format("Header section has more than %s bytes (maybe it is not properly terminated)", HEADER_PART_SIZE_MAX));
+                throw new MalformedStreamException(
+                        String.format("Header section has more than %s bytes (maybe it is not properly terminated)", HEADER_PART_SIZE_MAX));
             }
             if (b == HEADER_SEPARATOR[i]) {
                 i++;
diff --git a/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java b/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
index ad35d39..9974e02 100644
--- a/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
+++ b/src/main/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
@@ -16,7 +16,6 @@
  */
 package org.apache.commons.fileupload2.disk;
 
-import static java.lang.String.format;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -454,7 +453,7 @@ public class DiskFileItem implements FileItem {
             if (tempDir == null) {
                 tempDir = FileUtils.getTempDirectory();
             }
-            final String tempFileName = format("upload_%s_%s.tmp", UID, getUniqueId());
+            final String tempFileName = String.format("upload_%s_%s.tmp", UID, getUniqueId());
             tempFile = new File(tempDir, tempFileName);
         }
         return tempFile;
@@ -539,9 +538,8 @@ public class DiskFileItem implements FileItem {
      */
     @Override
     public String toString() {
-        return format("name=%s, StoreLocation=%s, size=%s bytes, isFormField=%s, FieldName=%s",
-                      getName(), getStoreLocation(), getSize(),
-                isFormField(), getFieldName());
+        return String.format("name=%s, StoreLocation=%s, size=%s bytes, isFormField=%s, FieldName=%s", getName(), getStoreLocation(), getSize(), isFormField(),
+                getFieldName());
     }
 
     /**
diff --git a/src/main/java/org/apache/commons/fileupload2/impl/FileItemIteratorImpl.java b/src/main/java/org/apache/commons/fileupload2/impl/FileItemIteratorImpl.java
index c68300e..6aff516 100644
--- a/src/main/java/org/apache/commons/fileupload2/impl/FileItemIteratorImpl.java
+++ b/src/main/java/org/apache/commons/fileupload2/impl/FileItemIteratorImpl.java
@@ -16,7 +16,6 @@
  */
 package org.apache.commons.fileupload2.impl;
 
-import static java.lang.String.format;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -252,7 +251,7 @@ public class FileItemIteratorImpl implements FileItemIterator {
     protected void init(final AbstractFileUpload fileUploadBase, final RequestContext requestContext) throws FileUploadException, IOException {
         final String contentType = ctx.getContentType();
         if ((null == contentType) || (!contentType.toLowerCase(Locale.ENGLISH).startsWith(AbstractFileUpload.MULTIPART))) {
-            throw new FileUploadContentTypeException(format("the request doesn't contain a %s or %s stream, content type header is %s",
+            throw new FileUploadContentTypeException(String.format("the request doesn't contain a %s or %s stream, content type header is %s",
                     AbstractFileUpload.MULTIPART_FORM_DATA, AbstractFileUpload.MULTIPART_MIXED, contentType), contentType);
         }
         final long contentLengthInt = ctx.getContentLength();
@@ -267,7 +266,7 @@ public class FileItemIteratorImpl implements FileItemIterator {
         if (sizeMax >= 0) {
             if (requestSize != -1 && requestSize > sizeMax) {
                 throw new FileUploadSizeException(
-                        format("the request was rejected because its size (%s) exceeds the configured maximum (%s)", requestSize, sizeMax), sizeMax,
+                        String.format("the request was rejected because its size (%s) exceeds the configured maximum (%s)", requestSize, sizeMax), sizeMax,
                         requestSize);
             }
             // N.B. this is eventually closed in MultipartStream processing
@@ -275,7 +274,7 @@ public class FileItemIteratorImpl implements FileItemIterator {
                 @Override
                 protected void raiseError(final long maxLen, final long count) throws IOException {
                     throw new FileUploadSizeException(
-                            format("The request was rejected because its size (%s) exceeds the configured maximum (%s)", count, maxLen), maxLen, count);
+                            String.format("The request was rejected because its size (%s) exceeds the configured maximum (%s)", count, maxLen), maxLen, count);
                 }
             };
         } else {
@@ -298,7 +297,7 @@ public class FileItemIteratorImpl implements FileItemIterator {
             multiPartStream = new MultipartStream(input, multiPartBoundary, progressNotifier);
         } catch (final IllegalArgumentException e) {
             IOUtils.closeQuietly(input); // avoid possible resource leak
-            throw new FileUploadContentTypeException(format("The boundary specified in the %s header is too long", AbstractFileUpload.CONTENT_TYPE), e);
+            throw new FileUploadContentTypeException(String.format("The boundary specified in the %s header is too long", AbstractFileUpload.CONTENT_TYPE), e);
         }
         multiPartStream.setHeaderEncoding(charEncoding);
     }
diff --git a/src/main/java/org/apache/commons/fileupload2/impl/FileItemStreamImpl.java b/src/main/java/org/apache/commons/fileupload2/impl/FileItemStreamImpl.java
index c389960..e89bc01 100644
--- a/src/main/java/org/apache/commons/fileupload2/impl/FileItemStreamImpl.java
+++ b/src/main/java/org/apache/commons/fileupload2/impl/FileItemStreamImpl.java
@@ -16,7 +16,6 @@
  */
 package org.apache.commons.fileupload2.impl;
 
-import static java.lang.String.format;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -98,9 +97,8 @@ public class FileItemStreamImpl implements FileItemStream {
         this.formField = formField;
         final long fileSizeMax = fileItemIteratorImpl.getFileSizeMax();
         if (fileSizeMax != -1 && contentLength != -1 && contentLength > fileSizeMax) {
-            throw new FileUploadByteCountLimitException(
-                    format("The field %s exceeds its maximum permitted size of %s bytes.", fieldName, fileSizeMax), contentLength, fileSizeMax, fileName,
-                    fieldName);
+            throw new FileUploadByteCountLimitException(String.format("The field %s exceeds its maximum permitted size of %s bytes.", fieldName, fileSizeMax),
+                    contentLength, fileSizeMax, fileName, fieldName);
         }
         // OK to construct stream now
         final ItemInputStream itemInputStream = fileItemIteratorImpl.getMultiPartStream().newInputStream();
@@ -111,7 +109,8 @@ public class FileItemStreamImpl implements FileItemStream {
                 protected void raiseError(final long sizeMax, final long count) throws IOException {
                     itemInputStream.close(true);
                     throw new FileUploadByteCountLimitException(
-                            format("The field %s exceeds its maximum permitted size of %s bytes.", fieldName, sizeMax), count, sizeMax, fileName, fieldName);
+                            String.format("The field %s exceeds its maximum permitted size of %s bytes.", fieldName, sizeMax), count, sizeMax, fileName,
+                            fieldName);
                 }
             };
         }