src/main/java/de/blau/android/net/ContentDispositionFileNameParser.java
/**
     * Tokenize a header value
     * 
     * @param headerValue the header value
     * @return a list of tokens
     */
Tokenize a header value

@param headerValue the header value
@return a list of tokens
Tokenize a header value @param headerValue the header value @return a list of tokens
private static List<String> tokenize(@NonNull String headerValue) {
        int index = headerValue.indexOf(';');
        String type = (index >= 0 ? headerValue.substring(0, index) : headerValue).trim();
        if (type.isEmpty()) {
            throw new IllegalArgumentException("Content-Disposition header must not be empty");
        }
        List<String> parts = new ArrayList<>();
        parts.add(type);
        if (index >= 0) {
            do {
                int nextIndex = index + 1;
                boolean quoted = false;
                boolean escaped = false;
                while (nextIndex < headerValue.length()) {
                    char ch = headerValue.charAt(nextIndex);
                    if (ch == ';') {
                        if (!quoted) {
                            break;
                        }
                    } else if (!escaped && ch == '"') {
                        quoted = !quoted;
                    }
                    escaped = (!escaped && ch == '\\');
                    nextIndex++;
                }
                String part = headerValue.substring(index + 1, nextIndex).trim();
                if (!part.isEmpty()) {
                    parts.add(part);
                }
                index = nextIndex;
            } while (index < headerValue.length());
        }
        return parts;
    }
private static List < String > tokenize ( @ NonNull String headerValue ) { int index = headerValue . indexOf ( ';' ) ; String type = ( index >= 0 ? headerValue . substring ( 0 , index ) : headerValue ) . trim ( ) ; if ( type . isEmpty ( ) ) { throw new IllegalArgumentException ( "Content-Disposition header must not be empty" ) ; } List < String > parts = new ArrayList < > ( ) ; parts . add ( type ) ; if ( index >= 0 ) { do { int nextIndex = index + 1 ; boolean quoted = false ; boolean escaped = false ; while ( nextIndex < headerValue . length ( ) ) { char ch = headerValue . charAt ( nextIndex ) ; if ( ch == ';' ) { if ( ! quoted ) { break ; } } else if ( ! escaped && ch == '"' ) { quoted = ! quoted ; } escaped = ( ! escaped && ch == '\\' ) ; nextIndex ++ ; } String part = headerValue . substring ( index + 1 , nextIndex ) . trim ( ) ; if ( ! part . isEmpty ( ) ) { parts . add ( part ) ; } index = nextIndex ; } while ( index < headerValue . length ( ) ) ; } return parts ; }
Tokenize a header value
Tokenize a header value