private InputStream printEntity(final StringBuilder sb, InputStream inputStream, final Charset charset)
            throws IOException {
        if (!inputStream.markSupported()) {
            inputStream = new BufferedInputStream(inputStream);
        }
        inputStream.mark(maxEntitySize + 1);
        final byte[] entity = new byte[maxEntitySize + 1];
        final int entitySize = inputStream.read(entity);
        sb.append(new String(entity, 0, Math.min(entitySize, maxEntitySize), charset));
        if (entitySize > maxEntitySize) {
            sb.append("...[truncated]");
        }
        sb.append('\n');
        inputStream.reset();
        return inputStream;
    }
Write the contents of a request/response body, up to a certain length
stroom-util/src/main/java/stroom/util/logging/DefaultLoggingFilter.java