Package java.net
Interface CookieStore
public interface CookieStore
A CookieStore object is a repository for cookies.
CookieManager will store cookies of every incoming HTTP response into
CookieStore, and retrieve cookies for every outgoing HTTP request.Expired
HttpCookies should be removed from this store by themselves.
- Since:
- 1.6
-
Method Summary
Modifier and Type Method Description voidadd(URI uri, HttpCookie cookie)Saves a HTTP cookie to this store.List<HttpCookie>get(URI uri)Retrieves cookies that match the specified URI.List<HttpCookie>getCookies()Get all cookies in cookie store which are not expired.List<URI>getURIs()Get a set of URIs, which is composed of associated URI with all the cookies in the store.booleanremove(URI uri, HttpCookie cookie)Remove the specified cookie from the store.booleanremoveAll()Clear this cookie store.
-
Method Details
-
add
Saves a HTTP cookie to this store. This is called for every incoming HTTP response. A cookie may or may not has an associated URI. If not, the cookie's domain and path attribute will show cradleland. If there is an associated URI and no domain and path attribute are speicifed for the cookie, the given URI will indicate where this cookie comes from. If a cookie corresponding to the given URI already exists, then it is replaced with the new one.- Parameters:
uri- the uri associated with the specified cookie. A null value indicates the cookie is not associated with a URIcookie- the cookie to be stored
-
get
Retrieves cookies that match the specified URI. Return not expired cookies. For every outgoing HTTP request, this method will be called.- Parameters:
uri- the uri this cookie associated with. If null, this cookie will not be associated with an URI- Returns:
- an immutable list of HttpCookies, return empty list if no cookies match the given URI
- Throws:
NullPointerException- if uri is null
-
getCookies
List<HttpCookie> getCookies()Get all cookies in cookie store which are not expired.- Returns:
- an empty list if there's no http cookie in store, or an immutable list of cookies
-
getURIs
Get a set of URIs, which is composed of associated URI with all the cookies in the store.- Returns:
- zero-length list if no cookie in the store is associated with any URIs, otherwise an immutable list of URIs.
-
remove
Remove the specified cookie from the store.- Parameters:
uri- the uri associated with the specified cookie. If the cookie is not associated with an URI when added, uri should be null; otherwise the uri should be non-null.cookie- the cookie to be removed- Returns:
- true if the specified cookie is contained in this store and removed successfully
-
removeAll
boolean removeAll()Clear this cookie store.- Returns:
- true if any cookies were removed as a result of this call.
-