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/10 13:30:24 UTC
[commons-fileupload] branch master updated: Reuse Java's ParseException intead of our own private custom ParseException
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
The following commit(s) were added to refs/heads/master by this push:
new 523bc55 Reuse Java's ParseException intead of our own private custom ParseException
523bc55 is described below
commit 523bc55541cde07ce8f0a53d179fae65be58c095
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 10 09:30:20 2023 -0400
Reuse Java's ParseException intead of our own private custom
ParseException
---
.../org/apache/commons/fileupload2/MimeUtils.java | 22 ++++++-------
.../apache/commons/fileupload2/ParseException.java | 37 ----------------------
2 files changed, 10 insertions(+), 49 deletions(-)
diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/MimeUtils.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/MimeUtils.java
index 33f9c61..460fbf7 100644
--- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/MimeUtils.java
+++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/MimeUtils.java
@@ -20,6 +20,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
+import java.text.ParseException;
import java.util.Base64;
import java.util.HashMap;
import java.util.Locale;
@@ -178,20 +179,21 @@ final class MimeUtils {
* @param word The possibly encoded word value.
*
* @return The decoded word.
- * @throws ParseException in case of a parse error of the RFC 2047
- * @throws UnsupportedEncodingException Thrown when Invalid RFC 2047 encoding was found
+ * @throws ParseException in case of a parse error of the RFC 2047.
+ * @throws UnsupportedEncodingException Thrown when Invalid RFC 2047 encoding was found.
*/
private static String decodeWord(final String word) throws ParseException, UnsupportedEncodingException {
// encoded words start with the characters "=?". If this not an encoded word, we throw a
// ParseException for the caller.
- if (!word.startsWith(ENCODED_TOKEN_MARKER)) {
- throw new ParseException("Invalid RFC 2047 encoded-word: " + word);
+ final int etmPos = word.indexOf(ENCODED_TOKEN_MARKER);
+ if (etmPos != 0) {
+ throw new ParseException("Invalid RFC 2047 encoded-word: " + word, etmPos);
}
final int charsetPos = word.indexOf('?', 2);
if (charsetPos == -1) {
- throw new ParseException("Missing charset in RFC 2047 encoded-word: " + word);
+ throw new ParseException("Missing charset in RFC 2047 encoded-word: " + word, charsetPos);
}
// pull out the character set information (this is the MIME name at this point).
@@ -200,7 +202,7 @@ final class MimeUtils {
// now pull out the encoding token the same way.
final int encodingPos = word.indexOf('?', charsetPos + 1);
if (encodingPos == -1) {
- throw new ParseException("Missing encoding in RFC 2047 encoded-word: " + word);
+ throw new ParseException("Missing encoding in RFC 2047 encoded-word: " + word, encodingPos);
}
final String encoding = word.substring(charsetPos + 1, encodingPos);
@@ -208,7 +210,7 @@ final class MimeUtils {
// and finally the encoded text.
final int encodedTextPos = word.indexOf(ENCODED_TOKEN_FINISHER, encodingPos + 1);
if (encodedTextPos == -1) {
- throw new ParseException("Missing encoded text in RFC 2047 encoded-word: " + word);
+ throw new ParseException("Missing encoded text in RFC 2047 encoded-word: " + word, encodedTextPos);
}
final String encodedText = word.substring(encodingPos + 1, encodedTextPos);
@@ -252,14 +254,10 @@ final class MimeUtils {
if (charset == null) {
return null;
}
-
final String mappedCharset = MIME2JAVA.get(charset.toLowerCase(Locale.ENGLISH));
// if there is no mapping, then the original name is used. Many of the MIME character set
// names map directly back into Java. The reverse isn't necessarily true.
- if (mappedCharset == null) {
- return charset;
- }
- return mappedCharset;
+ return mappedCharset == null ? charset : mappedCharset;
}
/**
diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/ParseException.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/ParseException.java
deleted file mode 100644
index cd2b574..0000000
--- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/ParseException.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.fileupload2;
-
-/**
- */
-final class ParseException extends Exception {
-
- /**
- * The UID to use when serializing this instance.
- */
- private static final long serialVersionUID = 2;
-
- /**
- * Constructs a new exception with the specified detail message.
- *
- * @param message the detail message.
- */
- ParseException(final String message) {
- super(message);
- }
-
-}