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