本文整理汇总了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
}