Top Description Fields Constructors Methods
java.net

pack-priv Class InMemoryCookieStore

extends Object
implements CookieStore
Class Inheritance
All Implemented Interfaces
java.net.CookieStore
Imports
java.net.URI, .CookieStore, .HttpCookie, .URISyntaxException, java.util.List, .Map, .ArrayList, .HashMap, .Collections, .Iterator, java.util.concurrent.locks.ReentrantLock

A simple in-memory java.net.CookieStore implementation
Author
Edward Wang
Since
1.6

Field Summary

Modifier and TypeField and Description
private List<HttpCookie>
private Map<String, List<HttpCookie>>
private ReentrantLock
private Map<URI, List<HttpCookie>>

Constructor Summary

AccessConstructor and Description
public
InMemoryCookieStore()

The default ctor

Method Summary

Modifier and TypeMethod and Description
public void
add(URI
the uri this cookie associated with. if null, this cookie will not be associated with an URI
uri
,
HttpCookie
the cookie to store
cookie
)

Implements java.net.CookieStore.add.

Add one cookie into cookie store.

private <T> void
addIndex(Map<T, List<HttpCookie>> indexStore, T index, HttpCookie cookie)

public List<HttpCookie>
get(URI
the uri associated with the cookies to be returned
uri
)

Implements java.net.CookieStore.get.

Get all cookies, which: 1) given uri domain-matches with, or, associated with given uri when added to the cookie store.

public List<HttpCookie>
getCookies()

Implements java.net.CookieStore.getCookies.

Get all cookies in cookie store, except those have expired

private URI
private void
getInternal1(List<HttpCookie> cookies, Map<String, List<HttpCookie>> cookieIndex, String host, boolean secureLink)

private <T> void
getInternal2(List<HttpCookie> cookies, Map<T, List<HttpCookie>> cookieIndex, Comparable<T> comparator, boolean secureLink)

public List<URI>
getURIs()

Implements java.net.CookieStore.getURIs.

Get all URIs, which are associated with at least one cookie of this cookie store.

private boolean
public boolean
remove(URI
the uri this cookie associated with. if null, the cookie to be removed is not associated with an URI when added; if not null, the cookie to be removed is associated with the given URI when added.
uri
,
HttpCookie
the cookie to remove
ck
)

Implements java.net.CookieStore.remove.

Remove a cookie from store

public boolean
removeAll()

Implements java.net.CookieStore.removeAll.

Remove all cookies in this cookie store.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cookieJarback to summary
private List<HttpCookie> cookieJar
domainIndexback to summary
private Map<String, List<HttpCookie>> domainIndex
lockback to summary
private ReentrantLock lock
uriIndexback to summary
private Map<URI, List<HttpCookie>> uriIndex

Constructor Detail

InMemoryCookieStoreback to summary
public InMemoryCookieStore()

The default ctor

Method Detail

addback to summary
public void add(URI uri, HttpCookie cookie)

Implements java.net.CookieStore.add.

Add one cookie into cookie store.

Parameters
uri:URI

Doc from java.net.CookieStore.add.

the uri this cookie associated with. if null, this cookie will not be associated with an URI

cookie:HttpCookie

Doc from java.net.CookieStore.add.

the cookie to store

addIndexback to summary
private <T> void addIndex(Map<T, List<HttpCookie>> indexStore, T index, HttpCookie cookie)
getback to summary
public List<HttpCookie> get(URI uri)

Implements java.net.CookieStore.get.

Get all cookies, which: 1) given uri domain-matches with, or, associated with given uri when added to the cookie store. 3) not expired. See RFC 2965 sec. 3.3.4 for more detail.

Parameters
uri:URI

Doc from java.net.CookieStore.get.

the uri associated with the cookies to be returned

Returns:List<HttpCookie>

Doc from java.net.CookieStore.get.

an immutable list of HttpCookie, return empty list if no cookies match the given URI

getCookiesback to summary
public List<HttpCookie> getCookies()

Implements java.net.CookieStore.getCookies.

Get all cookies in cookie store, except those have expired

Returns:List<HttpCookie>

Doc from java.net.CookieStore.getCookies.

an immutable list of http cookies; return empty list if there's no http cookie in store

getEffectiveURIback to summary
private URI getEffectiveURI(URI uri)
getInternal1back to summary
private void getInternal1(List<HttpCookie> cookies, Map<String, List<HttpCookie>> cookieIndex, String host, boolean secureLink)
getInternal2back to summary
private <T> void getInternal2(List<HttpCookie> cookies, Map<T, List<HttpCookie>> cookieIndex, Comparable<T> comparator, boolean secureLink)
getURIsback to summary
public List<URI> getURIs()

Implements java.net.CookieStore.getURIs.

Get all URIs, which are associated with at least one cookie of this cookie store.

Returns:List<URI>

Doc from java.net.CookieStore.getURIs.

an immutable list of URIs; return empty list if no cookie in this cookie store is associated with an URI

netscapeDomainMatchesback to summary
private boolean netscapeDomainMatches(String domain, String host)
removeback to summary
public boolean remove(URI uri, HttpCookie ck)

Implements java.net.CookieStore.remove.

Remove a cookie from store

Parameters
uri:URI

Doc from java.net.CookieStore.remove.

the uri this cookie associated with. if null, the cookie to be removed is not associated with an URI when added; if not null, the cookie to be removed is associated with the given URI when added.

ck:HttpCookie

Doc from java.net.CookieStore.remove.

the cookie to remove

Returns:boolean

Doc from java.net.CookieStore.remove.

true if this store contained the specified cookie

removeAllback to summary
public boolean removeAll()

Implements java.net.CookieStore.removeAll.

Remove all cookies in this cookie store.

Returns:boolean

Doc from java.net.CookieStore.removeAll.

true if this store changed as a result of the call