Java tutorial
//package com.java2s; /* * Copyright (c) 2016, WSO2 Inc. (http://wso2.com) All Rights Reserved. * <p> * WSO2 Inc. 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 * <p> * http://www.apache.org/licenses/LICENSE-2.0 * <p> * 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.util.Locale; public class Main { /** * check if the pair is [UTF-16,UTF-16LE] [UTF-32, UTF-32LE],[UTF-16,UTF-16BE] [UTF-32, * UTF-32BE] etc. * * @param enc1 encoding style * @param enc2 encoding style * @return true if the encoding styles are compatible, or false otherwise */ private static boolean compatibleEncodings(String enc1, String enc2) { enc1 = enc1.toLowerCase(Locale.getDefault()); enc2 = enc2.toLowerCase(Locale.getDefault()); if (enc1.endsWith("be") || enc1.endsWith("le")) { enc1 = enc1.substring(0, enc1.length() - 2); } if (enc2.endsWith("be") || enc2.endsWith("le")) { enc2 = enc2.substring(0, enc2.length() - 2); } return enc1.equals(enc2); } }