RSS Reader Java Library

repository·master·Indexed 41 days ago

https://github.com/w3stling/rssreader

A lightweight Java library for reading and parsing RSS and Atom feeds with zero third-party dependencies. It supports reading from URLs, files, and InputStreams, and includes specialized functionality via ItunesRssReader for podcast metadata and FeedFilter for preprocessing data.

Tokens
1.2K
Snippets
7
Records
7
Agent score
2%

What's inside RSS Reader

  1. Use Feed Filters to preprocess data

    master

    Feed filters allow you to transform or clean the raw InputStream of a feed before it is parsed. This is useful for removing invalid XML characters or applying custom preprocessing logic. To use a filter, implement the FeedFilter interface and pass it to addFeedFilter().

    RssReader reader = new RssReader();
    List<Item> items = reader.addFeedFilter(new InvalidXmlCharacterFilter())
                             .read(URL)
                             .toList();
  2. Install RSS Reader via Maven or Gradle

    master

    To use RSS Reader in your Java project, add the following dependency to your build configuration. Note that since version 3.0.0, the group ID is com.apptasticsoftware.

    Maven Add the dependency to your pom.xml:

    Gradle Add the implementation line to your build.gradle:

    <!-- Maven -->
    <dependency>
        <groupId>com.apptasticsoftware</groupId>
        <artifactId>rssreader</artifactId>
        <version>3.12.0</version>
    </dependency>
    
    <!-- Gradle -->
    dependencies {
        implementation 'com.apptasticsoftware:rssreader:3.12.0'
    }
  3. Read feeds from files or InputStreams

    master

    You can ingest feed data from local files using either an InputStream or a file URI.

    Using InputStream

    InputStream inputStream = new FileInputStream("/path/to/file");
    List<Item> items = new RssReader().read(inputStream).toList();

    Using file URI

    List<Item> items = new RssReader().read("file:/path/to/file").toList();
    // Using InputStream
    InputStream inputStream = new FileInputStream("/path/to/file");
    List<Item> items = new RssReader().read(inputStream).toList();
    
    // Using file URI
    List<Item> items = new RssReader().read("file:/path/to/file").toList();
  4. Read and sort multiple feeds

    master

    The read(List<String> urls) method allows you to process multiple feeds into a single stream. You can use ItemComparator to control the sort order of the resulting items.

    Available Comparators:

    • ItemComparator.oldestPublishedItemFirst(): Sorts by publication date (ascending).
    • ItemComparator.newestUpdatedItemFirst(): Sorts by updated date (descending).
    • ItemComparator.oldestUpdatedItemFirst(): Sorts by updated date (ascending).
    List<String> urls = List.of(URL1, URL2, URL3, URL4, URL5); 
    new RssReader().read(urls)
                   .sorted(ItemComparator.oldestPublishedItemFirst())
                   .map(Item::getTitle)
                   .forEach(System.out::println);
  5. Read an RSS or Atom feed

    master

    Use the RssReader class to read feeds from a URL. The read(URL) method returns a Stream<Item> which can be converted to a list or filtered.

    RssReader rssReader = new RssReader();
    List<Item> items = rssReader.read(URL)
                                .toList();
  6. Extract Podcast/iTunes data with ItunesRssReader

    master

    For feeds containing podcast-specific metadata, use the ItunesRssReader class. This specialized reader extracts data from iTunes-specific tags and attributes into ItunesItem objects.

    List<ItunesItem> items = new ItunesRssReader().read(URL)
                                                  .toList();
  7. Map custom RSS/Atom tags with item extensions

    master

    You can extend the standard Item object by mapping custom XML tags or attributes to existing setter methods using addItemExtension(String tagName, Consumer<Item> setter).

    List<Item> items = new RssReader()
                 .addItemExtension("dc:creator", Item::setAuthor)
                 .addItemExtension("dc:date", Item::setPubDate)
                 .read("https://lwn.net/headlines/rss")
                 .toList();