当前位置: 首页>>代码示例>>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;未经允许,请勿转载。