Package com.norconex.commons.lang.file

# Class WebFile

java.lang.Object
com.norconex.commons.lang.file.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

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `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.
  `WebFile(String url, Path localFile)`
  Creates a web file using a local path to store the dowloaded file.
  `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.
  `WebFile(URL url, Path localFile)`
  Creates a web file using a local path to store the dowloaded file.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `compareTo(Path other)`
  `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.
  `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.
  `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.
  `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.
  `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.
  `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.
  `protected void`
  `download(URL url, Path localFile)`
  `boolean`
  `endsWith(String other)`
  `boolean`
  `endsWith(Path other)`
  `boolean`
  `equals(Object obj)`
  `Path`
  `getFileName()`
  `FileSystem`
  `getFileSystem()`
  `Path`
  `getName(int index)`
  `int`
  `getNameCount()`
  `Path`
  `getParent()`
  `Path`
  `getRoot()`
  `URL`
  `getUrl()`
  `int`
  `hashCode()`
  `boolean`
  `isAbsolute()`
  `Iterator<Path>`
  `iterator()`
  `Path`
  `normalize()`
  `WatchKey`
  `register(WatchService watcher, WatchEvent.Kind<?>... events)`
  `WatchKey`
  `register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers)`
  `Path`
  `relativize(Path other)`
  `Path`
  `resolve(String other)`
  `Path`
  `resolve(Path other)`
  `Path`
  `resolveSibling(String other)`
  `Path`
  `resolveSibling(Path other)`
  `boolean`
  `startsWith(String other)`
  `boolean`
  `startsWith(Path other)`
  `Path`
  `subpath(int beginIndex, int endIndex)`
  `Path`
  `toAbsolutePath()`
  `File`
  `toFile()`
  `Path`
  `toRealPath(LinkOption... options)`
  `String`
  `toString()`
  `URI`
  `toUri()`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface java.lang.Iterable

  `forEach, spliterator`

- ## Constructor Details

  - ### 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 Details

  - ### 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)

  - ### getFileSystem

    public FileSystem getFileSystem()
    Specified by:
      `getFileSystem` in interface `Path`

  - ### isAbsolute

    public boolean isAbsolute()
    Specified by:
      `isAbsolute` in interface `Path`

  - ### getRoot

    public Path getRoot()
    Specified by:
      `getRoot` in interface `Path`

  - ### getFileName

    public Path getFileName()
    Specified by:
      `getFileName` in interface `Path`

  - ### getParent

    public Path getParent()
    Specified by:
      `getParent` 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`

  - ### normalize

    public Path normalize()
    Specified by:
      `normalize` in interface `Path`

  - ### resolve

    public Path resolve(Path other)
    Specified by:
      `resolve` in interface `Path`

  - ### resolve

    public Path resolve(String other)
    Specified by:
      `resolve` in interface `Path`

  - ### resolveSibling

    public Path resolveSibling(Path other)
    Specified by:
      `resolveSibling` in interface `Path`

  - ### resolveSibling

    public Path resolveSibling(String other)
    Specified by:
      `resolveSibling` in interface `Path`

  - ### relativize

    public Path relativize(Path other)
    Specified by:
      `relativize` in interface `Path`

  - ### toUri

    public URI toUri()
    Specified by:
      `toUri` in interface `Path`

  - ### toAbsolutePath

    public Path toAbsolutePath()
    Specified by:
      `toAbsolutePath` in interface `Path`

  - ### toRealPath

    public Path toRealPath(LinkOption... options) throws IOException
    Specified by:
      `toRealPath` in interface `Path`
    Throws:
      `IOException`

  - ### toFile

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

  - ### register

    public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException
    Specified by:
      `register` in interface `Path`
    Specified by:
      `register` in interface `Watchable`
    Throws:
      `IOException`

  - ### register

    public WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events) throws IOException
    Specified by:
      `register` in interface `Path`
    Specified by:
      `register` in interface `Watchable`
    Throws:
      `IOException`

  - ### iterator

    public Iterator<Path> iterator()
    Specified by:
      `iterator` in interface `Iterable<Path>`
    Specified by:
      `iterator` in interface `Path`

  - ### toString

    public String toString()
    Specified by:
      `toString` in interface `Path`
    Overrides:
      `toString` in class `Object`

  - ### hashCode

    public int hashCode()
    Specified by:
      `hashCode` in interface `Path`
    Overrides:
      `hashCode` in class `Object`

  - ### compareTo

    public int compareTo(Path other)
    Specified by:
      `compareTo` in interface `Comparable<Path>`
    Specified by:
      `compareTo` in interface `Path`

  - ### equals

    public boolean equals(Object obj)
    Specified by:
      `equals` in interface `Path`
    Overrides:
      `equals` in class `Object`