src/main/java/de/blau/android/net/ContentDispositionFileNameParser.java
/**
     * Parse a {@literal Content-Disposition} header value as defined in RFC 2183.
     *
     * @param contentDisposition the {@literal Content-Disposition} header value
     * @return Return the value of the {@literal filename} parameter (or the value of the {@literal filename*} one
     *         decoded as defined in the RFC 5987), or {@code null} if not defined.
     */
Parse a  Content-Disposition header value as defined in RFC 2183.
@param contentDisposition the  Content-Disposition header value
@return Return the value of the  filename parameter (or the value of the  filename* one
decoded as defined in the RFC 5987), or  null if not defined.
Parse a Content - Disposition header value as defined in RFC 2183 . @param contentDisposition the Content - Disposition header value @return Return the value of the filename parameter ( or the value of the filename * one decoded as defined in the RFC 5987 ) or null if not defined .
public static String parse(@NonNull String contentDisposition) {
        List<String> parts = tokenize(contentDisposition);
        String filename = null;
        Charset charset;
        for (int i = 1; i < parts.size(); i++) {
            String part = parts.get(i);
            int eqIndex = part.indexOf('=');
            if (eqIndex != -1) {
                String attribute = part.substring(0, eqIndex);
                String value = (part.startsWith("\"", eqIndex + 1) && part.endsWith("\"") ? part.substring(eqIndex + 2, part.length() - 1)
                        : part.substring(eqIndex + 1));
                if (attribute.equals(FILENAME_ATTR)) {
                    int idx1 = value.indexOf('\'');
                    int idx2 = value.indexOf('\'', idx1 + 1);
                    if (idx1 != -1 && idx2 != -1) {
                        charset = Charset.forName(value.substring(0, idx1).trim());
                        if (!(UTF_8.equals(charset) || ISO_8859_1.equals(charset))) {
                            throw new IllegalArgumentException("Charset should be UTF-8 or ISO-8859-1");
                        }
                        filename = decodeFilename(value.substring(idx2 + 1), charset);
                    } else {
                        filename = decodeFilename(value, US_ASCII);
                    }
                } else if (attribute.equals(FILENAME_ATTR) && (filename == null)) {
                    filename = value;
                }
            } else {
                throw new IllegalArgumentException("Invalid content disposition format");
            }
        }
        return filename;
    }
public static String parse ( @ NonNull String contentDisposition ) { List < String > parts = tokenize ( contentDisposition ) ; String filename = null ; Charset charset ; for ( int i = 1 ; i < parts . size ( ) ; i ++ ) { String part = parts . get ( i ) ; int eqIndex = part . indexOf ( '=' ) ; if ( eqIndex != - 1 ) { String attribute = part . substring ( 0 , eqIndex ) ; String value = ( part . startsWith ( "\"" , eqIndex + 1 ) && part . endsWith ( "\"" ) ? part . substring ( eqIndex + 2 , part . length ( ) - 1 ) : part . substring ( eqIndex + 1 ) ) ; if ( attribute . equals ( FILENAME_ATTR ) ) { int idx1 = value . indexOf ( '\'' ) ; int idx2 = value . indexOf ( '\'' , idx1 + 1 ) ; if ( idx1 != - 1 && idx2 != - 1 ) { charset = Charset . forName ( value . substring ( 0 , idx1 ) . trim ( ) ) ; if ( ! ( UTF_8 . equals ( charset ) || ISO_8859_1 . equals ( charset ) ) ) { throw new IllegalArgumentException ( "Charset should be UTF-8 or ISO-8859-1" ) ; } filename = decodeFilename ( value . substring ( idx2 + 1 ) , charset ) ; } else { filename = decodeFilename ( value , US_ASCII ) ; } } else if ( attribute . equals ( FILENAME_ATTR ) && ( filename == null ) ) { filename = value ; } } else { throw new IllegalArgumentException ( "Invalid content disposition format" ) ; } } return filename ; }
Parse a {@literal Content-Disposition} header value as defined in RFC 2183.
Parse a { @literal Content - Disposition } header value as defined in RFC 2183 .
// US ASCII