/** * Estimate the size needed for remaining characters * * @param enc encoder to use for estimates * @param charCount number of characters remaining * @return estimated size in bytes. */ private static int estimateIncrementalEncodingSize(CharsetEncoder enc, int charCount) { return (int) Math.ceil(charCount * enc.averageBytesPerChar()); }
@Override public int estimateSize(Object keyOrValue) { if (keyOrValue instanceof String) { CharsetEncoder encoder = CharsetUtil.encoder(charset); return (int) (encoder.averageBytesPerChar() * ((String) keyOrValue).length()); } return 0; }
/** * Estimate the initial encoded size (in bytes) for a character buffer. * <p> * The estimate assumes that one character consumes uses the maximum length encoding, * whilst the rest use an average size encoding. This accounts for any BOM for UTF-16, at * the expense of a couple of extra bytes for UTF-8 encoded ASCII. * </p> * * @param enc encoder to use for estimates * @param charChount number of characters in string * @return estimated size in bytes. */ private static int estimateInitialBufferSize(CharsetEncoder enc, int charChount) { float first = enc.maxBytesPerChar(); float rest = (charChount - 1) * enc.averageBytesPerChar(); return (int) Math.ceil(first + rest); }
.onUnmappableCharacter(CodingErrorAction.REPLACE); CharBuffer inBuffer = CharBuffer.wrap(charSequence); int estimatedSize = (int) (inBuffer.remaining() * charsetEncoder.averageBytesPerChar()); ByteBuffer outBuffer = ensureCapacity(estimatedSize) .asByteBuffer(writePosition(), writableByteCount());
/** * Construct a new instance. * * @param reader the reader to encode from * @param encoder the character set encoder * @param bufferSize the buffer size to use */ public ReaderInputStream(final Reader reader, final CharsetEncoder encoder, final int bufferSize) { if (reader == null) { throw msg.nullParameter("writer"); } if (encoder == null) { throw msg.nullParameter("decoder"); } if (bufferSize < 1) { throw msg.parameterOutOfRange("bufferSize"); } this.reader = reader; this.encoder = encoder; charBuffer = CharBuffer.wrap(new char[bufferSize]); byteBuffer = ByteBuffer.wrap(new byte[(int) ((float)bufferSize * encoder.averageBytesPerChar() + 0.5f)]); charBuffer.flip(); byteBuffer.flip(); }
.onUnmappableCharacter(CodingErrorAction.REPLACE); CharBuffer inBuffer = CharBuffer.wrap(charSequence); int estimatedSize = (int) (inBuffer.remaining() * charsetEncoder.averageBytesPerChar()); ByteBuffer outBuffer = ensureCapacity(estimatedSize) .asByteBuffer(writePosition(), writableByteCount());
switch (expandedState) { case 0: autoExpand((int) Math.ceil(in.remaining() * encoder.averageBytesPerChar())); expandedState++; break;
switch (expandedState) { case 0: autoExpand((int) Math.ceil(in.remaining() * encoder.averageBytesPerChar())); expandedState++; break;
/** * Estimate the size needed for remaining characters * * @param enc encoder to use for estimates * @param charCount number of characters remaining * @return estimated size in bytes. */ private static int estimateIncrementalEncodingSize(CharsetEncoder enc, int charCount) { return (int) Math.ceil(charCount * enc.averageBytesPerChar()); }
/** * Estimate the size needed for remaining characters * * @param enc encoder to use for estimates * @param charCount number of characters remaining * @return estimated size in bytes. */ private static int estimateIncrementalEncodingSize(CharsetEncoder enc, int charCount) { return (int) Math.ceil(charCount * enc.averageBytesPerChar()); }
@Override public int available() throws IOException { final int estimated = inputBuffer.capacity() * (int) encoder.averageBytesPerChar(); return Math.max(estimated - written, 0); }
@Override public int available() throws IOException { final int estimated = inputBuffer.capacity() * (int) encoder.averageBytesPerChar(); return Math.max(estimated - written, 0); }
@Override public int available() throws IOException { final int estimated = inputBuffer.capacity() * (int) encoder.averageBytesPerChar(); return Math.max(estimated - written, 0); }
/** * Call the superclass constructor with the Charset object and the * encodings sizes from the encoder. */ Encoder(Charset cs, CharsetEncoder encoder) { super(cs, encoder.averageBytesPerChar(), encoder.maxBytesPerChar()); this.encoder = encoder; }
@Override public int estimateSize(Object keyOrValue) { if (keyOrValue instanceof String) { CharsetEncoder encoder = CharsetUtil.encoder(charset); return (int) (encoder.averageBytesPerChar() * ((String) keyOrValue).length()); } return 0; }
@Override public int available() throws IOException { return (int) (reader.available() * (double) this.encoder.averageBytesPerChar()) + buffer.remaining(); }
@Override public int available() { return (int) (reader.available() * this.encoder.averageBytesPerChar()) + bytes.remaining(); }
/** * Constructor, call the superclass constructor with the * Charset object and the encodings sizes from the * delegate encoder. */ PicaEncoder(Charset cs, CharsetEncoder baseEncoder) { super(cs, baseEncoder.averageBytesPerChar(), baseEncoder.maxBytesPerChar()); this.baseEncoder = baseEncoder; }
protected Encoder(CharsetEncoder baseEncoder) { super(AddBOMCharset.this, baseEncoder.averageBytesPerChar(), baseEncoder.maxBytesPerChar() * 2, baseEncoder.replacement()); this.baseEncoder = baseEncoder; baseEncoder.onMalformedInput(CodingErrorAction.REPORT); baseEncoder.onUnmappableCharacter(CodingErrorAction.REPORT); }
private ProxyEncoder (final CharsetEncoder defaultEncoder) { super (ProxyCharset.this, defaultEncoder.averageBytesPerChar(), defaultEncoder.maxBytesPerChar(), defaultEncoder.replacement()); this.currentEncoder = defaultEncoder; this.initialized = true; }