commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1458210 - /commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/util/mime/MimeUtility.java
Date Tue, 19 Mar 2013 10:21:20 GMT
Author: simonetripodi
Date: Tue Mar 19 10:21:19 2013
New Revision: 1458210

URL: http://svn.apache.org/r1458210
Log:
extracted and documented constants that are used inside each algorithm iteration

Modified:
    commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/util/mime/MimeUtility.java

Modified: commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/util/mime/MimeUtility.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/util/mime/MimeUtility.java?rev=1458210&r1=1458209&r2=1458210&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/util/mime/MimeUtility.java
(original)
+++ commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/util/mime/MimeUtility.java
Tue Mar 19 10:21:19 2013
@@ -31,11 +31,31 @@ import java.util.Map;
 public final class MimeUtility {
 
     /**
+     * The {@code US-ASCII} charset identifier constant.
+     */
+    private static final String US_ASCII_CHARSET = "US-ASCII";
+
+    /**
+     * The marker to indicate text is encoded with BASE64 algorithm.
+     */
+    private static final String BASE64_ENCODING_MARKER = "B";
+
+    /**
+     * The marker to indicate text is encoded with QuotedPrintable algorithm.
+     */
+    private static final String QUOTEDPRINTABLE_ENCODING_MARKER = "Q";
+
+    /**
      * If the text contains any encoded tokens, those tokens will be marked with "=?".
      */
     private static final String ENCODED_TOKEN_MARKER = "=?";
 
     /**
+     * If the text contains any encoded tokens, those tokens will terminate with "=?".
+     */
+    private static final String ENCODED_TOKEN_FINISHER = "?=";
+
+    /**
      * The linear whitespace chars sequence.
      */
     private static final String LINEAR_WHITESPACE = " \t\r\n";
@@ -203,7 +223,7 @@ public final class MimeUtility {
         String encoding = word.substring(charsetPos + 1, encodingPos);
 
         // and finally the encoded text.
-        int encodedTextPos = word.indexOf("?=", encodingPos + 1);
+        int encodedTextPos = word.indexOf(ENCODED_TOKEN_FINISHER, encodingPos + 1);
         if (encodedTextPos == -1) {
             throw new ParseException("Missing encoded text in RFC 2047 encoded-word: " +
word);
         }
@@ -219,12 +239,12 @@ public final class MimeUtility {
             // the decoder writes directly to an output stream.
             ByteArrayOutputStream out = new ByteArrayOutputStream(encodedText.length());
 
-            byte[] encodedData = encodedText.getBytes("US-ASCII");
+            byte[] encodedData = encodedText.getBytes(US_ASCII_CHARSET);
 
             // Base64 encoded?
-            if (encoding.equals("B")) {
+            if (encoding.equals(BASE64_ENCODING_MARKER)) {
                 Base64Decoder.decode(encodedData, 0, encodedData.length, out);
-            } else if (encoding.equals("Q")) { // maybe quoted printable.
+            } else if (encoding.equals(QUOTEDPRINTABLE_ENCODING_MARKER)) { // maybe quoted
printable.
                 QuotedPrintableDecoder.decode(encodedData, 0, encodedData.length, out);
             } else {
                 throw new UnsupportedEncodingException("Unknown RFC 2047 encoding: " + encoding);



Mime
View raw message