public static String decode(ByteBuffer bb, Charset cs, CharBuffer cb) {
CharsetDecoder de = ThreadLocalCoders.decoderFor(cs)
.onMalformedInput(CodingErrorAction.REPLACE)
.onUnmappableCharacter(CodingErrorAction.REPLACE);
de.reset();
int len = bb.remaining();
CoderResult rt = de.decode(bb, cb, true);
if (rt == CoderResult.OVERFLOW) {
cb.flip();
CharBuffer lcb = CharBuffer.allocate((int)(len * (double)de.maxCharsPerByte()));