Class CookieFile
CookieAuthUtil parses.
Cookie exports arrive as files far more often than as pasted text — every browser extension that
produces them writes a cookies.txt, and the Netscape format they use is line-oriented, so a
paste through a single-line input mangles it. The parsing itself already lives in this package and
is format-tolerant; only getting the bytes to it was missing.
Decoding is byte-order-mark aware. A file redirected out of PowerShell is UTF-16LE, which decoded as UTF-8 yields text interleaved with NUL bytes — the parser then finds no cookie it recognises and the failure reads as "my cookies are bad" rather than "my file is in another encoding".
- Since:
- 0.7.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe extensions cookie exports normally carry, without a leading dot, for a host building a file picker's filter.static final longLargest cookie export accepted. -
Method Summary
-
Field Details
-
MAX_BYTES
public static final long MAX_BYTESLargest cookie export accepted. Netscape exports of a full browser profile run to tens of kilobytes; a megabyte is far past any real one and keeps a mistakenly picked archive or disk image from being read into memory.- Since:
- 0.7.0
- See Also:
-
EXTENSIONS
The extensions cookie exports normally carry, without a leading dot, for a host building a file picker's filter. Advisory only —read(Path)accepts any path, because a user who renamed their export is not wrong. Ordered most to least common.- Since:
- 0.7.0
-
-
Method Details
-
read
Readsfileas cookie text.Every failure is reported against the file's name only. The JDK's own I/O messages are the absolute path, and this message travels into a
LoginResulta host shows in its UI and writes to its log, so an access-denied on a file under a home directory would otherwise publish that directory.- Parameters:
file- the file to read- Returns:
- the file's text content, byte-order mark stripped
- Throws:
AltsException- of kindAltsFailure.Kind.INVALID_INPUTif the file is missing, is not a regular file, is larger thanMAX_BYTES, holds no text, or cannot be read; the message names the file, never its path, and no exception carrying the path rides along- Since:
- 0.7.0
-