< prev index next >

src/java.xml.ws/share/classes/com/sun/xml/internal/messaging/saaj/packaging/mime/internet/MimeUtility.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -508,12 +508,12 @@
             return etext;
 
         // Encoded words found. Start decoding ...
 
         st = new StringTokenizer(etext, lwsp, true);
-        StringBuffer sb = new StringBuffer();  // decode buffer
-        StringBuffer wsb = new StringBuffer(); // white space buffer
+        StringBuilder sb = new StringBuilder();  // decode buffer
+        StringBuilder wsb = new StringBuilder(); // white space buffer
         boolean prevWasEncoded = false;
 
         while (st.hasMoreTokens()) {
             char c;
             String s = st.nextToken();

@@ -646,11 +646,11 @@
             b64 = false;
         else
             throw new UnsupportedEncodingException(
                         "Unknown transfer encoding: " + encoding);
 
-        StringBuffer outb = new StringBuffer(); // the output buffer
+        StringBuilder outb = new StringBuilder(); // the output buffer
         doEncode(string, b64, jcharset,
                  // As per RFC 2047, size of an encoded string should not
                  // exceed 75 bytes.
                  // 7 = size of "=?", '?', 'B'/'Q', '?', "?="
                  75 - 7 - charset.length(), // the available space

@@ -660,11 +660,11 @@
         return outb.toString();
     }
 
     private static void doEncode(String string, boolean b64,
                 String jcharset, int avail, String prefix,
-                boolean first, boolean encodingWord, StringBuffer buf)
+                boolean first, boolean encodingWord, StringBuilder buf)
                         throws UnsupportedEncodingException {
 
         // First find out what the length of the encoded version of
         // 'string' would be.
         byte[] bytes = string.getBytes(jcharset);

@@ -810,11 +810,11 @@
      * produce such incorrect encodings.
      */
     private static String decodeInnerWords(String word)
                                 throws UnsupportedEncodingException {
         int start = 0, i;
-        StringBuffer buf = new StringBuffer();
+        StringBuilder buf = new StringBuilder();
         while ((i = word.indexOf("=?", start)) >= 0) {
             buf.append(word.substring(start, i));
             int end = word.indexOf("?=", i);
             if (end < 0)
                 break;

@@ -860,11 +860,11 @@
         boolean needQuoting = false;
         for (int i = 0; i < len; i++) {
             char c = word.charAt(i);
             if (c == '"' || c == '\\' || c == '\r' || c == '\n') {
                 // need to escape them and then quote the whole string
-                StringBuffer sb = new StringBuffer(len + 3);
+                StringBuilder sb = new StringBuilder(len + 3);
                 sb.append('"');
                 sb.append(word.substring(0, i));
                 int lastc = 0;
                 for (int j = i; j < len; j++) {
                     char cc = word.charAt(j);

@@ -883,11 +883,11 @@
                 // These characters cause the string to be quoted
                 needQuoting = true;
         }
 
         if (needQuoting) {
-            StringBuffer sb = new StringBuffer(len + 2);
+            StringBuilder sb = new StringBuilder(len + 2);
             sb.append('"').append(word).append('"');
             return sb.toString();
         } else
             return word;
     }

@@ -925,11 +925,11 @@
         // if the string fits now, just return it
         if (used + s.length() <= 76)
             return s;
 
         // have to actually fold the string
-        StringBuffer sb = new StringBuffer(s.length() + 4);
+        StringBuilder sb = new StringBuilder(s.length() + 4);
         char lastc = 0;
         while (used + s.length() > 76) {
             int lastspace = -1;
             for (int i = 0; i < s.length(); i++) {
                 if (lastspace != -1 && used + i > 76)

@@ -967,11 +967,11 @@
      */
     /*public*/ static String unfold(String s) {
         if (!foldText)
             return s;
 
-        StringBuffer sb = null;
+        StringBuilder sb = null;
         int i;
         while ((i = indexOfAny(s, "\r\n")) >= 0) {
             int start = i;
             int l = s.length();
             i++;                // skip CR or NL

@@ -984,28 +984,28 @@
                 if (i < l && ((c = s.charAt(i)) == ' ' || c == '\t')) {
                     i++;        // skip whitespace
                     while (i < l && ((c = s.charAt(i)) == ' ' || c == '\t'))
                         i++;
                     if (sb == null)
-                        sb = new StringBuffer(s.length());
+                        sb = new StringBuilder(s.length());
                     if (start != 0) {
                         sb.append(s.substring(0, start));
                         sb.append(' ');
                     }
                     s = s.substring(i);
                     continue;
                 }
                 // it's not a continuation line, just leave it in
                 if (sb == null)
-                    sb = new StringBuffer(s.length());
+                    sb = new StringBuilder(s.length());
                 sb.append(s.substring(0, i));
                 s = s.substring(i);
             } else {
                 // there's a backslash at "start - 1"
                 // strip it out, but leave in the line break
                 if (sb == null)
-                    sb = new StringBuffer(s.length());
+                    sb = new StringBuilder(s.length());
                 sb.append(s.substring(0, start - 1));
                 sb.append(s.substring(start, i));
                 s = s.substring(i);
             }
         }

@@ -1049,11 +1049,11 @@
     public static String javaCharset(String charset) {
         if (mime2java == null || charset == null)
             // no mapping table, or charset parameter is null
             return charset;
 
-        String alias = (String)mime2java.get(charset.toLowerCase());
+        String alias = mime2java.get(charset.toLowerCase());
         return alias == null ? charset : alias;
     }
 
     /**
      * Convert a java charset into its MIME charset name. <p>

@@ -1071,11 +1071,11 @@
     public static String mimeCharset(String charset) {
         if (java2mime == null || charset == null)
             // no mapping table or charset param is null
             return charset;
 
-        String alias = (String)java2mime.get(charset.toLowerCase());
+        String alias = java2mime.get(charset.toLowerCase());
         return alias == null ? charset : alias;
     }
 
     private static String defaultJavaCharset;
     private static String defaultMIMECharset;

@@ -1138,16 +1138,16 @@
         return defaultMIMECharset;
     }
 
     // Tables to map MIME charset names to Java names and vice versa.
     // XXX - Should eventually use J2SE 1.4 java.nio.charset.Charset
-    private static Hashtable mime2java;
-    private static Hashtable java2mime;
+    private static Hashtable<String, String> mime2java;
+    private static Hashtable<String, String> java2mime;
 
     static {
-        java2mime = new Hashtable(40);
-        mime2java = new Hashtable(10);
+        java2mime = new Hashtable<String, String>(40);
+        mime2java = new Hashtable<String, String>(10);
 
         try {
             // Use this class's classloader to load the mapping file
             // XXX - we should use SecuritySupport, but it's in another package
             InputStream is =

@@ -1227,11 +1227,11 @@
             mime2java.put("us-ascii", "ISO-8859-1");
             mime2java.put("x-us-ascii", "ISO-8859-1");
         }
     }
 
-    private static void loadMappings(LineInputStream is, Hashtable table) {
+    private static void loadMappings(LineInputStream is, Hashtable<String, String> table) {
         String currLine;
 
         while (true) {
             try {
                 currLine = is.readLine();
< prev index next >