當前位置: 首頁>>代碼示例>>Java>>正文


Java Charset.canEncode方法代碼示例

本文整理匯總了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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:EditHostActivity.java

示例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);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:MalformedSurrogates.java

示例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;
}
 
開發者ID:kroepke,項目名稱:luna,代碼行數:10,代碼來源:StringByteString.java

示例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;
}
 
開發者ID:kroepke,項目名稱:luna,代碼行數:21,代碼來源:ByteStringBuilder.java


注:本文中的java.nio.charset.Charset.canEncode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。