public static StringBuilder encode(String input, StringBuilder output) {
        for (int i = 0; i < input.length(); i = input.offsetByCodePoints(i, 1)) {
            int c = input.codePointAt(i);
            if (c <= '~') {
                if (c <= ' ') {
                    encode(c, output);
                } else {
                    switch (c) {
                        case '{':
                        case '}':
                            encode(c, output);
                            break;
                        default:
                            output.append((char) c);
                    }
                }
            } else {
                encode(c, output);
            }
        }
        return output;
    }
ISO 646.irv:1991 safe quoting into a StringBuilder instance.

@param input the string to encode
@param output the destination buffer
@return the destination buffer given as input
vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/Encoder.java