private static String encodeFilename(String input, Charset charset) {
        Objects.requireNonNull(input, "`input` is required");
        Objects.requireNonNull(charset, "`charset` is required");
        Preconditions.checkArgument(!StandardCharsets.US_ASCII.equals(charset), "ASCII does not require encoding");
        Preconditions.checkArgument(UTF_8.equals(charset) || ISO_8859_1.equals(charset), "Only UTF-8 and ISO-8859-1 supported.");
        byte[] source = input.getBytes(charset);
        int len = source.length;
        StringBuilder sb = new StringBuilder(len << 1);
        sb.append(charset.name());
        sb.append("''");
        for (byte b : source) {
            if (isRFC5987AttrChar(b)) {
                sb.append((char) b);
            }
            else {
                sb.append('%');
                char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16));
                char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16));
                sb.append(hex1);
                sb.append(hex2);
            }
        }
        return sb.toString();
    }
Encode the given header field param as describe in RFC 5987.
@param input the header field param
@param charset the charset of the header field param string,
only the US-ASCII, UTF-8 and ISO-8859-1 charsets are supported
@return the encoded header field param
@see <a href="https://tools.ietf.org/html/rfc5987">RFC 5987</a>
manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/util/ContentDisposition.java