Interface CookieStore
public interface CookieStore
CookieManager
will call CookieStore.add
to save cookies for every incoming HTTP response, and call CookieStore.get
to retrieve cookie for every outgoing HTTP request. A CookieStore is responsible for removing HttpCookie instances which have expired.
- Since:
- 1.6
Method Summary
Modifier and Type | Method | Description |
---|---|---|
void |
add |
Adds one HTTP cookie to the store. |
List<HttpCookie> |
get |
Retrieve cookies associated with given URI, or whose domain matches the given URI. |
List<HttpCookie> |
getCookies() |
Get all not-expired cookies in cookie store. |
List<URI> |
getURIs() |
Get all URIs which identify the cookies in this cookie store. |
boolean |
remove |
Remove a cookie from store. |
boolean |
removeAll() |
Remove all cookies in this cookie store. |
Method Details
add
void add(URI uri, HttpCookie cookie)
A cookie to store may or may not be associated with an URI. If it is not associated with an URI, the cookie's domain and path attribute will indicate where it comes from. If it is associated with an URI and its domain and path attribute are not specified, 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 this cookie associated with. ifnull
, this cookie will not be associated with an URI -
cookie
- the cookie to store - Throws:
-
NullPointerException
- ifcookie
isnull
- See Also:
get
List<HttpCookie> get(URI uri)
- Parameters:
-
uri
- the uri associated with the cookies to be returned - Returns:
- an immutable list of HttpCookie, return empty list if no cookies match the given URI
- Throws:
-
NullPointerException
- ifuri
isnull
- See Also:
getCookies
List<HttpCookie> getCookies()
- Returns:
- an immutable list of http cookies; return empty list if there's no http cookie in store
getURIs
List<URI> getURIs()
- Returns:
- an immutable list of URIs; return empty list if no cookie in this cookie store is associated with an URI
remove
boolean remove(URI uri, HttpCookie cookie)
- Parameters:
-
uri
- the uri this cookie associated with. ifnull
, the cookie to be removed is not associated with an URI when added; if notnull
, the cookie to be removed is associated with the given URI when added. -
cookie
- the cookie to remove - Returns:
-
true
if this store contained the specified cookie - Throws:
-
NullPointerException
- ifcookie
isnull
removeAll
boolean removeAll()
- Returns:
-
true
if this store changed as a result of the call
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/net/CookieStore.html