Package com.norconex.commons.lang.file
Class WebFile
- java.lang.Object
-
- com.norconex.commons.lang.file.WebFile
-
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 thisPathmethods are applied on the downloaded file.- Since:
- 2.0.0
- Author:
- Pascal Essiembre
-
-
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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Path other)static WebFilecreate(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 WebFilecreate(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 WebFilecreate(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 WebFilecreate(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 WebFilecreate(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 WebFilecreate(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 voiddownload(URL url, Path localFile)booleanendsWith(String other)booleanendsWith(Path other)booleanequals(Object obj)PathgetFileName()FileSystemgetFileSystem()PathgetName(int index)intgetNameCount()PathgetParent()PathgetRoot()URLgetUrl()inthashCode()booleanisAbsolute()Iterator<Path>iterator()Pathnormalize()WatchKeyregister(WatchService watcher, WatchEvent.Kind<?>... events)WatchKeyregister(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers)Pathrelativize(Path other)Pathresolve(String other)Pathresolve(Path other)PathresolveSibling(String other)PathresolveSibling(Path other)booleanstartsWith(String other)booleanstartsWith(Path other)Pathsubpath(int beginIndex, int endIndex)PathtoAbsolutePath()FiletoFile()PathtoRealPath(LinkOption... options)StringtoString()URItoUri()-
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 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 isnull, invoking this method is the same as invokingWebFile(URL)- Parameters:
url- URL to downloadlocalFile- 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 isnull, invoking this method is the same as invokingWebFile(URL)- Parameters:
url- URL to downloadlocalFile- 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 downloadlocalDir- 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 downloadlocalDir- full directory path to local directory destinationlocalName- 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 downloadlocalName- 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 downloadlocalDir- 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 downloadlocalDir- full directory path to local directory destinationlocalName- 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 downloadlocalName- local file name- Returns:
- web file
-
getUrl
public URL getUrl()
-
getFileSystem
public FileSystem getFileSystem()
- Specified by:
getFileSystemin interfacePath
-
isAbsolute
public boolean isAbsolute()
- Specified by:
isAbsolutein interfacePath
-
getFileName
public Path getFileName()
- Specified by:
getFileNamein interfacePath
-
getNameCount
public int getNameCount()
- Specified by:
getNameCountin interfacePath
-
startsWith
public boolean startsWith(Path other)
- Specified by:
startsWithin interfacePath
-
startsWith
public boolean startsWith(String other)
- Specified by:
startsWithin interfacePath
-
resolveSibling
public Path resolveSibling(Path other)
- Specified by:
resolveSiblingin interfacePath
-
resolveSibling
public Path resolveSibling(String other)
- Specified by:
resolveSiblingin interfacePath
-
relativize
public Path relativize(Path other)
- Specified by:
relativizein interfacePath
-
toAbsolutePath
public Path toAbsolutePath()
- Specified by:
toAbsolutePathin interfacePath
-
toRealPath
public Path toRealPath(LinkOption... options) throws IOException
- Specified by:
toRealPathin interfacePath- Throws:
IOException
-
register
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException
- Specified by:
registerin interfacePath- Specified by:
registerin interfaceWatchable- Throws:
IOException
-
register
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events) throws IOException
- Specified by:
registerin interfacePath- Specified by:
registerin interfaceWatchable- Throws:
IOException
-
compareTo
public int compareTo(Path other)
- Specified by:
compareToin interfaceComparable<Path>- Specified by:
compareToin interfacePath
-
toString
public String toString()
-
equals
public boolean equals(Object obj)
-
-