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

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

源代码1 项目: Nimingban   文件: TransportableHttpCookie.java
public static List<TransportableHttpCookie> from(URL url, List<HttpCookieWithId> list) {
    List<TransportableHttpCookie> result = new ArrayList<>(list.size());
    for (HttpCookieWithId hcwi : list) {
        HttpCookie cookie = hcwi.httpCookie;
        TransportableHttpCookie thc = new TransportableHttpCookie();
        thc.name = cookie.getName();
        thc.value = cookie.getValue();
        thc.comment = cookie.getComment();
        thc.commentURL = cookie.getCommentURL();
        thc.discard = cookie.getDiscard();
        thc.domain = cookie.getDomain();
        thc.maxAge = cookie.getMaxAge();
        thc.path = cookie.getPath();
        thc.portList = cookie.getPortlist();
        thc.secure = cookie.getSecure();
        thc.version = cookie.getVersion();
        thc.url = url.toString();
        result.add(thc);
    }
    return result;
}
 
源代码2 项目: rawhttp   文件: FileCookieJar.java
private int flush() throws IOException {
    int count = 0;

    try (FileWriter writer = new FileWriter(file)) {
        for (Map.Entry<URI, List<HttpCookie>> entry : persistentCookies.entrySet()) {
            URI uri = entry.getKey();
            writer.write(uri.toString());
            writer.write('\n');
            for (HttpCookie httpCookie : entry.getValue()) {
                long maxAge = httpCookie.getMaxAge();
                if (maxAge > 0 && !httpCookie.getDiscard()) {
                    long expiresAt = maxAge + System.currentTimeMillis() / 1000L;
                    writer.write(' ');
                    writeCookie(writer, httpCookie, expiresAt);
                    writer.write('\n');
                    count++;
                }
            }
        }
    }
    return count;
}
 
源代码3 项目: NoHttp   文件: CookieEntity.java
/**
 * Cookie building database entities.
 *
 * @param uri    cookie corresponding uri.
 * @param cookie cookie.
 */
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 != -1 && maxAge > 0) {
        this.expiry = (maxAge * 1000L) + System.currentTimeMillis();
        if (this.expiry < 0L) // 溢出
            this.expiry = HeaderUtils.getMaxExpiryMillis();
    } 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();
}
 
源代码4 项目: httplite   文件: PersistentCookieStore.java
/**
 * 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
            addIndex(domainIndex, cookie.getDomain(), cookie);
            // add it to uri index, too
            addIndex(uriIndex, getEffectiveURI(uri), cookie);
        }
    } finally {
        lock.unlock();
    }
    storeCookies();
}
 
/**
 * 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();
    }
}
 
源代码6 项目: jdk8u_jdk   文件: InMemoryCookieStore.java
/**
 * 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();
    }
}
 
源代码7 项目: JDKSourceCode1.8   文件: InMemoryCookieStore.java
/**
 * 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();
    }
}
 
源代码8 项目: Kalle   文件: Cookie.java
public static Cookie toCookie(String url, HttpCookie httpCookie) {
    Cookie cookie = new Cookie();
    cookie.setUrl(url);
    cookie.setName(httpCookie.getName());
    cookie.setValue(httpCookie.getValue());
    cookie.setComment(httpCookie.getComment());
    cookie.setCommentURL(httpCookie.getCommentURL());
    cookie.setDiscard(httpCookie.getDiscard());
    cookie.setDomain(httpCookie.getDomain());
    long maxAge = httpCookie.getMaxAge();
    if (maxAge > 0) {
        long expiry = (maxAge * 1000L) + System.currentTimeMillis();
        if (expiry < 0L) {
            expiry = System.currentTimeMillis() + 100L * 365L * 24L * 60L * 60L * 1000L;
        }
        cookie.setExpiry(expiry);
    } else if (maxAge < 0) {
        cookie.setExpiry(-1);
    } else {
        cookie.setExpiry(0);
    }

    String path = httpCookie.getPath();
    if (!TextUtils.isEmpty(path) && path.length() > 1 && path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
    }
    cookie.setPath(path);
    cookie.setPortList(httpCookie.getPortlist());
    cookie.setSecure(httpCookie.getSecure());
    cookie.setVersion(httpCookie.getVersion());
    return cookie;
}
 
源代码9 项目: openjdk-jdk8u   文件: InMemoryCookieStore.java
/**
 * 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();
    }
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: InMemoryCookieStore.java
/**
 * 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();
    }
}
 
源代码11 项目: Bytecoder   文件: InMemoryCookieStore.java
/**
 * 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();
    }
}
 
源代码12 项目: jdk-1.7-annotated   文件: InMemoryCookieStore.java
/**
 * 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();
    }
}
 
源代码13 项目: jdk8u-dev-jdk   文件: InMemoryCookieStore.java
/**
 * 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();
    }
}
 
源代码14 项目: rawhttp   文件: FileCookieJar.java
@Override
public void add(URI uri, HttpCookie cookie) {
    inMemory.add(uri, cookie);
    if (cookie.getMaxAge() > 0) {
        persistentCookies.computeIfAbsent(uri, (u) -> new ArrayList<>(4)).add(cookie);
        flushPolicy.onUpdate(inMemory);
    }
}
 
源代码15 项目: jdk8u-jdk   文件: InMemoryCookieStore.java
/**
 * 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();
    }
}
 
源代码16 项目: hottub   文件: InMemoryCookieStore.java
/**
 * 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();
    }
}
 
源代码17 项目: openjdk-8-source   文件: InMemoryCookieStore.java
/**
 * 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();
    }
}
 
源代码18 项目: http-builder-ng   文件: NonBlockingCookieStore.java
public void add(final URI uri, final HttpCookie cookie) {
    if(cookie.getMaxAge() == 0) {
        return;
    }

    if(cookie.getDomain() != null) {
        add(new DomainKey(cookie), cookie);
    }
    
    if(uri != null) {
        add(new UriKey(uri, cookie), cookie);
    }
}
 
源代码19 项目: http-builder-ng   文件: FileBackedCookieStore.java
@Override
public void add(final URI uri, final HttpCookie cookie) {
    assertLive();
    final Key key = Key.make(uri, cookie);
    add(key, cookie);
    if(cookie.getMaxAge() != -1L) {
        store(key, cookie);
    }
}
 
源代码20 项目: Nimingban   文件: HttpCookieWithId.java
public HttpCookieWithId(long id, HttpCookie httpCookie) {
    this.id = id;
    this.httpCookie = httpCookie;
    mMaxAge = httpCookie.getMaxAge();
    mWhenCreated = System.currentTimeMillis();
}