private String truncate(String value, int length, Map<String, String[]> data) {
        setTruncated(data);

        //correctly handle multibyte characters
        byte[] bytes = value.getBytes(StandardCharsets.UTF_16BE);
        ByteBuffer bb = ByteBuffer.wrap(bytes, 0, length);
        CharBuffer cb = CharBuffer.allocate(length);
        CharsetDecoder decoder = StandardCharsets.UTF_16BE.newDecoder();
        // Ignore last (potentially) incomplete character
        decoder.onMalformedInput(CodingErrorAction.IGNORE);
        decoder.decode(bb, cb, true);
        decoder.flush(cb);
        return new String(cb.array(), 0, cb.position());
    }
@param maxKeySize maximum key size in UTF-16 bytes-- keys will be truncated to this
                  length; if less than 0, keys will not be truncated
@param maxEstimatedSize
@param includeFields if null or empty, all fields are included; otherwise, which fields
                     to add to the metadata object.
@param excludeFields these fields will not be included (unless they're in {@link StandardWriteFilter#ALWAYS_SET_FIELDS})
@param includeEmpty if <code>true</code>, this will set or add an empty value to the
                    metadata object.
tika-core/src/main/java/org/apache/tika/metadata/writefilter/StandardWriteFilter.java