public class Location extends Object
File
that supports reading over HTTP
(among other things).
It is strongly recommended to use this instead of java.io.File.Modifier and Type | Class and Description |
---|---|
protected class |
Location.ListingsResult |
protected static class |
Location.UrlType |
Constructor and Description |
---|
Location(File file)
Construct a Location using the given file on disk.
|
Location(Location parent,
String child)
Construct a Location using the given directory and relative path.
|
Location(String pathname)
Construct a Location using the given path.
|
Location(String parent,
String child)
Construct a Location using the given directory and relative path.
|
Modifier and Type | Method and Description |
---|---|
static void |
cacheDirectoryListings(boolean cache)
Turn cacheing of directory listings on or off.
|
boolean |
canRead()
If the underlying location is a URL, this method will return true if
the URL exists.
|
boolean |
canWrite()
If the underlying location is a URL, this method will always return false.
|
static void |
checkValidId(String id)
Checks that the given id points at a valid data stream.
|
static void |
cleanStaleCacheEntries()
Remove any cached directory listings that have expired.
|
static void |
clearDirectoryListingsCache()
Clear the directory listings cache.
|
boolean |
createNewFile()
Creates a new empty file named by this Location's path name iff a file
with this name does not already exist.
|
boolean |
delete()
Deletes this file.
|
void |
deleteOnExit()
Request that this file be deleted when the JVM terminates.
|
boolean |
equals(Object obj) |
boolean |
exists()
Returns whether or not the pathname exists.
|
Location |
getAbsoluteFile()
Return the absolute form of this abstract location.
|
String |
getAbsolutePath()
Return the absolute form of this abstract location.
|
Location |
getCanonicalFile()
Returns the canonical path to this file.
|
String |
getCanonicalPath()
Returns the canonical path to this file.
|
static IRandomAccess |
getHandle(String id)
Gets an IRandomAccess object that can read from the given file.
|
static IRandomAccess |
getHandle(String id,
boolean writable)
Gets an IRandomAccess object that can read from or write to the given file.
|
static IRandomAccess |
getHandle(String id,
boolean writable,
boolean allowArchiveHandles)
Gets an IRandomAccess object that can read from or write to the given file.
|
static IRandomAccess |
getHandle(String id,
boolean writable,
boolean allowArchiveHandles,
int bufferSize)
Gets an IRandomAccess object that can read from or write to the given file.
|
static HashMap<String,Object> |
getIdMap()
Return the id mapping.
|
static IRandomAccess |
getMappedFile(String id)
Gets the random access handle for the given id.
|
static String |
getMappedId(String id)
Gets the actual filename on disk for the given id.
|
String |
getName()
Returns the name of this file, i.e.
|
String |
getParent()
Returns the pathname string of this abstract pathname's parent, or null if
this pathname does not have a parent directory.
|
Location |
getParentFile()
Returns the abstract pathname of this abstract pathname's parent, or null
if this pathname does not name a parent directory.
|
String |
getPath()
Returns the file's path.
|
int |
hashCode() |
boolean |
isAbsolute()
Returns whether or not this file's path is absolute.
|
boolean |
isDirectory()
Returns whether or not this file is a directory.
|
boolean |
isFile()
Returns whether or not this file is a regular file (i.e.
|
boolean |
isHidden()
Returns whether or not this file is marked hidden by the filesystem.
|
long |
lastModified()
Return the last modification time of the file.
|
long |
length()
Return the file length in bytes.
|
String[] |
list()
Return a list of relative file names in this directory, or null
if this file is not a directory.
|
String[] |
list(boolean noHiddenFiles)
Return a list of all of the files in this directory.
|
Location[] |
listFiles()
Return a list of files in this directory, or null if this file is
not a directory.
|
static void |
mapFile(String id,
IRandomAccess ira)
Maps the given id to the given IRandomAccess object.
|
static void |
mapId(String id,
String filename)
Maps the given id to an actual filename on disk.
|
boolean |
mkdirs()
Creates a directory structures described by this Location's internal
File instance. |
static void |
reset()
Clear all caches and reset cache-related bookkeeping variables to their
original values.
|
static void |
setCacheDirectoryTimeout(double sec)
Cache directory listings for this many seconds before relisting.
|
static void |
setIdMap(HashMap<String,Object> map)
Set the id mapping using the given HashMap.
|
String |
toString() |
URL |
toURL()
Return a
URL corresponding to this file. |
public Location(String pathname)
pathname
- a URL, a file on disk, or a mapped namegetMappedId(String)
,
getMappedFile(String)
public Location(File file)
file
- a file on diskpublic Location(String parent, String child)
parent
- the directory path namechild
- the relative path namepublic Location(Location parent, String child)
parent
- a Location representing the directory namechild
- the relative path nameLocation(String, String)
public static void reset()
public static void cacheDirectoryListings(boolean cache)
cache
- - true to turn cacheing on, false to leave it off.public static void setCacheDirectoryTimeout(double sec)
sec
- - use the cache if a directory list was done within this many
seconds.public static void clearDirectoryListingsCache()
public static void cleanStaleCacheEntries()
public static void mapId(String id, String filename)
id
- the mapped namefilename
- the actual filename on disk.
If null, any existing mapping for id
will be cleared.getMappedId(String)
public static void mapFile(String id, IRandomAccess ira)
id
- the mapped nameira
- the IRandomAccess object that will be referenced by
id
. If null, any existing mapping for
id
will be cleared.getMappedFile(String)
public static String getMappedId(String id)
id
- the mapped namemapId(String, String)
public static IRandomAccess getMappedFile(String id)
id
- the mapped namemapFile(String, IRandomAccess)
public static HashMap<String,Object> getIdMap()
mapId(String, String)
,
mapFile(String, IRandomAccess)
public static void setIdMap(HashMap<String,Object> map)
map
- the new mapping from names to filesystem paths
and IRandomAccess objectsIllegalArgumentException
- if the given HashMap is null.public static IRandomAccess getHandle(String id) throws IOException
id
- the name for which to locate an IRandomAccessIOException
- if a valid IRandomAccess cannot be createdgetHandle(String, boolean, boolean, int)
,
IRandomAccess
public static IRandomAccess getHandle(String id, boolean writable) throws IOException
id
- the name for which to locate an IRandomAccesswritable
- true if the returned IRandomAccess should have write permissionIOException
- if a valid IRandomAccess cannot be createdgetHandle(String, boolean, boolean, int)
,
IRandomAccess
public static IRandomAccess getHandle(String id, boolean writable, boolean allowArchiveHandles) throws IOException
id
- the name for which to locate an IRandomAccesswritable
- true if the returned IRandomAccess should have write permissionallowArchiveHandles
- true if checks for compressed/archive file types
(e.g. Zip, GZip, BZip2) should be enabledIOException
- if a valid IRandomAccess cannot be createdgetHandle(String, boolean, boolean, int)
,
IRandomAccess
public static IRandomAccess getHandle(String id, boolean writable, boolean allowArchiveHandles, int bufferSize) throws IOException
id
- the name for which to locate an IRandomAccesswritable
- true if the returned IRandomAccess should have write permissionallowArchiveHandles
- true if checks for compressed/archive file types
(e.g. Zip, GZip, BZip2) should be enabledbufferSize
- the buffer size to use when constructing a NIOFileHandle.
Ignored when non-positive.IOException
- if a valid IRandomAccess cannot be createdIRandomAccess
public static void checkValidId(String id) throws IOException
id
- The id string to validate.IOException
- if the id is not valid.public String[] list(boolean noHiddenFiles)
noHiddenFiles
- true if hidden files should be omittedFile.list()
public boolean canRead()
File.canRead()
public boolean canWrite()
File.canWrite()
public boolean createNewFile() throws IOException
IOException
- if an I/O error occurred, or the
abstract pathname is a URLFile.createNewFile()
public boolean mkdirs()
File
instance.true
if the directory structure was created
successfully.File.mkdirs()
public boolean delete()
isDirectory()
returns true, then the
directory must be empty in order to be deleted. URLs cannot be deleted.File.delete()
public void deleteOnExit()
File.deleteOnExit()
public boolean equals(Object obj)
equals
in class Object
File.equals(Object)
,
URL.equals(Object)
public boolean exists()
File.exists()
public Location getAbsoluteFile()
File.getAbsoluteFile()
public String getAbsolutePath()
File.getAbsolutePath()
public Location getCanonicalFile() throws IOException
getAbsoluteFile()
). Otherwise, this method
will delegate to File.getCanonicalFile()
.IOException
- if the canonical path cannot be constructedFile.getCanonicalFile()
public String getCanonicalPath() throws IOException
getAbsolutePath()
). Otherwise, this method
will delegate to File.getCanonicalPath()
.IOException
- if the path cannot be retrievedpublic String getName()
File.getName()
public String getParent()
File.getParent()
public Location getParentFile()
File.getParentFile()
public String getPath()
File.getPath()
public boolean isAbsolute()
File.isAbsolute()
public boolean isDirectory()
File.isDirectory()
public boolean isFile()
File.exists()
public boolean isHidden()
File.isHidden()
public long lastModified()
File.lastModified()
,
URLConnection.getLastModified()
public long length()
File.length()
,
URLConnection.getContentLength()
public String[] list()
list(boolean)
public Location[] listFiles()
list()
public URL toURL() throws MalformedURLException
URL
corresponding to this file.MalformedURLException
- if the pathname is not a valid URLFile.toURL()
public String toString()
toString
in class Object
File.toString()
,
URL.toString()
Copyright © 2005–2024 Open Microscopy Environment. All rights reserved.