This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch release-1.x in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git
commit 4ea8459865cf659225f1d8771aabd5f557661400 Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Thu Jun 5 11:15:58 2025 -0400 Reduce public API surface The new class RFC2231Utility doesn't need to be public, it's only used from ParameterParser. --- .../apache/commons/fileupload/ParameterParser.java | 1 - .../fileupload/{util/mime => }/RFC2231Utility.java | 52 +++++++++++----------- .../{util/mime => }/RFC2231UtilityTestCase.java | 5 ++- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/apache/commons/fileupload/ParameterParser.java b/src/main/java/org/apache/commons/fileupload/ParameterParser.java index 4bd8dabd..f44eb3f6 100644 --- a/src/main/java/org/apache/commons/fileupload/ParameterParser.java +++ b/src/main/java/org/apache/commons/fileupload/ParameterParser.java @@ -22,7 +22,6 @@ import java.util.Locale; import java.util.Map; import org.apache.commons.fileupload.util.mime.MimeUtility; -import org.apache.commons.fileupload.util.mime.RFC2231Utility; /** * A simple parser intended to parse sequences of name/value pairs. diff --git a/src/main/java/org/apache/commons/fileupload/util/mime/RFC2231Utility.java b/src/main/java/org/apache/commons/fileupload/RFC2231Utility.java similarity index 78% rename from src/main/java/org/apache/commons/fileupload/util/mime/RFC2231Utility.java rename to src/main/java/org/apache/commons/fileupload/RFC2231Utility.java index 11879f13..ce4b5188 100644 --- a/src/main/java/org/apache/commons/fileupload/util/mime/RFC2231Utility.java +++ b/src/main/java/org/apache/commons/fileupload/RFC2231Utility.java @@ -14,28 +14,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.commons.fileupload.util.mime; + +package org.apache.commons.fileupload; import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; + /** - * Utility class to decode/encode character set on HTTP Header fields based on RFC 2231. - * This implementation adheres to RFC 5987 in particular, which was defined for HTTP headers. + * Utility class to decode/encode character set on HTTP Header fields based on RFC 2231. This implementation adheres to RFC 5987 in particular, which was + * defined for HTTP headers. * <p> - * RFC 5987 builds on RFC 2231, but has lesser scope like - * <a href="https://tools.ietf.org/html/rfc5987#section-3.2">mandatory charset definition</a> - * and <a href="https://tools.ietf.org/html/rfc5987#section-4">no parameter continuation</a> + * RFC 5987 builds on RFC 2231, but has lesser scope like <a href="https://tools.ietf.org/html/rfc5987#section-3.2">mandatory charset definition</a> and + * <a href="https://tools.ietf.org/html/rfc5987#section-4">no parameter continuation</a> + * </p> * * @see <a href="https://tools.ietf.org/html/rfc2231">RFC 2231</a> * @see <a href="https://tools.ietf.org/html/rfc5987">RFC 5987</a> */ -public final class RFC2231Utility { +final class RFC2231Utility { /** * Percent character '{@value}'. */ private static final char PERCENT = '%'; - /** * The Hexadecimal values char array. */ @@ -52,7 +53,6 @@ public final class RFC2231Utility { * The Hexadecimal decode value. */ private static final byte[] HEX_DECODE = new byte[MASK_128]; - // create a ASCII decoded array of Hexadecimal values static { for (int i = 0; i < HEX_DIGITS.length; i++) { @@ -62,23 +62,22 @@ public final class RFC2231Utility { } /** - * Decode a string of text obtained from a HTTP header as per RFC 2231 + * Decodes a string of text obtained from a HTTP header as per RFC 2231 * <p> - * <strong>Eg 1.</strong> {@code us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A} - * will be decoded to {@code This is ***fun***} + * <strong>Eg 1.</strong> {@code us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A} will be decoded to {@code This is ***fun***} + * </p> * <p> - * <strong>Eg 2.</strong> {@code iso-8859-1'en'%A3%20rate} - * will be decoded to {@code £ rate} + * <strong>Eg 2.</strong> {@code iso-8859-1'en'%A3%20rate} will be decoded to {@code £ rate} + * </p> * <p> - * <strong>Eg 3.</strong> {@code UTF-8''%c2%a3%20and%20%e2%82%ac%20rates} - * will be decoded to {@code £ and € rates} + * <strong>Eg 3.</strong> {@code UTF-8''%c2%a3%20and%20%e2%82%ac%20rates} will be decoded to {@code £ and € rates} + * </p> * - * @param encodedText Text to be decoded has a format of {@code <charset>'<language>'<encoded_value>} - * and ASCII only + * @param encodedText Text to be decoded has a format of {@code <charset>'<language>'<encoded_value>} and ASCII only * @return Decoded text based on charset encoding * @throws UnsupportedEncodingException The requested character set wasn't found. */ - public static String decodeText(final String encodedText) throws UnsupportedEncodingException { + static String decodeText(final String encodedText) throws UnsupportedEncodingException { final int langDelimitStart = encodedText.indexOf('\''); if (langDelimitStart == -1) { // missing charset @@ -125,12 +124,12 @@ public final class RFC2231Utility { } /** - * Checks if Asterisk (*) at the end of parameter name to indicate, - * if it has charset and language information to decode the value. + * Checks if Asterisk (*) at the end of parameter name to indicate, if it has charset and language information to decode the value. + * * @param paramName The parameter, which is being checked. * @return {@code true}, if encoded as per RFC 2231, {@code false} otherwise */ - public static boolean hasEncodedValue(final String paramName) { + static boolean hasEncodedValue(final String paramName) { if (paramName != null) { return paramName.lastIndexOf('*') == paramName.length() - 1; } @@ -138,12 +137,12 @@ public final class RFC2231Utility { } /** - * If {@code paramName} has Asterisk (*) at the end, it will be stripped off, - * else the passed value will be returned. + * If {@code paramName} has Asterisk (*) at the end, it will be stripped off, else the passed value will be returned. + * * @param paramName The parameter, which is being inspected. * @return stripped {@code paramName} of Asterisk (*), if RFC2231 encoded */ - public static String stripDelimiter(final String paramName) { + static String stripDelimiter(final String paramName) { if (hasEncodedValue(paramName)) { final StringBuilder paramBuilder = new StringBuilder(paramName); paramBuilder.deleteCharAt(paramName.lastIndexOf('*')); @@ -153,8 +152,7 @@ public final class RFC2231Utility { } /** - * Private constructor so that no instances can be created. This class - * contains only static utility methods. + * Private constructor so that no instances can be created. This class contains only static utility methods. */ private RFC2231Utility() { } diff --git a/src/test/java/org/apache/commons/fileupload/util/mime/RFC2231UtilityTestCase.java b/src/test/java/org/apache/commons/fileupload/RFC2231UtilityTestCase.java similarity index 96% rename from src/test/java/org/apache/commons/fileupload/util/mime/RFC2231UtilityTestCase.java rename to src/test/java/org/apache/commons/fileupload/RFC2231UtilityTestCase.java index c31ebd1c..c575433b 100644 --- a/src/test/java/org/apache/commons/fileupload/util/mime/RFC2231UtilityTestCase.java +++ b/src/test/java/org/apache/commons/fileupload/RFC2231UtilityTestCase.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.commons.fileupload.util.mime; +package org.apache.commons.fileupload; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -22,9 +22,12 @@ import static org.junit.Assert.assertTrue; import java.io.UnsupportedEncodingException; +import org.apache.commons.fileupload.RFC2231Utility; import org.junit.Test; /** + * Tests {@link RFC2231Utility}. + * * The expected characters are encoded in UTF16, while the actual characters may be encoded in UTF-8/ISO-8859-1 * * RFC 5987 recommends to support both UTF-8 & ISO 8859-1. Test values are taken from https://tools.ietf.org/html/rfc5987#section-3.2.2