Path: blob/master/src/java.base/share/classes/java/net/CookieStore.java
41152 views
/*1* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.net;2627import java.util.List;28import java.util.Map;2930/**31* A CookieStore object represents a storage for cookie. Can store and retrieve32* cookies.33*34* <p>{@link CookieManager} will call {@code CookieStore.add} to save cookies35* for every incoming HTTP response, and call {@code CookieStore.get} to36* retrieve cookie for every outgoing HTTP request. A CookieStore37* is responsible for removing HttpCookie instances which have expired.38*39* @author Edward Wang40* @since 1.641*/42public interface CookieStore {43/**44* Adds one HTTP cookie to the store. This is called for every45* incoming HTTP response.46*47* <p>A cookie to store may or may not be associated with an URI. If it48* is not associated with an URI, the cookie's domain and path attribute49* will indicate where it comes from. If it is associated with an URI and50* its domain and path attribute are not specified, given URI will indicate51* where this cookie comes from.52*53* <p>If a cookie corresponding to the given URI already exists,54* then it is replaced with the new one.55*56* @param uri the uri this cookie associated with.57* if {@code null}, this cookie will not be associated58* with an URI59* @param cookie the cookie to store60*61* @throws NullPointerException if {@code cookie} is {@code null}62*63* @see #get64*65*/66public void add(URI uri, HttpCookie cookie);676869/**70* Retrieve cookies associated with given URI, or whose domain matches the71* given URI. Only cookies that have not expired are returned.72* This is called for every outgoing HTTP request.73*74* @return an immutable list of HttpCookie,75* return empty list if no cookies match the given URI76*77* @param uri the uri associated with the cookies to be returned78*79* @throws NullPointerException if {@code uri} is {@code null}80*81* @see #add82*83*/84public List<HttpCookie> get(URI uri);858687/**88* Get all not-expired cookies in cookie store.89*90* @return an immutable list of http cookies;91* return empty list if there's no http cookie in store92*/93public List<HttpCookie> getCookies();949596/**97* Get all URIs which identify the cookies in this cookie store.98*99* @return an immutable list of URIs;100* return empty list if no cookie in this cookie store101* is associated with an URI102*/103public List<URI> getURIs();104105106/**107* Remove a cookie from store.108*109* @param uri the uri this cookie associated with.110* if {@code null}, the cookie to be removed is not associated111* with an URI when added; if not {@code null}, the cookie112* to be removed is associated with the given URI when added.113* @param cookie the cookie to remove114*115* @return {@code true} if this store contained the specified cookie116*117* @throws NullPointerException if {@code cookie} is {@code null}118*/119public boolean remove(URI uri, HttpCookie cookie);120121122/**123* Remove all cookies in this cookie store.124*125* @return {@code true} if this store changed as a result of the call126*/127public boolean removeAll();128}129130131