- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface ScrapedArticleReceiver
ScrapedArticleReceiver - Documentation.
FunctionalInterface, meaning it has only one method which must be written to satisfy the requirements of implementing the
interface.The method in this
FunctionalInterfaceis here to receive
Article'sthat have been downloaded by the
class ScrapeArticles- allowing the programmer to decide where, how and when to save those
NOTE: There is a simple, standardized factory-builder method in this
interfacethat may be used if the programmer is satisfied with saving downloaded
Articleclasses to a simple directory on the file-system.
- View Here: Torello/HTML/Tools/NewsSite/ScrapedArticleReceiver.java
- Open New Browser-Tab: Torello/HTML/Tools/NewsSite/ScrapedArticleReceiver.java
void receive(Article articleBody, int sectionURLNum, int articleNum) throws ReceiveExceptionFUNCTIONAL-INTERFACE METHOD: This is the method that must be fulfilled to meet the requirements of this
articleBody- After an article has been downloaded by the
ScrapeArticlesclass, it will build an instance of
class Articleand pass it to this class. It is the programmer's responsibility to ultimately decide what to do with news articles after they have been successfully scraped and parsed.
sectionURLNum- This is a convenience parameter that informs the implementing-
interfacefrom which URL Section of the News Web-Sites main-page that this article is being downloaded.
NOTE: Review the
class ScrapeURLsto read more about "Section
URL's." The number of "Section
URL's" for a news web-site scrape is just the length of the
articleNum- This parameter informs the implementing-
interfacewhich article number is being downloaded. Each section-
URLwill have a number of different articles in the section. These numbers can be used to create unique file-names, for instance.
ReceiveException- This exception may be thrown by the lambda-expression or class instance that implements this
FunctionalInterface. It is not mandatory that this exception be used.
static ScrapedArticleReceiver saveToFS(java.lang.String dirNameStr)saveToFS => Save To File-System
This is a static factory-builder method that will produce a
'ScrapedArticleReceiver'that simply saves downloaded articles to a directory on the file-system. The user, here, merely needs to provide a directory-name using parameter
NOTE: This is the most simple way to create an instance of this class.
dirNameStr- This is a directory on the file-system that will be used to save articles that are received directly to the file-system.
WritableDirectoryException- This method shall check whether it is possible to write to the provided directory name.
- Exact Method Body: