Code example for CharsetDecoder

Methods: decodeflushmaxCharsPerByte

	public static StringBuilder decodeUTF8(StringBuilder result, byte[] bytes, int offset, int length)
		CharsetDecoder decoder = acquireUTF8Encoder();
		int scaledLength = (int) ((double) length * (double) decoder.maxCharsPerByte());
		char[] chars = charArrayPool.acquire();
		if (chars.length < scaledLength)
			chars = new char[scaledLength]; // we'll swap buffers on the pool, let the smaller one get
																			// gc'ed 
		CharBuffer cb = CharBuffer.wrap(chars);
		ByteBuffer bb = ByteBuffer.wrap(bytes, offset, length);
		CoderResult cr = decoder.decode(bb, cb, true);
		// cb.rewind(); // reset for re-use -- 
		int resultLength = cb.position();
		result.append(chars, 0, resultLength);
		return result;
Contextual code suggestions in your IDE  Get Codota for Java