Android Charset Create getCharset(String charsetName)

Here you can find the source of getCharset(String charsetName)

Description

get Charset

License

Apache License

Declaration

public static java.nio.charset.Charset getCharset(String charsetName) 

Method Source Code

/****************************************************************
 * 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 java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
import java.util.HashMap;
import java.util.TreeSet;
import org.apache.james.mime4j.Log;
import org.apache.james.mime4j.LogFactory;

public class Main{
    private static Log log = LogFactory.getLog(CharsetUtil.class);
    public static java.nio.charset.Charset getCharset(String charsetName) {
        String defaultCharset = "ISO-8859-1";

        // Use the default chareset if given charset is null
        if (charsetName == null)
            charsetName = defaultCharset;

        try {/*w  ww. j a v a  2s.com*/
            return java.nio.charset.Charset.forName(charsetName);
        } catch (IllegalCharsetNameException e) {
            // Use default charset on exception
            return java.nio.charset.Charset.forName(defaultCharset);
        } catch (UnsupportedCharsetException ex) {
            // Use default charset on exception
            return java.nio.charset.Charset.forName(defaultCharset);
        }

    }
}

Related

  1. charsetForVendor(String charsetName)
  2. charsetForVendor(String charsetName, String vendor)