Class WebFile

  • All Implemented Interfaces:
    Comparable<Path>, Iterable<Path>, Path, Watchable

    public class WebFile
    extends Object
    implements Path
    Access a web-based file as a local file. File is lazily downloaded the first time it is accessed only, unless it gets deleted, in which case it will be downloaded again. Use this class for simple scenarios. If more complex ones are required (e.g., authentication, proxy, etc), use a different approach. All this Path methods are applied on the downloaded file.
    Since:
    2.0.0
    Author:
    Pascal Essiembre
    • Constructor Detail

      • WebFile

        public WebFile​(String url)
        Creates a web file using the OS temp directory + "webfiles" as the local download location, and the URL "file" name as the local file name.
        Parameters:
        url - URL to download
      • WebFile

        public WebFile​(String url,
                       Path localFile)
        Creates a web file using a local path to store the dowloaded file. If the local file argument is null, invoking this method is the same as invoking WebFile(URL)
        Parameters:
        url - URL to download
        localFile - full file path to local file destination
      • WebFile

        public WebFile​(URL url)
        Creates a web file using the OS temp directory + "webfiles" as the local download location, and the URL "file" name as the local file name.
        Parameters:
        url - URL to download
      • WebFile

        public WebFile​(URL url,
                       Path localFile)
        Creates a web file using a local path to store the dowloaded file. If the local file argument is null, invoking this method is the same as invoking WebFile(URL)
        Parameters:
        url - URL to download
        localFile - full file path to local file destination
    • Method Detail

      • create

        public static WebFile create​(String url,
                                     Path localDir)
        Creates a web file using the given directory as the local download location, and the URL "file" name as the local file name.
        Parameters:
        url - URL to download
        localDir - full directory path to local directory destination
        Returns:
        web file
      • create

        public static WebFile create​(String url,
                                     Path localDir,
                                     String localName)
        Creates a web file using the given directory as the local download location, and the given name as the local file name.
        Parameters:
        url - URL to download
        localDir - full directory path to local directory destination
        localName - local file name
        Returns:
        web file
      • create

        public static WebFile create​(String url,
                                     String localName)
        Creates a web file using the OS temp directory + "webfiles" as the local download location, and the given name as the local file name.
        Parameters:
        url - URL to download
        localName - local file name
        Returns:
        web file
      • create

        public static WebFile create​(URL url,
                                     Path localDir)
        Creates a web file using the given directory as the local download location, and the URL "file" name as the local file name.
        Parameters:
        url - URL to download
        localDir - full directory path to local directory destination
        Returns:
        web file
      • create

        public static WebFile create​(URL url,
                                     Path localDir,
                                     String localName)
        Creates a web file using the given directory as the local download location, and the given name as the local file name.
        Parameters:
        url - URL to download
        localDir - full directory path to local directory destination
        localName - local file name
        Returns:
        web file
      • create

        public static WebFile create​(URL url,
                                     String localName)
        Creates a web file using the OS temp directory + "webfiles" as the local download location, and the given name as the local file name.
        Parameters:
        url - URL to download
        localName - local file name
        Returns:
        web file
      • getUrl

        public URL getUrl()
      • download

        protected void download​(URL url,
                                Path localFile)
      • isAbsolute

        public boolean isAbsolute()
        Specified by:
        isAbsolute in interface Path
      • getRoot

        public Path getRoot()
        Specified by:
        getRoot in interface Path
      • getNameCount

        public int getNameCount()
        Specified by:
        getNameCount in interface Path
      • getName

        public Path getName​(int index)
        Specified by:
        getName in interface Path
      • subpath

        public Path subpath​(int beginIndex,
                            int endIndex)
        Specified by:
        subpath in interface Path
      • startsWith

        public boolean startsWith​(Path other)
        Specified by:
        startsWith in interface Path
      • startsWith

        public boolean startsWith​(String other)
        Specified by:
        startsWith in interface Path
      • endsWith

        public boolean endsWith​(Path other)
        Specified by:
        endsWith in interface Path
      • endsWith

        public boolean endsWith​(String other)
        Specified by:
        endsWith in interface Path
      • toUri

        public URI toUri()
        Specified by:
        toUri in interface Path
      • toFile

        public File toFile()
        Specified by:
        toFile in interface Path