private Set<Cookie> doDecode(String header) {
        List<String> names = new ArrayList<String>(8);
        List<String> values = new ArrayList<String>(8);
        extractKeyValuePairs(header, names, values);

        if (names.isEmpty()) {
            return Collections.emptySet();
        }

        int i;
        int version = 0;

        // $Version is the only attribute that can appear before the actual
        // cookie name-value pair.
        if (names.get(0).equalsIgnoreCase(VERSION)) {
            try {
                version = Integer.parseInt(values.get(0));
            } catch (NumberFormatException e) {
                // Ignore.
            }
            i = 1;
        } else {
            i = 0;
        }

        if (names.size() <= i) {
            // There's a version attribute, but nothing more.
            return Collections.emptySet();
        }

        Set<Cookie> cookies = new TreeSet<Cookie>();
        for (; i < names.size(); i ++) {
            String name = names.get(i);
            String value = values.get(i);
            if (value == null) {
                value = "";
            }

            Cookie c = initCookie(name, value);

            if (c == null) {
                break;
            }

            boolean discard = false;
            boolean secure = false;
            boolean httpOnly = false;
            String comment = null;
            String commentURL = null;
            String domain = null;
            String path = null;
            long maxAge = Long.MIN_VALUE;
            List<Integer> ports = new ArrayList<Integer>(2);

            for (int j = i + 1; j < names.size(); j++, i++) {
                name = names.get(j);
                value = values.get(j);

                if (DISCARD.equalsIgnoreCase(name)) {
                    discard = true;
                } else if (CookieHeaderNames.SECURE.equalsIgnoreCase(name)) {
                    secure = true;
                } else if (CookieHeaderNames.HTTPONLY.equalsIgnoreCase(name)) {
                   httpOnly = true;
                } else if (COMMENT.equalsIgnoreCase(name)) {
                    comment = value;
                } else if (COMMENTURL.equalsIgnoreCase(name)) {
                    commentURL = value;
                } else if (CookieHeaderNames.DOMAIN.equalsIgnoreCase(name)) {
                    domain = value;
                } else if (CookieHeaderNames.PATH.equalsIgnoreCase(name)) {
                    path = value;
                } else if (CookieHeaderNames.EXPIRES.equalsIgnoreCase(name)) {
                    Date date = DateFormatter.parseHttpDate(value);
                    if (date != null) {
                        long maxAgeMillis = date.getTime() - System.currentTimeMillis();
                        maxAge = maxAgeMillis / 1000 + (maxAgeMillis % 1000 != 0? 1 : 0);
                    }
                } else if (CookieHeaderNames.MAX_AGE.equalsIgnoreCase(name)) {
                    maxAge = Integer.parseInt(value);
                } else if (VERSION.equalsIgnoreCase(name)) {
                    version = Integer.parseInt(value);
                } else if (PORT.equalsIgnoreCase(name)) {
                    String[] portList = value.split(",");
                    for (String s1: portList) {
                        try {
                            ports.add(Integer.valueOf(s1));
                        } catch (NumberFormatException e) {
                            // Ignore.
                        }
                    }
                } else {
                    break;
                }
            }

            c.setVersion(version);
            c.setMaxAge(maxAge);
            c.setPath(path);
            c.setDomain(domain);
            c.setSecure(secure);
            c.setHttpOnly(httpOnly);
            if (version > 0) {
                c.setComment(comment);
            }
            if (version > 1) {
                c.setCommentUrl(commentURL);
                c.setPorts(ports);
                c.setDiscard(discard);
            }

            cookies.add(c);
        }

        return cookies;
    }
private Set < Cookie > doDecode ( String header ) { List < String > names = new ArrayList < String > ( 8 ) ; List < String > values = new ArrayList < String > ( 8 ) ; extractKeyValuePairs ( header , names , values ) ; if ( names . isEmpty ( ) ) { return Collections . emptySet ( ) ; } int i ; int version = 0 ; if ( names . get ( 0 ) . equalsIgnoreCase ( VERSION ) ) { try { version = Integer . parseInt ( values . get ( 0 ) ) ; } catch ( NumberFormatException e ) { } i = 1 ; } else { i = 0 ; } if ( names . size ( ) <= i ) { return Collections . emptySet ( ) ; } Set < Cookie > cookies = new TreeSet < Cookie > ( ) ; for ( ; i < names . size ( ) ; i ++ ) { String name = names . get ( i ) ; String value = values . get ( i ) ; if ( value == null ) { value = "" ; } Cookie c = initCookie ( name , value ) ; if ( c == null ) { break ; } boolean discard = false ; boolean secure = false ; boolean httpOnly = false ; String comment = null ; String commentURL = null ; String domain = null ; String path = null ; long maxAge = Long . MIN_VALUE ; List < Integer > ports = new ArrayList < Integer > ( 2 ) ; for ( int j = i + 1 ; j < names . size ( ) ; j ++ , i ++ ) { name = names . get ( j ) ; value = values . get ( j ) ; if ( DISCARD . equalsIgnoreCase ( name ) ) { discard = true ; } else if ( CookieHeaderNames . SECURE . equalsIgnoreCase ( name ) ) { secure = true ; } else if ( CookieHeaderNames . HTTPONLY . equalsIgnoreCase ( name ) ) { httpOnly = true ; } else if ( COMMENT . equalsIgnoreCase ( name ) ) { comment = value ; } else if ( COMMENTURL . equalsIgnoreCase ( name ) ) { commentURL = value ; } else if ( CookieHeaderNames . DOMAIN . equalsIgnoreCase ( name ) ) { domain = value ; } else if ( CookieHeaderNames . PATH . equalsIgnoreCase ( name ) ) { path = value ; } else if ( CookieHeaderNames . EXPIRES . equalsIgnoreCase ( name ) ) { Date date = DateFormatter . parseHttpDate ( value ) ; if ( date != null ) { long maxAgeMillis = date . getTime ( ) - System . currentTimeMillis ( ) ; maxAge = maxAgeMillis / 1000 + ( maxAgeMillis % 1000 != 0 ? 1 : 0 ) ; } } else if ( CookieHeaderNames . MAX_AGE . equalsIgnoreCase ( name ) ) { maxAge = Integer . parseInt ( value ) ; } else if ( VERSION . equalsIgnoreCase ( name ) ) { version = Integer . parseInt ( value ) ; } else if ( PORT . equalsIgnoreCase ( name ) ) { String [ ] portList = value . split ( "," ) ; for ( String s1 : portList ) { try { ports . add ( Integer . valueOf ( s1 ) ) ; } catch ( NumberFormatException e ) { } } } else { break ; } } c . setVersion ( version ) ; c . setMaxAge ( maxAge ) ; c . setPath ( path ) ; c . setDomain ( domain ) ; c . setSecure ( secure ) ; c . setHttpOnly ( httpOnly ) ; if ( version > 0 ) { c . setComment ( comment ) ; } if ( version > 1 ) { c . setCommentUrl ( commentURL ) ; c . setPorts ( ports ) ; c . setDiscard ( discard ) ; } cookies . add ( c ) ; } return cookies ; }
Decodes the specified HTTP header value into {@link Cookie}s.

@return the decoded {@link Cookie}s