Class NvdCveClient

  • All Implemented Interfaces:
    PagedDataSource<DefCveItem>, java.lang.AutoCloseable, java.util.Iterator<java.util.Collection<DefCveItem>>

    public class NvdCveClient
    extends java.lang.Object
    implements PagedDataSource<DefCveItem>
    A simple client for the NVD CVE API. Use the NvdCveClientBuilder with the desired filters to build the client and then iterate over the results:
     try (NvdCveClient api = NvdCveClientBuilder.aNvdCveApi().build()) {
         while (api.hasNext()) {
             Collection<DefCveItem> items = api.next();
         }
     }
     
    See Also:
    NVD CVE API
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Cleanup allocated resources.
      int getLastStatusCode()
      Returns the last HTTP Status Code.
      java.time.ZonedDateTime getLastUpdated()
      Returns the latest updated date.
      int getTotalAvailable()
      Only available after the first call to `next()`; returns the total number of records that will be returned.
      boolean hasNext()
      Returns true if there are more records available; otherwise false.
      java.util.Collection<DefCveItem> next()
      Retrieves the next entry.
      protected int parseResultsPerPage​(java.lang.String msg)
      Attempts to parse the resultsPerPage error message to determine the maximum number of results per page.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining, remove
    • Method Detail

      • getTotalAvailable

        public int getTotalAvailable()
        Only available after the first call to `next()`; returns the total number of records that will be returned.
        Specified by:
        getTotalAvailable in interface PagedDataSource<DefCveItem>
        Returns:
        the total number of records that will be returned
      • close

        public void close()
        Description copied from interface: PagedDataSource
        Cleanup allocated resources.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface PagedDataSource<DefCveItem>
      • hasNext

        public boolean hasNext()
        Description copied from interface: PagedDataSource
        Returns true if there are more records available; otherwise false.
        Specified by:
        hasNext in interface java.util.Iterator<java.util.Collection<DefCveItem>>
        Specified by:
        hasNext in interface PagedDataSource<DefCveItem>
        Returns:
        true if there are more records available; otherwise false.
      • next

        public java.util.Collection<DefCveItem> next()

        Retrieves the next entry. Note that even if `hasNext()` returns true it is possible that `next()` will return null. This will generally only occur on the very first call.

        Specified by:
        next in interface java.util.Iterator<java.util.Collection<DefCveItem>>
        Specified by:
        next in interface PagedDataSource<DefCveItem>
        Returns:
        the next collection of CVE entries
      • parseResultsPerPage

        protected int parseResultsPerPage​(java.lang.String msg)
        Attempts to parse the resultsPerPage error message to determine the maximum number of results per page.
        Parameters:
        msg - the error message from the NVD
        Returns:
        the parsed results per page if succesful; otherwise the previously confiuged results per page