本文整理汇总了Java中java.nio.charset.CharsetEncoder.averageBytesPerChar方法的典型用法代码示例。如果您正苦于以下问题:Java CharsetEncoder.averageBytesPerChar方法的具体用法?Java CharsetEncoder.averageBytesPerChar怎么用?Java CharsetEncoder.averageBytesPerChar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.charset.CharsetEncoder
的用法示例。
在下文中一共展示了CharsetEncoder.averageBytesPerChar方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setEncoding
import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
protected final void setEncoding(final String encoding)
throws UnsupportedEncodingException {
final Charset charSet = charsetForName(encoding);
final CharsetEncoder encoder = charSet.newEncoder().onMalformedInput(
CodingErrorAction.REPLACE).onUnmappableCharacter(
CodingErrorAction.REPLACE);
final float maxBytesPerChar = encoder.maxBytesPerChar();
final float averageBytesPerChar = encoder.averageBytesPerChar();
final boolean fixedWidthCharset =
(maxBytesPerChar == Math.round(maxBytesPerChar))
&& (maxBytesPerChar == averageBytesPerChar);
//
m_fixedWidthCharset = fixedWidthCharset;
m_maxCharWidth = Math.round(maxBytesPerChar);
m_charset = charSet;
m_encoder = encoder;
m_encoding = m_charset.name();
}
示例2: encode
import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
private static ByteBuffer encode(CharBuffer in, CharsetEncoder encoder) {
int length = (int) (in.remaining() * (double) encoder.averageBytesPerChar());
ByteBuffer out = ByteBuffer.allocate(length);
encoder.reset();
CoderResult flushResult = null;
while (flushResult != CoderResult.UNDERFLOW) {
CoderResult encodeResult = encoder.encode(in, out, true);
if (encodeResult == CoderResult.OVERFLOW) {
out = allocateMore(out);
continue;
}
flushResult = encoder.flush(out);
if (flushResult == CoderResult.OVERFLOW) {
out = allocateMore(out);
}
}
out.flip();
return out;
}
示例3: MockCharsetEncoder
import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
protected MockCharsetEncoder(Charset cs, CharsetEncoder raw){
super(cs, raw.averageBytesPerChar(), raw.maxBytesPerChar());
this.raw = raw;
}
示例4: ProxyEncoder
import java.nio.charset.CharsetEncoder; //导入方法依赖的package包/类
private ProxyEncoder (final CharsetEncoder defaultEncoder) {
super (ProxyCharset.this, defaultEncoder.averageBytesPerChar(), defaultEncoder.maxBytesPerChar(), defaultEncoder.replacement());
this.currentEncoder = defaultEncoder;
this.initialized = true;
}