< prev index next >

jaxws/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, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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

@@ -63,15 +63,15 @@
  * yet a widely used charset, one might want to first charset-encode
  * the String into another charset and then do the transfer-encoding.
  * <p>
  * Note that to get the actual bytes of a mail-safe String (say,
  * for sending over SMTP), one must do
- * <p><blockquote><pre>
+ * <blockquote><pre>
  *
  *      byte[] bytes = string.getBytes("iso-8859-1");
  *
- * </pre></blockquote><p>
+ * </pre></blockquote>
  *
  * The <code>setHeader</code> and <code>addHeader</code> methods
  * on MimeMessage and MimeBodyPart assume that the given header values
  * are Unicode strings that contain only US-ASCII characters. Hence
  * the callers of those methods must insure that the values they pass

@@ -220,10 +220,14 @@
      * "text/plain" String) because all the I/O is done in this
      * thread.  In the case requiring an <code>InputStream</code> the
      * <code>DataHandler</code> uses a thread, a pair of pipe streams,
      * and the <code>writeTo</code> method to produce the data. <p>
      *
+     * @param dh data handler
+     *
+     * @return encoding
+     *
      * @since   JavaMail 1.2
      */
     public static String getEncoding(DataHandler dh) {
         ContentType cType = null;
         String encoding = null;

@@ -292,10 +296,11 @@
      * supported.
      *
      * @param   is              input stream
      * @param   encoding        the encoding of the stream.
      * @return                  decoded input stream.
+     * @exception MessagingException in case of error
      */
     public static InputStream decode(InputStream is, String encoding)
                 throws MessagingException {
         if (encoding.equalsIgnoreCase("base64"))
             return new BASE64DecoderStream(is);

@@ -321,10 +326,11 @@
      *
      * @param   os              output stream
      * @param   encoding        the encoding of the stream.
      * @return                  output stream that applies the
      *                          specified encoding.
+     * @exception MessagingException in case of error
      */
     public static OutputStream encode(OutputStream os, String encoding)
                 throws MessagingException {
         if (encoding == null)
             return os;

@@ -356,10 +362,11 @@
      * @param   encoding        the encoding of the stream.
      * @param   filename        name for the file being encoded (only used
      *                          with uuencode)
      * @return                  output stream that applies the
      *                          specified encoding.
+     * @exception MessagingException in case of error
      * @since                   JavaMail 1.2
      */
     public static OutputStream encode(OutputStream os, String encoding,
                                       String filename)
                 throws MessagingException {

@@ -395,11 +402,11 @@
      *
      * Note that this method should be used to encode only
      * "unstructured" RFC 822 headers. <p>
      *
      * Example of usage:
-     * <p><blockquote><pre>
+     * <blockquote><pre>
      *
      *  MimeBodyPart part = ...
      *  String rawvalue = "FooBar Mailer, Japanese version 1.1"
      *  try {
      *    // If we know for sure that rawvalue contains only US-ASCII

@@ -409,11 +416,11 @@
      *    // encoding failure
      *  } catch (MessagingException me) {
      *   // setHeader() failure
      *  }
      *
-     * </pre></blockquote><p>
+     * </pre></blockquote>
      *
      * @param   text    unicode string
      * @return  Unicode string containing only US-ASCII characters
      * @exception UnsupportedEncodingException if the encoding fails
      */

@@ -444,10 +451,11 @@
      *          values are "B" and "Q". If this parameter is null, then
      *          the "Q" encoding is used if most of characters to be
      *          encoded are in the ASCII charset, otherwise "B" encoding
      *          is used.
      * @return  Unicode string containing only US-ASCII characters
+     * @exception UnsupportedEncodingException in case of unsupported encoding
      */
     public static String encodeText(String text, String charset,
                                     String encoding)
                         throws UnsupportedEncodingException {
         return encodeWord(text, charset, encoding, false);

@@ -462,11 +470,11 @@
      * for any sequence, an UnsupportedEncodingException is thrown.
      * If the String is not an RFC 2047 style encoded header, it is
      * returned as-is <p>
      *
      * Example of usage:
-     * <p><blockquote><pre>
+     * <blockquote><pre>
      *
      *  MimeBodyPart part = ...
      *  String rawvalue = null;
      *  String  value = null;
      *  try {

@@ -477,13 +485,14 @@
      *      value = rawvalue;
      *  } catch (MessagingException me) { }
      *
      *  return value;
      *
-     * </pre></blockquote><p>
+     * </pre></blockquote>
      *
      * @param   etext   the possibly encoded value
+     * @return decoded text
      * @exception       UnsupportedEncodingException if the charset
      *                  conversion failed.
      */
     public static String decodeText(String etext)
                 throws UnsupportedEncodingException {

@@ -566,11 +575,11 @@
      *
      * This method is meant to be used when creating RFC 822 "phrases".
      * The InternetAddress class, for example, uses this to encode
      * it's 'phrase' component.
      *
-     * @param   text    unicode string
+     * @param   word    unicode string
      * @return  Array of Unicode strings containing only US-ASCII
      *          characters.
      * @exception UnsupportedEncodingException if the encoding fails
      */
     public static String encodeWord(String word)

@@ -588,11 +597,11 @@
      * characters, it is first character-encoded using the specified
      * charset, then transfer-encoded using either the B or Q encoding.
      * The resulting bytes are then returned as a Unicode string
      * containing only ASCII characters. <p>
      *
-     * @param   text    unicode string
+     * @param   word    unicode string
      * @param   charset the MIME charset
      * @param   encoding the encoding to be used. Currently supported
      *          values are "B" and "Q". If this parameter is null, then
      *          the "Q" encoding is used if most of characters to be
      *          encoded are in the ASCII charset, otherwise "B" encoding

@@ -718,10 +727,11 @@
      * thrown. Otherwise, it is transfer-decoded, and then
      * charset-converted into Unicode. If the charset-conversion
      * fails, an UnsupportedEncodingException is thrown.<p>
      *
      * @param   eword   the possibly encoded value
+     * @return deocoded word
      * @exception       ParseException if the string is not an
      *                  encoded-word as per RFC 2047.
      * @exception       UnsupportedEncodingException if the charset
      *                  conversion failed.
      */

@@ -845,12 +855,12 @@
      * RFC 822 and MIME header fields.
      *
      * @param   word    word to be quoted
      * @param   specials the set of special characters
      * @return          the possibly quoted word
-     * @see     javax.mail.internet.HeaderTokenizer#MIME
-     * @see     javax.mail.internet.HeaderTokenizer#RFC822
+     * @see     com.sun.xml.internal.messaging.saaj.packaging.mime.internet.HeaderTokenizer#MIME
+     * @see     com.sun.xml.internal.messaging.saaj.packaging.mime.internet.HeaderTokenizer#RFC822
      */
     public static String quote(String word, String specials) {
         int len = word.length();
 
         /*

@@ -1109,10 +1119,11 @@
                 defaultJavaCharset = System.getProperty("file.encoding",
                                                         "8859_1");
             } catch (SecurityException sex) {
 
                 class NullInputStream extends InputStream {
+                    @Override
                     public int read() {
                         return 0;
                     }
                 }
                 InputStreamReader reader =

@@ -1275,11 +1286,11 @@
     static int checkAscii(String s) {
         int ascii = 0, non_ascii = 0;
         int l = s.length();
 
         for (int i = 0; i < l; i++) {
-            if (nonascii((int)s.charAt(i))) // non-ascii
+            if (nonascii(s.charAt(i))) // non-ascii
                 non_ascii++;
             else
                 ascii++;
         }
 

@@ -1442,18 +1453,21 @@
     public AsciiOutputStream(boolean breakOnNonAscii, boolean encodeEolStrict) {
         this.breakOnNonAscii = breakOnNonAscii;
         checkEOL = encodeEolStrict && breakOnNonAscii;
     }
 
+    @Override
     public void write(int b) throws IOException {
         check(b);
     }
 
+    @Override
     public void write(byte b[]) throws IOException {
         write(b, 0, b.length);
     }
 
+    @Override
     public void write(byte b[], int off, int len) throws IOException {
         len += off;
         for (int i = off; i < len ; i++)
             check(b[i]);
     }
< prev index next >