Here you can find the source of canEncode(String charset, CharSequence text, String unicodeValue)
Parameter | Description |
---|---|
charset | non null |
text | non null |
unicodeValue | a parameter |
public static String canEncode(String charset, CharSequence text, String unicodeValue)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004 Andrei Loskutov./*from www .j a v a 2 s . c o m*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the BSD License * which accompanies this distribution, and is available at * http://www.opensource.org/licenses/bsd-license.php * Contributor: Andrei Loskutov - initial API and implementation *******************************************************************************/ import java.nio.charset.Charset; import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.UnsupportedCharsetException; public class Main { /** * * @param charset non null * @param text non null * @param unicodeValue * @return null if text could be encoded, error message otherwise */ public static String canEncode(String charset, CharSequence text, String unicodeValue) { Charset cs; try { cs = Charset.forName(charset); } catch (IllegalCharsetNameException e) { return "Charset name '" + charset + "' is illegal."; } catch (UnsupportedCharsetException e) { return "Charset '" + charset + "' is not supported."; } if (cs.canEncode() && cs.newEncoder().canEncode(text)) { return null; } return "Charset '" + charset + "' does not support encoding for \\u" + unicodeValue + "."; } }