@SuppressFBWarnings("SUA_SUSPICIOUS_UNINITIALIZED_ARRAY") public static String decode( final CharsetDecoder cd, final byte[] ba, final int off, final int len) { if (len == 0) { return ""; } int en = (int) (len * (double) cd.maxCharsPerByte()); char[] ca = Arrays.getCharsTmp(en); if (cd instanceof ArrayDecoder) { int clen = ((ArrayDecoder) cd).decode(ba, off, len, ca); return new String(ca, 0, clen); } cd.reset(); ByteBuffer bb = ByteBuffer.wrap(ba, off, len); CharBuffer cb = CharBuffer.wrap(ca); try { CoderResult cr = cd.decode(bb, cb, true); if (!cr.isUnderflow()) { cr.throwException(); } cr = cd.flush(cb); if (!cr.isUnderflow()) { cr.throwException(); } } catch (CharacterCodingException x) { throw new Error(x); } return new String(ca, 0, cb.position()); }