< 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 **** /* ! * 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 --- 1,7 ---- /* ! * 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,77 **** * 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> * * byte[] bytes = string.getBytes("iso-8859-1"); * ! * </pre></blockquote><p> * * 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 --- 63,77 ---- * 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 ! * <blockquote><pre> * * byte[] bytes = string.getBytes("iso-8859-1"); * ! * </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,229 **** --- 220,233 ---- * "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,301 **** --- 296,306 ---- * 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,330 **** --- 326,336 ---- * * @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,365 **** --- 362,372 ---- * @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,405 **** * * Note that this method should be used to encode only * "unstructured" RFC 822 headers. <p> * * Example of usage: ! * <p><blockquote><pre> * * MimeBodyPart part = ... * String rawvalue = "FooBar Mailer, Japanese version 1.1" * try { * // If we know for sure that rawvalue contains only US-ASCII --- 402,412 ---- * * Note that this method should be used to encode only * "unstructured" RFC 822 headers. <p> * * Example of usage: ! * <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,419 **** * // encoding failure * } catch (MessagingException me) { * // setHeader() failure * } * ! * </pre></blockquote><p> * * @param text unicode string * @return Unicode string containing only US-ASCII characters * @exception UnsupportedEncodingException if the encoding fails */ --- 416,426 ---- * // encoding failure * } catch (MessagingException me) { * // setHeader() failure * } * ! * </pre></blockquote> * * @param text unicode string * @return Unicode string containing only US-ASCII characters * @exception UnsupportedEncodingException if the encoding fails */
*** 444,453 **** --- 451,461 ---- * 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,472 **** * 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> * * MimeBodyPart part = ... * String rawvalue = null; * String value = null; * try { --- 470,480 ---- * 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: ! * <blockquote><pre> * * MimeBodyPart part = ... * String rawvalue = null; * String value = null; * try {
*** 477,489 **** * value = rawvalue; * } catch (MessagingException me) { } * * return value; * ! * </pre></blockquote><p> * * @param etext the possibly encoded value * @exception UnsupportedEncodingException if the charset * conversion failed. */ public static String decodeText(String etext) throws UnsupportedEncodingException { --- 485,498 ---- * value = rawvalue; * } catch (MessagingException me) { } * * return value; * ! * </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,576 **** * * 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 * @return Array of Unicode strings containing only US-ASCII * characters. * @exception UnsupportedEncodingException if the encoding fails */ public static String encodeWord(String word) --- 575,585 ---- * * 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 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,598 **** * 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 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 --- 597,607 ---- * 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 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,727 **** --- 727,737 ---- * 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,856 **** * 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 */ public static String quote(String word, String specials) { int len = word.length(); /* --- 855,866 ---- * 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 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,1118 **** --- 1119,1129 ---- defaultJavaCharset = System.getProperty("file.encoding", "8859_1"); } catch (SecurityException sex) { class NullInputStream extends InputStream { + @Override public int read() { return 0; } } InputStreamReader reader =
*** 1275,1285 **** 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 non_ascii++; else ascii++; } --- 1286,1296 ---- static int checkAscii(String s) { int ascii = 0, non_ascii = 0; int l = s.length(); for (int i = 0; i < l; i++) { ! if (nonascii(s.charAt(i))) // non-ascii non_ascii++; else ascii++; }
*** 1442,1459 **** --- 1453,1473 ---- 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 >