本文整理匯總了Java中java.net.HttpCookie.hasExpired方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpCookie.hasExpired方法的具體用法?Java HttpCookie.hasExpired怎麽用?Java HttpCookie.hasExpired使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.net.HttpCookie
的用法示例。
在下文中一共展示了HttpCookie.hasExpired方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getValidCookies
import java.net.HttpCookie; //導入方法依賴的package包/類
private List<HttpCookie> getValidCookies(URI uri) {
List<HttpCookie> validCookies = new ArrayList<>();
for (URI storedUri : cookiesCache.keySet()) {
if (uriMatch(storedUri, uri)) {
validCookies.addAll(cookiesCache.get(storedUri));
}
}
Iterator<HttpCookie> it = validCookies.iterator();
while (it.hasNext()) {
HttpCookie cookie = it.next();
if (cookie.hasExpired()) {
removeFromPersistence(uri, cookie);
cookiesCache.get(uri).remove(cookie);
it.remove();
}
}
return validCookies;
}
示例2: main
import java.net.HttpCookie; //導入方法依賴的package包/類
public static void main(String... args) {
HttpCookie cookie = new HttpCookie("testCookie", "value");
cookie.setMaxAge(Integer.MIN_VALUE);
if (cookie.hasExpired()) {
throw new RuntimeException("Cookie has unexpectedly expired");
}
List<HttpCookie> cookies = HttpCookie.parse("Set-Cookie: " +
"expiredCookie=value; expires=Thu, 01 Jan 1970 00:00:00 GMT");
if (cookies.size() == 1) {
if (cookies.get(0).getMaxAge() != 0) {
throw new RuntimeException("Cookie maxAge expected to be 0");
}
} else {
throw new RuntimeException("Header was incorrectly parsed");
}
}
示例3: getInternal2
import java.net.HttpCookie; //導入方法依賴的package包/類
private <T> void getInternal2(List<HttpCookie> cookies,
Map<T, List<HttpCookie>> cookieIndex,
Comparable<T> comparator, boolean secureLink)
{
for (T index : cookieIndex.keySet()) {
if (comparator.compareTo(index) == 0) {
List<HttpCookie> indexedCookies = cookieIndex.get(index);
// check the list of cookies associated with this domain
if (indexedCookies != null) {
Iterator<HttpCookie> it = indexedCookies.iterator();
while (it.hasNext()) {
HttpCookie ck = it.next();
if (cookieJar.indexOf(ck) != -1) {
// the cookie still in main cookie store
if (!ck.hasExpired()) {
// don't add twice
if ((secureLink || !ck.getSecure()) &&
!cookies.contains(ck))
cookies.add(ck);
} else {
it.remove();
cookieJar.remove(ck);
}
} else {
// the cookie has beed removed from main store,
// so also remove it from domain indexed store
it.remove();
}
}
} // end of indexedCookies != null
} // end of comparator.compareTo(index) == 0
} // end of cookieIndex iteration
}