public static String replaceSuffix(String str, String oldSuffix, String newSuffix) {
        if (!str.endsWith(oldSuffix))
            throw new IllegalArgumentException("Expected string to end with " + oldSuffix + " but string is " + str);
        return str.substring(0, str.length() - oldSuffix.length()) + newSuffix;
    }
Replace the given string suffix with the new suffix. If the string doesn't end with the given suffix throw an exception.
clients/src/main/java/org/apache/kafka/common/utils/Utils.java