CoderResult (ByteBuffer in, CharBuffer out) { try { CoderResult coderResult = doFlush(out); if (coderResult == CoderResult.OVERFLOW) return CoderResult.OVERFLOW; int start = in.position(); byte[] buf = new byte[4]; while (in.position() < in.limit()) { in.mark(); final byte b = in.get(); if (b == '\\') { decodeArray(in.array(), start, in.position()-1); byte next = in.get(); if (next == 'u') { buf[0] = in.get(); buf[1] = in.get(); buf[2] = in.get(); buf[3] = in.get(); char decoded = unicode(buf); if (decoded == INVALID_CHAR) { myOutBuffer.append("\\u"); myOutBuffer.append((char)buf[0]); myOutBuffer.append((char)buf[1]); myOutBuffer.append((char)buf[2]); myOutBuffer.append((char)buf[3]); } else { myOutBuffer.append(decoded); } } else { myOutBuffer.append("\\"); myOutBuffer.append((char)next); } start = in.position(); } } decodeArray(in.array(), start, in.position()); } catch (BufferUnderflowException e) { in.reset(); } return doFlush(out); }