Tuesday 27 June 2017

Check encoding scheme supported or not in java

'java.nio.charset.Charset' class provides 'isSupported' method to check whether given character encoding is supported by your Java implementation or not.
package com.sample;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

public class Test {

  public static void main(String args[]) throws UnsupportedEncodingException {

    boolean isUTF8Supported = Charset.isSupported("UTF-8");
    boolean isUTF16Supported = Charset.isSupported("UTF-16");
    boolean isUTF32Supported = Charset.isSupported("UTF-32");
    boolean isUTF64Supported = Charset.isSupported("UTF-64");
    boolean isUTF128Supported = Charset.isSupported("UTF-128");
    boolean isUTF256Supported = Charset.isSupported("UTF-256");

    System.out.println("isUTF8Supported : " + isUTF8Supported);
    System.out.println("isUTF16Supported : " + isUTF16Supported);
    System.out.println("isUTF32Supported : " + isUTF32Supported);
    System.out.println("isUTF64Supported : " + isUTF64Supported);
    System.out.println("isUTF128Supported : " + isUTF128Supported);
    System.out.println("isUTF256Supported : " + isUTF256Supported);
  }
}

Output
isUTF8Supported : true
isUTF16Supported : true
isUTF32Supported : true
isUTF64Supported : false
isUTF128Supported : false
isUTF256Supported : false




No comments:

Post a Comment