Here you can find the source of canEncode(String sz, String charset)
public static boolean canEncode(String sz, String charset)
//package com.java2s; /* /*from ww w . j a v a 2s. c om*/ * Serposcope - SEO rank checker https://serposcope.serphacker.com/ * * Copyright (c) 2016 SERP Hacker * @author Pierre Nogues <support@serphacker.com> * @license https://opensource.org/licenses/MIT MIT License */ import java.nio.CharBuffer; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; public class Main { public static boolean canEncode(String sz, String charset) { try { Charset cs = Charset.forName(charset); if (cs.canEncode()) { CharsetEncoder cse = cs.newEncoder(); return cse.encode(CharBuffer.wrap(sz)) != null; } else { return false; } } catch (Exception e) { return false; } } }