Class FileRetrieveImpl

  • All Implemented Interfaces:
    FileRetrieve

    public class FileRetrieveImpl
    extends java.lang.Object
    implements FileRetrieve
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static Logger LOGGER  
      private java.util.List<java.io.File> rootdirs  
      private java.util.List<java.lang.String> urls  
    • Constructor Summary

      Constructors 
      Constructor Description
      FileRetrieveImpl()  
      FileRetrieveImpl​(java.io.File rootdir)
      Constructs a new FileRetrieveImpl with the given root url's and directories
      FileRetrieveImpl​(java.lang.String... strings)
      Constructs a new FileRetrieveImpl with the given root url's and directories
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addRootDir​(java.io.File dir)
      Add a root directory.
      void addURL​(java.lang.String url)
      Add a root URL.
      private java.net.URL detectWithRootUrls​(java.lang.String href)  
      void processFromHref​(java.lang.String href, ReadingProcessor processor)
      ProcessFromHref first tries to create an URL from the given href, if that throws a MalformedURLException, it will prepend the given root URLs to href until a valid URL is found.
      If by then there is no valid url found, this method will see if the given href is a valid file and can read it.
      If it's not a valid file or a file that can't be read, the given root directories will be set as root path with the given href as file path until a valid file has been found.
      void processFromStream​(java.io.InputStream in, ReadingProcessor processor)
      Process content from a given stream.
      private void read​(ReadingProcessor processor, java.io.InputStream in)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOGGER

        private static final Logger LOGGER
      • rootdirs

        private final java.util.List<java.io.File> rootdirs
      • urls

        private final java.util.List<java.lang.String> urls
    • Constructor Detail

      • FileRetrieveImpl

        public FileRetrieveImpl()
      • FileRetrieveImpl

        public FileRetrieveImpl​(java.lang.String... strings)
        Constructs a new FileRetrieveImpl with the given root url's and directories
        Parameters:
        strings - an array of strings, if the String starts with http or https it's taken as URL otherwise we check if it's a directory with
         File f = new File(str);
         f.isDirectory()
         
      • FileRetrieveImpl

        public FileRetrieveImpl​(java.io.File rootdir)
        Constructs a new FileRetrieveImpl with the given root url's and directories
        Parameters:
        strings - an array of strings, if the String starts with http or https it's taken as URL otherwise we check if it's a directory with
         File f = new File(str);
         f.isDirectory()
         
    • Method Detail

      • processFromHref

        public void processFromHref​(java.lang.String href,
                                    ReadingProcessor processor)
                             throws java.io.IOException
        ProcessFromHref first tries to create an URL from the given href, if that throws a MalformedURLException, it will prepend the given root URLs to href until a valid URL is found.
        If by then there is no valid url found, this method will see if the given href is a valid file and can read it.
        If it's not a valid file or a file that can't be read, the given root directories will be set as root path with the given href as file path until a valid file has been found.
        Specified by:
        processFromHref in interface FileRetrieve
        Parameters:
        href - the URL to process
        processor - the ReadingProcessor
        Throws:
        java.io.IOException - if something went wrong.
      • detectWithRootUrls

        private java.net.URL detectWithRootUrls​(java.lang.String href)
                                         throws java.net.MalformedURLException
        Parameters:
        href - the reference
        Throws:
        java.net.MalformedURLException - if no valid URL could be found.
      • processFromStream

        public void processFromStream​(java.io.InputStream in,
                                      ReadingProcessor processor)
                               throws java.io.IOException
        Description copied from interface: FileRetrieve
        Process content from a given stream.
        Specified by:
        processFromStream in interface FileRetrieve
        Parameters:
        in - the stream to process
        processor - the ReadingProcessor
        Throws:
        java.io.IOException - if something went wrong.
      • read

        private void read​(ReadingProcessor processor,
                          java.io.InputStream in)
                   throws java.io.IOException
        Parameters:
        processor -
        in -
        Throws:
        java.io.IOException
      • addRootDir

        public void addRootDir​(java.io.File dir)
        Add a root directory.
        Parameters:
        dir - the root directory
      • addURL

        public void addURL​(java.lang.String url)
        Add a root URL.
        Parameters:
        url - the URL