本文整理匯總了Java中java.nio.charset.Charset.aliases方法的典型用法代碼示例。如果您正苦於以下問題:Java Charset.aliases方法的具體用法?Java Charset.aliases怎麽用?Java Charset.aliases使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.charset.Charset
的用法示例。
在下文中一共展示了Charset.aliases方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: MysqlCharset
import java.nio.charset.Charset; //導入方法依賴的package包/類
/**
* Constructs MysqlCharset object
*
* @param charsetName
* MySQL charset name
* @param mblen
* Max number of bytes per character
* @param priority
* MysqlCharset with highest lever of this param will be used for Java encoding --> Mysql charsets conversion.
* @param javaEncodings
* List of Java encodings corresponding to this MySQL charset; the first name in list is the default for mysql --> java data conversion
*/
public MysqlCharset(String charsetName, int mblen, int priority, String[] javaEncodings) {
this.charsetName = charsetName;
this.mblen = mblen;
this.priority = priority;
for (int i = 0; i < javaEncodings.length; i++) {
String encoding = javaEncodings[i];
try {
Charset cs = Charset.forName(encoding);
addEncodingMapping(cs.name());
Set<String> als = cs.aliases();
Iterator<String> ali = als.iterator();
while (ali.hasNext()) {
addEncodingMapping(ali.next());
}
} catch (Exception e) {
// if there is no support of this charset in JVM it's still possible to use our converter for 1-byte charsets
if (mblen == 1) {
addEncodingMapping(encoding);
}
}
}
if (this.javaEncodingsUc.size() == 0) {
if (mblen > 1) {
addEncodingMapping("UTF-8");
} else {
addEncodingMapping("Cp1252");
}
}
}