Java String Encode encodeTexts(String s)

Here you can find the source of encodeTexts(String s)

Description

Encode non ascii characters present in email headers

License

Apache License

Declaration

public static String encodeTexts(String s) 

Method Source Code

//package com.java2s;
/****************************************************************
 * Licensed to the Apache Software Foundation (ASF) under one   *
 * or more contributor license agreements.  See the NOTICE file *
 * distributed with this work for additional information        *
 * regarding copyright ownership.  The ASF licenses this file   *
 * to you under the Apache License, Version 2.0 (the            *
 * "License"); you may not use this file except in compliance   *
 * with the License.  You may obtain a copy of the License at   *
 *                                                              *
 *   http://www.apache.org/licenses/LICENSE-2.0                 *
 *                                                              *
 * Unless required by applicable law or agreed to in writing,   *
 * software distributed under the License is distributed on an  *
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
 * KIND, either express or implied.  See the License for the    *
 * specific language governing permissions and limitations      *
 * under the License.                                           *
 ****************************************************************/

import java.io.UnsupportedEncodingException;

import javax.mail.internet.MimeUtility;

public class Main {
    /**/*ww w .  j  a va  2s.c  o m*/
     * Encode non ascii characters present in email headers
     */
    public static String encodeTexts(String s) {
        String ret = s;
        if (s != null) {
            try {
                ret = MimeUtility.encodeText(s, "ISO-8859-1", null);
            } catch (UnsupportedEncodingException e) {
            }
        }
        return ret;
    }
}

Related

  1. encodeString(String text, String charsetName)
  2. encodeString(String value)
  3. encodeStringByUTF8(String str)
  4. encodeText(String str)
  5. encodeText(String str, String fromEnc, String toEnc)
  6. encodeTextValue(char[] characters, int offset, int length, Writer writer)
  7. encodeThoroughly(String s)
  8. encodeToFlex(Object o)
  9. encodeToForm(Map msg)