private static String decodeFilename(String filename, Charset charset) {
        final byte[] value = filename.getBytes(charset);
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int index = 0;
        while (index < value.length) {
            final byte b = value[index];
            if (isRFC5987AttrChar(b)) {
                baos.write((char) b);
                index++;
            } else if (b == '%' && index < value.length - 2) {
                final char[] array = {(char) value[index + 1], (char) value[index + 2]};
                try {
                    baos.write(Integer.parseInt(String.valueOf(array), 16));
                } catch (NumberFormatException ex) {
                    throw new IllegalArgumentException(
                            "Invalid filename header field parameter format (as defined in RFC 5987): " +
                            filename + " (charset: " + charset + ')', ex);
                }
                index += 3;
            } else {
                throw new IllegalArgumentException(
                        "Invalid filename header field parameter format (as defined in RFC 5987): " +
                        filename + " (charset: " + charset + ')');
            }
        }
        try {
            return baos.toString(charset.name());
        } catch (UnsupportedEncodingException e) {
            // Should never reach here.
            // The charset should be either UTF-8 or ISO-8859-1.
            throw new Error();
        }
    }
Decodes the given header field param as described in RFC 5987.

<p>Only the US-ASCII, UTF-8 and ISO-8859-1 charsets are supported.

@param filename the filename
@param charset the charset for the filename
@return the encoded header field param

@see <a href="https://datatracker.ietf.org/doc/rfc5987/">RFC 5987</a>
core/src/main/java/com/linecorp/armeria/common/ContentDisposition.java