本文整理汇总了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");
}
}
}