Class NetscapeCookieFile
- java.lang.Object
-
- org.eclipse.jgit.internal.transport.http.NetscapeCookieFile
-
public final class NetscapeCookieFile extends Object
Wraps all cookies persisted in a Netscape Cookie File Format being referenced via the git config http.cookieFile.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!
-
-
Constructor Summary
Constructors Constructor Description NetscapeCookieFile(Path path)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<HttpCookie>
getCookies(boolean refresh)
Return all cookies from the underlying cookie file.Path
getPath()
Path to the underlying cookie file.void
write(URL url)
Writes all the cookies being maintained in the set being returned bygetCookies(boolean)
to the underlying file.
-
-
-
Constructor Detail
-
NetscapeCookieFile
public NetscapeCookieFile(Path path)
- Parameters:
path
- where to find the cookie file
-
-
Method Detail
-
getPath
public Path getPath()
Path to the underlying cookie file.- Returns:
- the path
-
getCookies
public Set<HttpCookie> getCookies(boolean refresh)
Return all cookies from the underlying cookie file.- Parameters:
refresh
- iftrue
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.- 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 via
write(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.
-
write
public void write(URL url) throws IOException, InterruptedException
Writes all the cookies being maintained in the set being returned bygetCookies(boolean)
to the underlying file.Session-cookies will not be persisted.
- Parameters:
url
- url for which to write the cookies (important to derive default values for non-explicitly set attributes)- Throws:
IOException
- if the underlying cookie file could not be read or written or a problem with the lock fileInterruptedException
- if the thread is interrupted while waiting for the lock
-
-