src/main/java/de/blau/android/net/ContentDispositionFileNameParser.java
/**
     * Decode 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
     */
Decode the given header field param as described in RFC 5987.

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
Decode the given header field param as described in RFC 5987 . 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
private static String decodeFilename(String filename, Charset charset) {
        if (filename == null) {
            throw new IllegalArgumentException("'input' String` should not be null");
        }
        if (charset == null) {
            throw new IllegalArgumentException("'charset' should not be null");
        }
        byte[] value = filename.getBytes(charset);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        int index = 0;
        while (index < value.length) {
            byte b = value[index];
            if (isRFC5987AttrChar(b)) {
                byteArrayOutputStream.write((char) b);
                index++;
            } else if (b == '%' && index < value.length - 2) {
                char[] array = new char[] { (char) value[index + 1], (char) value[index + 2] };
                try {
                    byteArrayOutputStream.write(Integer.parseInt(String.valueOf(array), 16));
                } catch (NumberFormatException ex) {
                    throw new IllegalArgumentException(INVALID_HEADER_FIELD_PARAMETER_FORMAT, ex);
                }
                index += 3;
            } else {
                throw new IllegalArgumentException(INVALID_HEADER_FIELD_PARAMETER_FORMAT);
            }
        }
        try {
            return byteArrayOutputStream.toString(charset.name());
        } catch (UnsupportedEncodingException e) {
            throw new IllegalArgumentException("Failed to copy contents of ByteArrayOutputStream into a String", e);
        }
    }
private static String decodeFilename ( String filename , Charset charset ) { if ( filename == null ) { throw new IllegalArgumentException ( "'input' String` should not be null" ) ; } if ( charset == null ) { throw new IllegalArgumentException ( "'charset' should not be null" ) ; } byte [ ] value = filename . getBytes ( charset ) ; ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ( ) ; int index = 0 ; while ( index < value . length ) { byte b = value [ index ] ; if ( isRFC5987AttrChar ( b ) ) { byteArrayOutputStream . write ( ( char ) b ) ; index ++ ; } else if ( b == '%' && index < value . length - 2 ) { char [ ] array = new char [ ] { ( char ) value [ index + 1 ] , ( char ) value [ index + 2 ] } ; try { byteArrayOutputStream . write ( Integer . parseInt ( String . valueOf ( array ) , 16 ) ) ; } catch ( NumberFormatException ex ) { throw new IllegalArgumentException ( INVALID_HEADER_FIELD_PARAMETER_FORMAT , ex ) ; } index += 3 ; } else { throw new IllegalArgumentException ( INVALID_HEADER_FIELD_PARAMETER_FORMAT ) ; } } try { return byteArrayOutputStream . toString ( charset . name ( ) ) ; } catch ( UnsupportedEncodingException e ) { throw new IllegalArgumentException ( "Failed to copy contents of ByteArrayOutputStream into a String" , e ) ; } }
Decode the given header field param as described in RFC 5987.
Decode the given header field param as described in RFC 5987 .