Class NvdCveClient
- java.lang.Object
-
- io.github.jeremylong.openvulnerability.client.nvd.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 voidclose()Cleanup allocated resources.intgetLastStatusCode()Returns the last HTTP Status Code.java.time.ZonedDateTimegetLastUpdated()Returns the latest updated date.intgetTotalAvailable()Only available after the first call to `next()`; returns the total number of records that will be returned.booleanhasNext()Returnstrueif there are more records available; otherwisefalse.java.util.Collection<DefCveItem>next()Retrieves the next entry.protected intparseResultsPerPage(java.lang.String msg)Attempts to parse the resultsPerPage error message to determine the maximum number of results per page.
-
-
-
Method Detail
-
getLastStatusCode
public int getLastStatusCode()
Returns the last HTTP Status Code.- Specified by:
getLastStatusCodein interfacePagedDataSource<DefCveItem>- Returns:
- the last HTTP Status Code
-
getTotalAvailable
public int getTotalAvailable()
Only available after the first call to `next()`; returns the total number of records that will be returned.- Specified by:
getTotalAvailablein interfacePagedDataSource<DefCveItem>- Returns:
- the total number of records that will be returned
-
close
public void close()
Description copied from interface:PagedDataSourceCleanup allocated resources.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacePagedDataSource<DefCveItem>
-
hasNext
public boolean hasNext()
Description copied from interface:PagedDataSourceReturnstrueif there are more records available; otherwisefalse.- Specified by:
hasNextin interfacejava.util.Iterator<java.util.Collection<DefCveItem>>- Specified by:
hasNextin interfacePagedDataSource<DefCveItem>- Returns:
trueif there are more records available; otherwisefalse.
-
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:
nextin interfacejava.util.Iterator<java.util.Collection<DefCveItem>>- Specified by:
nextin interfacePagedDataSource<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
-
getLastUpdated
public java.time.ZonedDateTime getLastUpdated()
Description copied from interface:PagedDataSourceReturns the latest updated date.- Specified by:
getLastUpdatedin interfacePagedDataSource<DefCveItem>- Returns:
- the latest updated date
-
-