public static String toStringAndRightTrim(final byte[] bytes, final int offset, final int length) {
        final int rTrimIndex = rightTrimIndex(bytes, offset, length);
        if (rTrimIndex == -1) {
            return null;
        }
        return toString(bytes, offset, rTrimIndex - offset);
    }
copy google protocol buffer
https://github.com/google/protobuf/blob/master/java/src/main/java/com/google/protobuf/CodedOutputStream.java
commons/src/main/java/com/navercorp/pinpoint/common/util/BytesUtils.java