presto-rcfile/src/main/java/io/prestosql/rcfile/RcFileDecoderUtils.java/RcFileDecoderUtils/calculateTruncationLength
class RcFileDecoderUtils:    private static int calculateTruncationLength(int maxCharacterCount, Slice slice, int offset, int length)
    {
        requireNonNull(slice, "slice is null");
        if (maxCharacterCount < 0) {
            throw new IllegalArgumentException("Max length must be greater or equal than zero");
        }
        if (length <= maxCharacterCount) {
            return length;
        }

        int indexEnd = offsetOfCodePoint(slice, offset, maxCharacterCount);
        if (indexEnd < 0) {
            return length;
        }
        return indexEnd - offset;
    }