james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mwiederk...@apache.org
Subject svn commit: r804989 - /james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/DecoderUtil.java
Date Mon, 17 Aug 2009 14:10:21 GMT
Author: mwiederkehr
Date: Mon Aug 17 14:10:21 2009
New Revision: 804989

URL: http://svn.apache.org/viewvc?rev=804989&view=rev
Log:
extracted method replaceUnderscores()

Modified:
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/DecoderUtil.java

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/DecoderUtil.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/DecoderUtil.java?rev=804989&r1=804988&r2=804989&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/DecoderUtil.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/codec/DecoderUtil.java Mon
Aug 17 14:10:21 2009
@@ -102,8 +102,8 @@
      */
     public static String decodeB(String encodedWord, String charset) 
             throws UnsupportedEncodingException {
-        
-        return new String(decodeBase64(encodedWord), charset);
+        byte[] decodedBytes = decodeBase64(encodedWord);
+        return new String(decodedBytes, charset);
     }
     
     /**
@@ -118,21 +118,10 @@
      */
     public static String decodeQ(String encodedWord, String charset)
             throws UnsupportedEncodingException {
-           
-        /*
-         * Replace _ with =20
-         */
-        StringBuilder sb = new StringBuilder(128);
-        for (int i = 0; i < encodedWord.length(); i++) {
-            char c = encodedWord.charAt(i);
-            if (c == '_') {
-                sb.append("=20");
-            } else {
-                sb.append(c);
-            }
-        }
+        encodedWord = replaceUnderscores(encodedWord);
         
-        return new String(decodeQuotedPrintable(sb.toString()), charset);
+        byte[] decodedBytes = decodeQuotedPrintable(encodedWord);
+        return new String(decodedBytes, charset);
     }
     
     /**
@@ -247,4 +236,22 @@
             return null;
         }
     }
+
+    // Replace _ with =20
+    private static String replaceUnderscores(String str) {
+        // probably faster than String#replace(CharSequence, CharSequence)
+
+        StringBuilder sb = new StringBuilder(128);
+
+        for (int i = 0; i < str.length(); i++) {
+            char c = str.charAt(i);
+            if (c == '_') {
+                sb.append("=20");
+            } else {
+                sb.append(c);
+            }
+        }
+        
+        return sb.toString();
+    }
 }



Mime
View raw message