Java Charset Create getCharset(int ibmCharacterSetId)

Here you can find the source of getCharset(int ibmCharacterSetId)

Description

<p> Returns the Charset#name() associated with the given <code>ibmCharacterSetId</code> </p> <p> Associations are defined by Charset#aliases() ; special cases are defined by <a href="http://publib.boulder.ibm.com/infocenter/wmqv6/v6r0/topic/com.ibm.mq.csqzav.doc/csqzav0561.htm#csq77t8">IBM Websphere MQ Infocenter - Character set identifiers</a> </p>

License

Apache License

Parameter

Parameter Description
ibmCharacterSetId ccsid (e.g. 819)

Exception

Parameter Description
UnsupportedCharsetException No matching charset found

Return

Charset charset (e.g. "ISO-8859-1")

Declaration

static public Charset getCharset(int ibmCharacterSetId)
        throws UnsupportedCharsetException 

Method Source Code

//package com.java2s;
/*// w  w w. j a  va 2s. co m
 * Copyright 2002-2006 the original author or authors.
 *
 * Licensed 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.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;

public class Main {
    private static final Charset UTF8 = Charset.forName("UTF-8");
    private static final Charset UNICODE = Charset.forName("Unicode");
    /**
     * Mapping between utf-8 and ibm-1208 is not done in the JVM {@link Charset#aliases()}
     */
    private static final int IBM_CHARACTER_SET_ID_UTF8 = 1208;
    /**
     * Mapping between utf-16/unicode and ibm-1200 is not done in the JVM {@link Charset#aliases()}
     */
    private static final int IBM_CHARACTER_SET_ID_UNICODE = 1200;

    /**
     * <p>
     * Returns the {@link Charset#name()} associated with the given <code>ibmCharacterSetId</code>
     * </p>
     * <p>
     * Associations are defined by {@link Charset#aliases()} ; special cases are defined by <a
     * href="http://publib.boulder.ibm.com/infocenter/wmqv6/v6r0/topic/com.ibm.mq.csqzav.doc/csqzav0561.htm#csq77t8">IBM
     * Websphere MQ Infocenter - Character set identifiers</a>
     * </p>
     * 
     * @param ibmCharacterSetId
     *            ccsid (e.g. 819)
     * @return Charset charset (e.g. "ISO-8859-1")
     * @throws UnsupportedCharsetException
     *             No matching charset found
     */
    static public Charset getCharset(int ibmCharacterSetId)
            throws UnsupportedCharsetException {
        Charset charset;
        switch (ibmCharacterSetId) {
        case IBM_CHARACTER_SET_ID_UNICODE:
            charset = UNICODE;
            break;
        case IBM_CHARACTER_SET_ID_UTF8:
            charset = UTF8;
            break;
        default:
            charset = Charset.forName("IBM-" + ibmCharacterSetId);
            break;
        }
        return charset;
    }
}

Related

  1. getCanonicalCharset(String charset)
  2. getCanonicalCharset(String charset)
  3. getCharset()
  4. getCharset()
  5. getCharset(int cpgid, int gcsgid)
  6. getCharSet(String charset)
  7. getCharset(String charsetName)
  8. getCharset(String charsetName)
  9. getCharset(String contentType)