java.lang.Object
net.i2p.router.news.PersistNews
Handles persistent storage and retrieval of news entries to/from disk.
Manages individual news entries stored in separate compressed XML files named with UUID-based file names. Provides atomic write operations and compressed storage for efficient disk usage and data integrity.
Supports loading of news collections with proper sorting, validation, and error handling. Includes utilities for file naming based on content hashes and secure file operations.
Field Summary
FieldsConstructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionstatic booleandelete(I2PAppContext ctx, NewsEntry entry) Unused for now, as we don't have any way to remember it's deleted.private static NewsEntryThis does not check for any missing values.private static StringidToName(I2PAppContext ctx, String id) Non-null.load(I2PAppContext ctx) This does not check for any missing values.static booleanstore(I2PAppContext ctx, List<Node> entries) Store each entry.
Field Details
DIR
Directory the saved news items live in.- See Also:
PFX
SFX
XML_START
Constructor Details
PersistNews
PersistNews()Never instantiated; every operation on this class is static.
Method Details
store
Store each entry. Old entries are always overwritten, as they may change even without the updated date changing.- Parameters:
ctx- the router contextentries- each one should be "entry" at the root- Returns:
- true if any new entry was written (not if changed)
load
This does not check for any missing values. Any fields in any NewsEntry may be null. Content is not sanitized byNewsXMLParserhere, do that before storing.- Parameters:
ctx- the router context- Returns:
- non-null, sorted by updated date, newest first
extract
This does not check for any missing values. Any fields in any NewsEntry may be null. Content is not sanitized by NewsXMLParser here, do that before storing.- Parameters:
entry- the news XML node whose title, link and other fields are read- Returns:
- non-null, throws on errors
delete
Unused for now, as we don't have any way to remember it's deleted.- Parameters:
ctx- the router contextentry- the news entry to delete- Returns:
- true if the file was deleted; false if entry has no id or the file is already gone
idToName
Non-null.- Parameters:
ctx- the context whose SHA-256 implementation hashes the idid- non-null- Returns:
- the file name for the entry: news- prefix, then Base64 of the SHA-256 of the UTF-8 id, then the .xml.gz suffix