本文整理匯總了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;
}