Interface ImageScraper.TargetDirectoryRetriever

  • All Superinterfaces:
    java.io.Serializable
    Enclosing class:
    ImageScraper
    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 static interface ImageScraper.TargetDirectoryRetriever
    extends java.io.Serializable
    TargetDirectoryRetriever - Documentation.

    When this interface is implemented, the "save directory" for an image can be provided on an image-by-image basis. Instantiate this a class with this interface, (or a lambda-function of this), and provide as a parameter to the constructor that contains this class as a parameter. The purpose of class ImageScraper over the original class class ImageScrape is that this class-inner-static-class compilation allows the programmer to configure many different courses of play for image downloading. Perhaps saving to disk is important, or perhaps, after download, the user might wish to send them to something other than disk.

    NOTE: The purpose of this static-inner-interface is to allow a user to configure where each file is saved, as each file is downloaded... (on an image-by-image basis).



    • Field Detail

      • serialVersionUID

        static final long serialVersionUID
        This fulfils the SerialVersion UID requirement for all classes that implement Java's interface java.io.Serializable. Using the Serializable Implementation offered by java is very easy, and can make saving program state when debugging a lot easier. It can also be used in place of more complicated systems like "hibernate" to store data as well.

        Functional Interfaces are usually not thought of as Data Objects that need to be saved, stored and retrieved; however, having the ability to store intermediate results along with the lambda-functions that helped get those results can make debugging easier.
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
        1
        public static final long serialVersionUID = 1;
        
    • Method Detail

      • dir

        java.lang.String dir​(java.net.URL url,
                             java.lang.String fileName,
                             IF imageFormat,
                             int iteratorCount,
                             int successCount)
        The dir(...) method within this interface will be called each time that an image successfully downloads from the internet. It's purpose is to allow the programmer to supply a target directory for where to store this downloaded image. Implement the lone-method from this interface, and images will be saved to individual save-directories on an image-by-image basis. If a interface TargetDirectorieRetriever is not provided, then all images will be saved to a single target-directory (or the interface 'ImageReceiver" must be implemented).
        Parameters:
        url - This is the URL that was used to connect to the internet, and download the image in question.
        fileName - This parameter will receive the computed filename of the image.
        imageFormat - This identifies whether the image-in-question is a GIF, JPG, PNG etc... Remember the image might not be saved by the same name which was used in the HTML on the website from which this was downloaded.
        iteratorCount - Identifies the 'count' in the Iterator's retrieval. Since this int is used as an array-index pointer, it is initialized to '0' (zero). Specifically, if this method were called upon completion of three iterations of Image-URL retrieval, this counter would be '2' (two).
        successCount - This identifies how many images have successfully downloaded, not the number of images for which a "download attempt" occurred. Since this int is used as an array-index pointer, it is initialized to '0' (zero). If on the third iteration of the source-Iterator, an IOException occurred between the Java-Virtual-Machine and the internet, the following invocation of this method would have successCount as '2' (two), but the iteratorCount would be '3' (three).
        Returns:
        It is up to the user implement this method such that it returns a String that identifies an appropriate directory in the local filesystem where the image may be saved.