private static void decodeAsPrintableChars(final CharsetDecoder charsetDecoder,
                                               final byte[] bytes,
                                               final StringBuilder stringBuilder,
                                               final char unknownCharReplacement) {

        final ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);

        for (int i = 0; i < bytes.length; i++) {
            byteBuffer.position(i);
            byteBuffer.limit(i + 1);
            char chr;
            try {
                final CharBuffer charBuffer = charsetDecoder.decode(byteBuffer);
                chr = charBuffer.charAt(0);
            } catch (CharacterCodingException e) {
                chr = unknownCharReplacement;
            }
            final char printableChar = asPrintableChar(chr);
            stringBuilder.append(printableChar);
        }
    }
Replaces chr if it is a control character
stroom-util/src/main/java/stroom/util/string/HexDumpUtil.java