本文整理汇总了Java中java.nio.charset.Charset.canEncode方法的典型用法代码示例。如果您正苦于以下问题:Java Charset.canEncode方法的具体用法?Java Charset.canEncode怎么用?Java Charset.canEncode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.charset.Charset
的用法示例。
在下文中一共展示了Charset.canEncode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import java.nio.charset.Charset; //导入方法依赖的package包/类
private synchronized static void initialize() {
if (mInitialized)
return;
mData = new HashMap<>();
for (Map.Entry<String, Charset> entry : Charset.availableCharsets().entrySet()) {
Charset c = entry.getValue();
if (c.canEncode() && c.isRegistered()) {
String key = entry.getKey();
if (key.startsWith("cp")) {
// Custom CP437 charset changes.
mData.put("CP437", "CP437");
}
mData.put(c.displayName(), entry.getKey());
}
}
mInitialized = true;
}
示例2: main
import java.nio.charset.Charset; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
SortedMap<String, Charset> map = Charset.availableCharsets();
for (String name : map.keySet()) {
Charset charset = map.get(name);
if (charset.canEncode() && !charset.name().equals("x-COMPOUND_TEXT")) {
testNormalSurrogate(charset, NORMAL_SURROGATE);
testMalformedSurrogate(charset, MALFORMED_SURROGATE);
testMalformedSurrogate(charset, REVERSED_SURROGATE);
testMalformedSurrogate(charset, SOLITARY_HIGH_SURROGATE);
testMalformedSurrogate(charset, SOLITARY_LOW_SURROGATE);
testSurrogateWithReplacement(charset, NORMAL_SURROGATE);
testSurrogateWithReplacement(charset, MALFORMED_SURROGATE);
testSurrogateWithReplacement(charset, REVERSED_SURROGATE);
testSurrogateWithReplacement(charset, SOLITARY_HIGH_SURROGATE);
testSurrogateWithReplacement(charset, SOLITARY_LOW_SURROGATE);
}
}
}
示例3: StringByteString
import java.nio.charset.Charset; //导入方法依赖的package包/类
StringByteString(String s, Charset charset) {
this.string = Objects.requireNonNull(s);
this.charset = Objects.requireNonNull(charset);
if (!charset.canEncode()) {
throw new IllegalArgumentException("Charset cannot encode: " + charset.name());
}
this.byteHashCode = 0;
this.byteLength = string.isEmpty() ? 0 : -1;
}
示例4: append
import java.nio.charset.Charset; //导入方法依赖的package包/类
/**
* Appends a char sequence {@code charSequence} interpreted as a sequence
* of bytes using the specified {@code Charset}.
*
* @param charSequence the char sequence to append, must not be {@code null}
* @param charset the charset to use for encoding, must not be {@code null}
* @return this builder
* @throws NullPointerException if {@code string} is {@code null}
* @throws IllegalArgumentException if {@code charset} cannot does not provide encoding capability
* (see {@link Charset#canEncode()})
*/
public ByteStringBuilder append(CharSequence charSequence, Charset charset) {
if (!charset.canEncode()) {
throw new IllegalArgumentException("Charset cannot encode: " + charset.name());
}
// FIXME: inefficient, could be done more directly
append(ByteString.of(charSequence.toString(), charset));
return this;
}