java.net.HttpCookie#hasExpired ( )源码实例Demo

下面列出了java.net.HttpCookie#hasExpired ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk9   文件: CookieNegativeMaxAge.java
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");
    }
}
 
源代码2 项目: NewsMe   文件: PersistentCookieStore.java
@Override
public void add(URI uri, HttpCookie cookie)
{
    String name = getCookieToken(uri, cookie);

    // Save cookie into local store, or remove if expired
    if (!cookie.hasExpired())
    {
        if (!cookies.containsKey(uri.getHost()))
            cookies.put(uri.getHost(), new ConcurrentHashMap<String, HttpCookie>());
        cookies.get(uri.getHost()).put(name, cookie);
    } else
    {
        if (cookies.containsKey(uri.toString()))
            cookies.get(uri.getHost()).remove(name);
    }

    // Save cookie into persistent store
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
    prefsWriter.putString(uri.getHost(), TextUtils.join(",", cookies.get(uri.getHost()).keySet()));
    prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableHttpCookie(cookie)));
    prefsWriter.commit();
}
 
@Override
public void add(URI uri, HttpCookie cookie) {
    String name = getCookieToken(uri, cookie);

    String host = uri.getHost();

    if (!cookie.hasExpired()) {
        if (!cookies.containsKey(host))
            cookies.put(host, new ConcurrentHashMap<String, HttpCookie>());
        cookies.get(host).put(name, cookie);
    } else {
        if (cookies.containsKey(uri.toString()))
            cookies.get(host).remove(name);
    }

    ConcurrentHashMap<String, HttpCookie> c = cookies.get(host);
    if (c == null)
        return;

    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();

    prefsWriter.putString(host, TextUtils.join(",", cookies.get(host).keySet()));
    prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableHttpCookie(cookie)));
    prefsWriter.commit();
}
 
源代码4 项目: AndroidStudyDemo   文件: PersistentCookieStore.java
@Override
public void add(URI uri, HttpCookie cookie) {
    String name = getCookieToken(uri, cookie);
    // Save cookie into local store, or remove if expired
    if (!cookie.hasExpired()) {
        if (!mCookieMap.containsKey(uri.getHost()))
            mCookieMap.put(uri.getHost(), new ConcurrentHashMap<String, HttpCookie>());
        mCookieMap.get(uri.getHost()).put(name, cookie);
    } else {
        if (mCookieMap.containsKey(uri.toString()))
            mCookieMap.get(uri.getHost()).remove(name);
    }
    // Save cookie into persistent store
    SharedPreferences.Editor prefsWriter = mCookiePrefs.edit();
    prefsWriter.putString(uri.getHost(), TextUtils.join(",", mCookieMap.get(uri.getHost()).keySet()));
    prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableHttpCookie(cookie)));
    prefsWriter.commit();
}
 
源代码5 项目: FimiX8-RE   文件: PersistentCookieStore.java
public void add(URI uri, HttpCookie cookie) {
    String name = getCookieToken(uri, cookie);
    if (!cookie.hasExpired()) {
        if (!this.cookies.containsKey(uri.getHost())) {
            this.cookies.put(uri.getHost(), new ConcurrentHashMap());
        }
        ((ConcurrentHashMap) this.cookies.get(uri.getHost())).put(name, cookie);
    } else if (this.cookies.containsKey(uri.toString())) {
        ((ConcurrentHashMap) this.cookies.get(uri.getHost())).remove(name);
    }
    Editor prefsWriter = this.cookiePrefs.edit();
    prefsWriter.putString(uri.getHost(), TextUtils.join(",", ((ConcurrentHashMap) this.cookies.get(uri.getHost())).keySet()));
    prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableHttpCookie(cookie)));
    prefsWriter.commit();
}
 
源代码6 项目: ratebeer   文件: Api.java
private boolean haveLoginCookie() {
	if (cookieManager.getCookieStore().getCookies().isEmpty())
		return false;
	boolean hasUserCookie = false, hasSessionCookie = false;
	for (HttpCookie cookie : cookieManager.getCookieStore().getCookies()) {
		if (cookie.getName().equals(COOKIE_USERID) && !TextUtils.isEmpty(cookie.getValue()) && !cookie.hasExpired())
			hasUserCookie = true;
		if (cookie.getName().equals(COOKIE_SESSIONID) && !TextUtils.isEmpty(cookie.getValue()) && !cookie.hasExpired())
			hasSessionCookie = true;
	}
	return hasUserCookie && hasSessionCookie;
}
 
源代码7 项目: dragonwell8_jdk   文件: InMemoryCookieStore.java
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
}
 
源代码8 项目: TencentKona-8   文件: InMemoryCookieStore.java
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
}
 
源代码9 项目: jdk8u60   文件: InMemoryCookieStore.java
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
}
 
源代码10 项目: JDKSourceCode1.8   文件: InMemoryCookieStore.java
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
}
 
源代码11 项目: openjdk-jdk8u   文件: InMemoryCookieStore.java
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
}
 
源代码12 项目: DaVinci   文件: PersistentCookieStore.java
private List<HttpCookie> getValidCookies(URI uri) {
    List<HttpCookie> targetCookies = new ArrayList<HttpCookie>();
    // If the stored URI does not have a path then it must match any URI in
    // the same domain
    for (URI storedUri : allCookies.keySet()) {
        // Check ith the domains match according to RFC 6265
        if (checkDomainsMatch(storedUri.getHost(), uri.getHost())) {
            // Check if the paths match according to RFC 6265
            if (checkPathsMatch(storedUri.getPath(), uri.getPath())) {
                targetCookies.addAll(allCookies.get(storedUri));
            }
        }
    }

    // Check it there are expired cookies and remove them
    if (!targetCookies.isEmpty()) {
        List<HttpCookie> cookiesToRemoveFromPersistence = new ArrayList<HttpCookie>();
        for (Iterator<HttpCookie> it = targetCookies.iterator(); it
                .hasNext(); ) {
            HttpCookie currentCookie = it.next();
            if (currentCookie.hasExpired()) {
                cookiesToRemoveFromPersistence.add(currentCookie);
                it.remove();
            }
        }

        if (!cookiesToRemoveFromPersistence.isEmpty()) {
            removeFromPersistence(uri, cookiesToRemoveFromPersistence);
        }
    }
    return targetCookies;
}
 
源代码13 项目: Bytecoder   文件: InMemoryCookieStore.java
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 been 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
}
 
源代码14 项目: openjdk-jdk9   文件: InMemoryCookieStore.java
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
}
 
源代码15 项目: jdk8u-jdk   文件: InMemoryCookieStore.java
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
}
 
源代码16 项目: Java8CN   文件: InMemoryCookieStore.java
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
}
 
源代码17 项目: JavaSCR   文件: mutableInputs.java
public void useMutableInput(HttpCookie cookie) {
	Objects.requireNonNull(cookie, "cookie cannot be null"); //$NON-NLS-1$
	// Check whether cookie has expired
	if (cookie.hasExpired()) {
		throw new IllegalArgumentException();
	}

	// Cookie may have expired since time of check
	doLogic(cookie);
}
 
源代码18 项目: openjdk-8-source   文件: InMemoryCookieStore.java
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
}
 
源代码19 项目: openjdk-8   文件: InMemoryCookieStore.java
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
}
 
源代码20 项目: jdk8u-jdk   文件: InMemoryCookieStore.java
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
}