當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpCookie.getMaxAge方法代碼示例

本文整理匯總了Java中java.net.HttpCookie.getMaxAge方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpCookie.getMaxAge方法的具體用法?Java HttpCookie.getMaxAge怎麽用?Java HttpCookie.getMaxAge使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.HttpCookie的用法示例。


在下文中一共展示了HttpCookie.getMaxAge方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: of

import java.net.HttpCookie; //導入方法依賴的package包/類
/**
 * Create a new SerializableHttpCookie from a HttpCookie
 *
 * @param cookie An original cookie
 * @return SerializableHttpCookie that have same contents
 */
@NotNull
public static SerializableHttpCookie of(@NotNull HttpCookie cookie) {
    SerializableHttpCookie newCookie = new SerializableHttpCookie();
    newCookie.name = cookie.getName();
    newCookie.value = cookie.getValue();
    newCookie.comment = cookie.getComment();
    newCookie.commentURL = cookie.getCommentURL();
    newCookie.toDiscard = cookie.getDiscard();
    newCookie.domain = cookie.getDomain();
    newCookie.maxAge = cookie.getMaxAge();
    newCookie.path = cookie.getPath();
    newCookie.portlist = cookie.getPortlist();
    newCookie.secure = cookie.getSecure();
    newCookie.version = cookie.getVersion();

    // for Android (API level 24)
    // https://developer.android.com/reference/java/net/HttpCookie.html#isHttpOnly()
    try {
        newCookie.httpOnly = cookie.isHttpOnly();
    } catch (NoSuchMethodError e) {
        newCookie.httpOnly = false;
    }

    return newCookie;
}
 
開發者ID:emoji-gen,項目名稱:bottler,代碼行數:32,代碼來源:SerializableHttpCookie.java

示例2: CookieEntity

import java.net.HttpCookie; //導入方法依賴的package包/類
public CookieEntity(URI uri, HttpCookie cookie) {
    this.uri = uri == null ? null : uri.toString();
    this.name = cookie.getName();
    this.value = cookie.getValue();
    this.comment = cookie.getComment();
    this.commentURL = cookie.getCommentURL();
    this.discard = cookie.getDiscard();
    this.domain = cookie.getDomain();
    long maxAge = cookie.getMaxAge();
    if (maxAge != -1L && maxAge > 0) {
        this.expiry = (maxAge * 1000L) + System.currentTimeMillis();
        if (this.expiry < 0L) { // 計算溢出?
            this.expiry = MAX_EXPIRY;
        }
    } else {
        this.expiry = -1L;
    }
    this.path = cookie.getPath();
    if (!TextUtils.isEmpty(path) && path.length() > 1 && path.endsWith("/")) {
        this.path = path.substring(0, path.length() - 1);
    }
    this.portList = cookie.getPortlist();
    this.secure = cookie.getSecure();
    this.version = cookie.getVersion();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:CookieEntity.java

示例3: fromString

import java.net.HttpCookie; //導入方法依賴的package包/類
@Override
public NewCookie fromString(final String value) {
    if (value == null || value.isEmpty()) {
        return null;
    }

    final List<HttpCookie> httpCookies = HttpCookie.parse(value);
    final HttpCookie httpCookie = httpCookies.get(0);
    return new NewCookie(
            httpCookie.getName(),
            httpCookie.getValue(),
            httpCookie.getPath(),
            httpCookie.getDomain(),
            httpCookie.getVersion(),
            httpCookie.getComment(),
            (int) httpCookie.getMaxAge(),
            null,
            httpCookie.getSecure(),
            httpCookie.isHttpOnly());
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:21,代碼來源:MinijaxNewCookieDelegate.java

示例4: add

import java.net.HttpCookie; //導入方法依賴的package包/類
/**
 * Add one cookie into cookie store.
 */
public void add(URI uri, HttpCookie cookie) {
    // pre-condition : argument can't be null
    if (cookie == null) {
        throw new NullPointerException("cookie is null");
    }


    lock.lock();
    try {
        // remove the ole cookie if there has had one
        cookieJar.remove(cookie);

        // add new cookie if it has a non-zero max-age
        if (cookie.getMaxAge() != 0) {
            cookieJar.add(cookie);
            // and add it to domain index
            if (cookie.getDomain() != null) {
                addIndex(domainIndex, cookie.getDomain(), cookie);
            }
            if (uri != null) {
                // add it to uri index, too
                addIndex(uriIndex, getEffectiveURI(uri), cookie);
            }
        }
    } finally {
        lock.unlock();
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:32,代碼來源:InMemoryCookieStore.java

示例5: add

import java.net.HttpCookie; //導入方法依賴的package包/類
public void add(final URI uri, final HttpCookie cookie) {
    if (cookie.getMaxAge() == 0L) {
        cookie.setMaxAge(-1L);
    }
    delegateCS.add(uri, cookie);
}
 
開發者ID:optimatika,項目名稱:ojAlgo-finance,代碼行數:7,代碼來源:YahooSymbol.java


注:本文中的java.net.HttpCookie.getMaxAge方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。