public abstract class WebFileSystem extends FileSystem
FileSystem.DirectoryEntry, FileSystem.FileSystemOfflineException
Modifier and Type | Field and Description |
---|---|
static int |
HTTP_CHECK_TIMESTAMP_LIMIT_MS
timestamp checks will occur no more often than this.
|
protected static java.lang.String |
id
ID string for the process.
|
static int |
LISTING_TIMEOUT_MS
we keep a cached listing in on disk.
|
protected java.io.File |
localRoot |
protected static java.util.logging.Logger |
logger |
static int |
MEMORY_LISTING_TIMEOUT_MS
we keep a cached listing in memory for performance.
|
protected boolean |
offline
true means only local files are used from the cache.
|
protected java.lang.String |
offlineMessage
the response message explaining why the filesystem is offline.
|
protected int |
offlineResponseCode |
static java.lang.String |
PROP_OFFLINE
if true, then the remote filesystem is not accessible, but local cache
copies may be accessed.
|
static java.lang.String |
PROP_READ_ONLY_CACHE
alternate location to check for file before downloading.
|
protected WebProtocol |
protocol
plug-in template for implementation.
|
loggerUrl, NULL, PROP_CASE_INSENSITIVE, properties
Modifier | Constructor and Description |
---|---|
protected |
WebFileSystem(java.net.URI root,
java.io.File localRoot)
Creates a new instance of WebFileSystem
|
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener) |
protected java.util.Map<java.lang.String,FileSystem.DirectoryEntry> |
addRoCacheEntries(java.lang.String directory,
java.util.Map<java.lang.String,FileSystem.DirectoryEntry> remoteList)
Allow the local RO Cache to contain files that are not yet in the remote filesystem, to support the case
where a data provider tests locally available products before mirroring them out to the public website.
|
void |
cacheListing(java.lang.String directory,
FileSystem.DirectoryEntry[] listing) |
static void |
consumeStream(java.io.InputStream err)
Deprecated.
see HtmlUtil.consumeStream.
|
protected long |
copyStream(java.io.InputStream is,
java.io.OutputStream out,
ProgressMonitor monitor)
copies data from in to out, sending the number of bytesTransferred to the monitor.
|
protected abstract java.util.Map<java.lang.String,java.lang.String> |
downloadFile(java.lang.String filename,
java.io.File f,
java.io.File partfile,
ProgressMonitor monitor)
Transfers the file from the remote store to a local copy f.
|
static java.io.File |
getDownloadDirectory() |
protected java.util.concurrent.locks.Lock |
getDownloadLock(java.lang.String filename,
java.io.File f,
ProgressMonitor monitor)
Request lock to download file.
|
FileObject |
getFileObject(java.lang.String filename)
Return the handle for this file.
|
protected long |
getLastAccessed(java.lang.String filename)
reduce the number of hits to a server by caching last access times for local files.
|
java.lang.String |
getLocalName(java.io.File file)
return the name of the File within the FileSystem, where File is a local
file within the local copy of the filesystem.
|
java.lang.String |
getLocalName(java.net.URL url) |
java.io.File |
getLocalRoot()
return the folder that is a local copy of the filesystem.
|
java.lang.String |
getLocalRootAbsPath()
Deprecated.
use getLocalRoot().getAbsolutePath()
|
java.lang.String |
getOfflineMessage()
return the reason (if any provided) why the filesystem is offline,
|
int |
getOfflineResponseCode()
if non-zero, the response code (e.g.
|
java.io.File |
getPartFile(java.io.File localFile)
return a name where the download is to be staged.
|
WebProtocol |
getProtocol()
return the protocol object, which allows access to the metadata.
|
java.io.File |
getReadOnlyCache() |
java.net.URL |
getRootURL()
return the root of the filesystem as a URL.
|
java.net.URI |
getURI(java.lang.String filename)
return the URI for the internal filename
|
java.net.URL |
getURL(java.lang.String filename)
return the URL for the internal filename, encoding the characters if necessary.
|
boolean |
isAppletMode() |
abstract boolean |
isDirectory(java.lang.String filename)
return true if the name refers to a directory, not a file.
|
static java.lang.String |
isGitClone(java.io.File root,
java.lang.String path)
return the canonical path for the path, if it is part of a git clone.
|
boolean |
isListingCached(java.lang.String directory)
return true if the listing file (.listing) is available in the
file system cache, and is still fresh.
|
boolean |
isOffline() |
abstract java.lang.String[] |
listDirectory(java.lang.String directory)
return the directory listing for the name.
|
java.lang.String[] |
listDirectory(java.lang.String directory,
java.lang.String regex)
returns a list of the names of the files in a directory that match regex.
|
protected FileSystem.DirectoryEntry[] |
listDirectoryFromMemory(java.lang.String directory)
list the directory using the ram memory cache.
|
protected java.io.File |
listingFile(java.lang.String directory)
return the File for the cached listing, even if it does not exist.
|
static java.io.File |
localRoot(java.net.URI root)
return the local root for the URI.
|
FileSystem.DirectoryEntry |
maybeUpdateDirectoryEntry(java.lang.String filename,
boolean force)
trigger an update of the in-memory listing, or check to see if it is in memory.
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener) |
void |
resetListCache(java.lang.String directory)
From FTPBeanFileSystem.
|
void |
resetListingCache()
reset the .listing files and the ram-memory caches.
|
void |
setAppletMode(boolean applet) |
void |
setOffline(boolean offline) |
void |
setReadOnlyCache(java.io.File f) |
java.lang.String |
toString() |
create, create, create, create, create, create, createFileSystem, getExceptionHandler, getListing, getListing, getProperty, getRootURI, listDirectory, listDirectory, listDirectoryDeep, peek, peekInstances, recreate, recreate, registerFileSystemFactory, reset, reset, setExceptionHandler, settings, splitUrl, toCanonicalFilename, toCanonicalFolderName, toCanonicalFolderName
protected static final java.util.logging.Logger logger
public static final int LISTING_TIMEOUT_MS
public static final int MEMORY_LISTING_TIMEOUT_MS
public static final int HTTP_CHECK_TIMESTAMP_LIMIT_MS
protected final java.io.File localRoot
protected WebProtocol protocol
protected boolean offline
protected java.lang.String offlineMessage
public static final java.lang.String PROP_OFFLINE
protected int offlineResponseCode
public static final java.lang.String PROP_READ_ONLY_CACHE
protected static final java.lang.String id
protected WebFileSystem(java.net.URI root, java.io.File localRoot)
root
- the remote URI.localRoot
- local directory used to store local copies of the data.public static java.io.File getDownloadDirectory()
public boolean isOffline()
public void setOffline(boolean offline)
offline
- public java.lang.String getOfflineMessage()
public int getOfflineResponseCode()
public final void setReadOnlyCache(java.io.File f)
public final java.io.File getReadOnlyCache()
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
public static java.lang.String isGitClone(java.io.File root, java.lang.String path)
root
- a directory which is a clone of some path, possiblypath
- the path within the path.protected java.util.Map<java.lang.String,FileSystem.DirectoryEntry> addRoCacheEntries(java.lang.String directory, java.util.Map<java.lang.String,FileSystem.DirectoryEntry> remoteList)
directory
- remoteList
- public static java.io.File localRoot(java.net.URI root)
root
- the URI such as http://das2.org/data/public final java.io.File getPartFile(java.io.File localFile)
localFile
- protected java.util.concurrent.locks.Lock getDownloadLock(java.lang.String filename, java.io.File f, ProgressMonitor monitor) throws java.io.IOException
filename
- the filename with in the filesystem.f
- the File which will be the local copy.monitor
- a monitor for the download. If a MutatorLock is returned, then
the monitor is not touched, but other threads may use it to keep track
of the download progress.java.io.FileNotFoundException
- if the file wasn't found after another thread loaded the file.java.io.IOException
protected abstract java.util.Map<java.lang.String,java.lang.String> downloadFile(java.lang.String filename, java.io.File f, java.io.File partfile, ProgressMonitor monitor) throws java.io.IOException
filename
- the name of the file, relative to the filesystem.f
- the file to where the file is downloaded.partfile
- the temporary file during download.monitor
- progress monitorjava.io.IOException
WebProtocol.getMetadata(org.das2.util.filesystem.WebFileObject)
public java.lang.String getLocalRootAbsPath()
public java.io.File getLocalRoot()
FileSystem
getLocalRoot
in class FileSystem
public WebProtocol getProtocol()
public void resetListingCache()
public void resetListCache(java.lang.String directory)
directory
- protected java.io.File listingFile(java.lang.String directory)
directory
- public boolean isListingCached(java.lang.String directory)
directory
- public void cacheListing(java.lang.String directory, FileSystem.DirectoryEntry[] listing)
protected FileSystem.DirectoryEntry[] listDirectoryFromMemory(java.lang.String directory)
directory
- the directory name within the filesystem.public FileSystem.DirectoryEntry maybeUpdateDirectoryEntry(java.lang.String filename, boolean force) throws java.io.IOException
filename
- the particular file for which we need a listing.force
- if true, then list if it isn't available.java.io.IOException
- when the directory is listed.public abstract boolean isDirectory(java.lang.String filename) throws java.io.IOException
isDirectory
in class FileSystem
filename
- java.io.IOException
public abstract java.lang.String[] listDirectory(java.lang.String directory) throws java.io.IOException
listDirectory
in class FileSystem
directory
- java.io.IOException
public java.lang.String[] listDirectory(java.lang.String directory, java.lang.String regex) throws java.io.IOException
FileSystem
listDirectory
in class FileSystem
directory
- the directoryregex
- regular expressionjava.io.IOException
public java.net.URL getURL(java.lang.String filename)
filename
- internal filenameDefaultHttpProtocol.urlEncodeSansSlash(java.lang.String)
public java.net.URI getURI(java.lang.String filename)
filename
- internal filenamepublic java.net.URL getRootURL()
public java.lang.String getLocalName(java.io.File file)
file
- public java.lang.String getLocalName(java.net.URL url)
public FileObject getFileObject(java.lang.String filename)
getFileObject
in class FileSystem
filename
- the name of the file within the filesystem.protected long getLastAccessed(java.lang.String filename)
filename
- the filename within the filesystem.protected long copyStream(java.io.InputStream is, java.io.OutputStream out, ProgressMonitor monitor) throws java.io.IOException
is
- the input streamout
- the output streammonitor
- monitor for the task. Note this violates the monitor policy, and only calls setTaskProgress. Use with care!java.io.IOException
public static void consumeStream(java.io.InputStream err) throws java.io.IOException
err
- java.io.IOException
HtmlUtil.consumeStream(java.io.InputStream)
public java.lang.String toString()
toString
in class java.lang.Object
public boolean isAppletMode()
public void setAppletMode(boolean applet)