java.lang.Object
net.i2p.router.news.PersistNews

class PersistNewsextends Object
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 Details

  • Constructor Details

    • PersistNews

      PersistNews()
      Never instantiated; every operation on this class is static.
  • Method Details

    • store

      public static boolean store(I2PAppContext ctx, List<Node> entries)
      Store each entry. Old entries are always overwritten, as they may change even without the updated date changing.
      Parameters:
      ctx - the router context
      entries - each one should be "entry" at the root
      Returns:
      true if any new entry was written (not if changed)
    • load

      public static List<NewsEntry> load(I2PAppContext ctx)
      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:
      ctx - the router context
      Returns:
      non-null, sorted by updated date, newest first
    • extract

      private static NewsEntry extract(Node entry)
      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

      public static boolean delete(I2PAppContext ctx, NewsEntry entry)
      Unused for now, as we don't have any way to remember it's deleted.
      Parameters:
      ctx - the router context
      entry - 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

      private static String idToName(I2PAppContext ctx, String id)
      Non-null.
      Parameters:
      ctx - the context whose SHA-256 implementation hashes the id
      id - 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