It will only load the cookies lazily, i.e. before calling
getCookies(boolean) the file is not evaluated. This class also
allows persisting cookies in that file format.
In general this class is not thread-safe. So any consumer needs to take care of synchronization!
NetscapeCookieFileCache
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private Set | |
| private final Instant | |
| private byte[] | |
| private static final String | |
| private static final String | |
| private static final int | LOCK_ACQUIRE_MAX_RETRY_COUNT
Maximum number of retries to acquire the lock for writing to the underlying file. |
| private static final int | LOCK_ACQUIRE_RETRY_SLEEP
Sleep time in milliseconds between retries to acquire the lock for writing to the underlying file. |
| private static final Logger | |
| private final Path | |
| private FileSnapshot |
| Access | Constructor and Description |
|---|---|
| public | |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public Set | Returns: all cookies (may contain session cookies as well). This does not return a copy of the list but rather the original one. Every addition to the returned list can afterwards be persisted viawrite(URL). Errors in the underlying file will not lead
to exceptions but rather to an empty set being returned and the
underlying error being logged.if refresh)true updates the list from the underlying cookie
file if it has been modified since the last read otherwise
returns the current transient state. In case the cookie file
has never been read before will always read from the
underlying file disregarding the value of this parameter.Return all cookies from the underlying cookie file. |
| private byte[] | Returns: the file contents in case the file has been modified since the last access, otherwisenullRead the underlying file and return its content but only in case it has been modified since the last access. |
| public Path | |
| private static byte[] | |
| pack-priv static Set | Returns: the merged cookiesfirst set of cookies cookies1, Set<HttpCookie> second set of cookies cookies2)Merge the given sets in the following way. |
| private static Set | Returns: the set of parsed cookies from the given file (even expired ones). If there is more than one cookie with the same name in this file the last one overwrites the first one!the file content to parse input, Instant cookie creation time; used to calculate the maxAge based on
the expiration date given within the file createdAt)Parses the given file and extracts all cookie information from it. |
| private static HttpCookie | |
| public void | write(URL
url for which to write the cookies (important to derive
default values for non-explicitly set attributes) url)Writes all the cookies being maintained in the set being returned by
|
| pack-priv static void | write(Writer
the writer to use to persist the cookies writer, Collection<HttpCookie> the cookies to write into the file cookies, URL the url for which to write the cookie (to derive the default
values for certain cookie attributes) url, Instant cookie creation time; used to calculate a cookie's expiration
time createdAt)Writes the given cookies to the file in the Netscape Cookie File Format (also used by curl). |
| private static void |
| COLUMN_SEPARATOR | back to summary |
|---|---|
| private static final String COLUMN_SEPARATOR | |
| cookies | back to summary |
|---|---|
| private Set<HttpCookie> cookies | |
| createdAt | back to summary |
|---|---|
| private final Instant createdAt | |
| hash | back to summary |
|---|---|
| private byte[] hash | |
| HTTP_ONLY_PREAMBLE | back to summary |
|---|---|
| private static final String HTTP_ONLY_PREAMBLE | |
| LINE_SEPARATOR | back to summary |
|---|---|
| private static final String LINE_SEPARATOR | |
| LOCK_ACQUIRE_MAX_RETRY_COUNT | back to summary |
|---|---|
| private static final int LOCK_ACQUIRE_MAX_RETRY_COUNT Maximum number of retries to acquire the lock for writing to the underlying file. | |
| LOCK_ACQUIRE_RETRY_SLEEP | back to summary |
|---|---|
| private static final int LOCK_ACQUIRE_RETRY_SLEEP Sleep time in milliseconds between retries to acquire the lock for writing to the underlying file. | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| path | back to summary |
|---|---|
| private final Path path | |
| snapshot | back to summary |
|---|---|
| private FileSnapshot snapshot | |
| NetscapeCookieFile | back to summary |
|---|---|
public NetscapeCookieFile(Path path)
| |
| NetscapeCookieFile | back to summary |
|---|---|
| pack-priv NetscapeCookieFile(Path path, Instant createdAt) | |
| getCookies | back to summary |
|---|---|
| public Set Return all cookies from the underlying cookie file.
| |
| getFileContentIfModified | back to summary |
|---|---|
| private byte[] getFileContentIfModified() throws IOException Read the underlying file and return its content but only in case it has been modified since the last access.
Internally calculates the hash and maintains
| |
| getPath | back to summary |
|---|---|
| public Path getPath() Path to the underlying cookie file.
| |
| hash | back to summary |
|---|---|
| private static byte[] hash(final byte[] in) | |
| mergeCookies | back to summary |
|---|---|
| pack-priv static Set Merge the given sets in the following way. All cookies from
| |
| parseCookieFile | back to summary |
|---|---|
| private static Set Parses the given file and extracts all cookie information from it.
| |
| parseLine | back to summary |
|---|---|
| private static HttpCookie parseLine(String line, Instant createdAt) | |
| write | back to summary |
|---|---|
| public void write(URL url) throws IOException, InterruptedException Writes all the cookies being maintained in the set being returned by
Session-cookies will not be persisted.
| |
| write | back to summary |
|---|---|
| pack-priv static void write(Writer writer, Collection<HttpCookie> cookies, URL url, Instant createdAt) throws IOException Writes the given cookies to the file in the Netscape Cookie File Format (also used by curl).
| |
| writeCookie | back to summary |
|---|---|
| private static void writeCookie(Writer writer, HttpCookie cookie, URL url, Instant createdAt) throws IOException | |