FileDocCategorySizeDatePackage
BasicCookieStore.javaAPI DocAndroid 1.5 API5339Wed May 06 22:41:10 BST 2009org.apache.http.impl.client

BasicCookieStore

public class BasicCookieStore extends Object implements CookieStore
Default implementation of {@link CookieStore}
author
Remy Maucherat
author
Rodney Waldhoff
author
Jeff Dever
author
Sean C. Sullivan
author
Michael Becke
author
Oleg Kalnichevski
author
Mike Bowler
author
Adrian Sutton
since
4.0

Fields Summary
private final ArrayList
cookies
private final Comparator
cookieComparator
Constructors Summary
public BasicCookieStore()
Default constructor.

        super();
        this.cookies = new ArrayList<Cookie>();
        this.cookieComparator = new CookieIdentityComparator();
    
Methods Summary
public synchronized voidaddCookie(org.apache.http.cookie.Cookie cookie)
Adds an {@link Cookie HTTP cookie}, replacing any existing equivalent cookies. If the given cookie has already expired it will not be added, but existing values will still be removed.

param
cookie the {@link Cookie cookie} to be added
see
#addCookies(Cookie[])

        if (cookie != null) {
            // first remove any old cookie that is equivalent
            for (Iterator<Cookie> it = cookies.iterator(); it.hasNext();) {
                if (cookieComparator.compare(cookie, it.next()) == 0) {
                    it.remove();
                    break;
                }
            }
            if (!cookie.isExpired(new Date())) {
                cookies.add(cookie);
            }
        }
    
public synchronized voidaddCookies(org.apache.http.cookie.Cookie[] cookies)
Adds an array of {@link Cookie HTTP cookies}. Cookies are added individually and in the given array order. If any of the given cookies has already expired it will not be added, but existing values will still be removed.

param
cookies the {@link Cookie cookies} to be added
see
#addCookie(Cookie)

        if (cookies != null) {
            for (Cookie cooky : cookies) {
                this.addCookie(cooky);
            }
        }
    
public synchronized voidclear()
Clears all cookies.

        cookies.clear();
    
public synchronized booleanclearExpired(java.util.Date date)
Removes all of {@link Cookie cookies} in this HTTP state that have expired by the specified {@link java.util.Date date}.

return
true if any cookies were purged.
see
Cookie#isExpired(Date)

        if (date == null) {
            return false;
        }
        boolean removed = false;
        for (Iterator<Cookie> it = cookies.iterator(); it.hasNext();) {
            if (it.next().isExpired(date)) {
                it.remove();
                removed = true;
            }
        }
        return removed;
    
public synchronized java.util.ListgetCookies()
Returns an immutable array of {@link Cookie cookies} that this HTTP state currently contains.

return
an array of {@link Cookie cookies}.

        return Collections.unmodifiableList(this.cookies);
    
public java.lang.StringtoString()

        return cookies.toString();