Android UTF Check isUTF8(String encoding)

Here you can find the source of isUTF8(String encoding)

Description

Whether a given encoding - or the platform's default encoding if the parameter is null - is UTF-8.

License

Apache License

Declaration

static boolean isUTF8(String encoding) 

Method Source Code

//package com.java2s;
/*/*from w  w  w.java2s .c o m*/
 *  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.
 *
 */

public class Main {
    /**
     * name of the encoding UTF-8
     */
    static final String UTF8 = "UTF8";
    /**
     * variant name of the encoding UTF-8 used for comparisions.
     */
    private static final String UTF_DASH_8 = "utf-8";

    /**
     * Whether a given encoding - or the platform's default encoding
     * if the parameter is null - is UTF-8.
     */
    static boolean isUTF8(String encoding) {
        if (encoding == null) {
            // check platform's default encoding
            encoding = System.getProperty("file.encoding");
        }
        return UTF8.equalsIgnoreCase(encoding)
                || UTF_DASH_8.equalsIgnoreCase(encoding);
    }
}

Related

  1. getUTFFormat(int p_type)
  2. isUTFFormat(String p_format)
  3. utf8Length(byte[] buffer, int str, int len)