Class AbstractFileSystem
java.lang.Object
org.apache.commons.vfs2.provider.AbstractVfsComponent
org.apache.commons.vfs2.provider.AbstractFileSystem
- All Implemented Interfaces:
Closeable, AutoCloseable, FileSystem, VfsComponent
- Direct Known Subclasses:
CompressedFileFileSystem, FtpFileSystem, Http4FileSystem, LocalFileSystem, RamFileSystem, SftpFileSystem, TarFileSystem, UrlFileSystem, VirtualFileSystem, ZipFileSystem
A partial
FileSystem implementation.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate FileSystemKeyprivate final Collection<Capability> private static final FileListener[]private final FileSystemOptionsFileSystemOptions used for configurationprivate final Map<FileName, ArrayList<FileListener>> Map from FileName to an ArrayList of listeners for that file.private static final org.apache.commons.logging.Logprivate final AtomicIntegeropen streams counter for this file systemprivate final FileObjectprivate final FileNameThe "root" of the file system.private final StringThe root URI of the file system.private final AtomicLongHow many fileObjects are handed out -
Constructor Summary
ConstructorsModifierConstructorDescription(package private)Only provided for Serializable subclasses.protectedAbstractFileSystem(FileName rootFileName, FileObject parentLayer, FileSystemOptions fileSystemOptions) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidaddCapabilities(Collection<Capability> caps) Adds the capabilities of this file system.voidaddJunction(String junctionPoint, FileObject targetFile) Adds a junction to this file system.voidaddListener(FileObject file, FileListener listener) Adds a listener on a file in this file system.voidclose()Closes this component.voidCloses the underlying link used to access the files.protected abstract FileObjectcreateFile(AbstractFileName name) Creates a file object.protected FileObjectdecorateFileObject(FileObject file) protected voidCloses the underlying link used to access the files.protected FiledoReplicateFile(FileObject file, FileSelector selector) Creates a temporary local copy of a file and its descendants.(package private) voidfileObjectDestroyed(FileObject fileObject) (package private) voidfileObjectHanded(FileObject fileObject) private voidfireEvent(AbstractFileChangeEvent event) Fires an event.voidfireFileChanged(FileObject file) Fires a file changed event.voidfireFileCreated(FileObject file) Fires a file create event.voidfireFileDeleted(FileObject file) Fires a file delete event.(package private) voidgetAttribute(String attrName) Retrieves the attribute with the specified name.(package private) FileSystemKeyprotected FileObjectgetFileFromCache(FileName name) Returns a cached file.private FilesCacheReturns the FileSystemManager used to instantiate this file system.Returns the FileSystemOptions used to instantiate this file system.doubleReturns the accuracy of the last modification time.Returns the parent layer if this is a layered file system.getRoot()Returns the root file of this file system.Returns the name of the root of this file system.Returns the root URI specified for this file System.booleanhasCapability(Capability capability) Determines if this file system has a particular capability.voidinit()Initializes this component.booleanisOpen()Checks if this file system has open streams.booleanReturns true if no file is using this FileSystem.protected voidCalled after all file-objects closed their streams.protected voidputFileToCache(FileObject file) Adds a file object to the cache.protected voidremoveFileFromCache(FileName name) Removes a cached file.voidremoveJunction(String junctionPoint) Removes a junction from this file system.voidremoveListener(FileObject file, FileListener listener) Removes a listener from a file in this file system.replicateFile(FileObject file, FileSelector selector) Creates a temporary local copy of a file and its descendants.resolveFile(String nameStr) Finds a file in this file system.resolveFile(FileName name) Finds a file in this file system.private FileObjectresolveFile(FileName name, boolean useCache) voidsetAttribute(String attrName, Object value) Sets the attribute with the specified name.(package private) voidsetCacheKey(FileSystemKey cacheKey) (package private) void(package private) voidMethods inherited from class AbstractVfsComponent
getContext, getLogger, setContext, setLogger
-
Field Details
-
EMPTY_FILE_LISTENER_ARRAY
-
LOG
private static final org.apache.commons.logging.Log LOG -
rootName
The "root" of the file system. This is always "/" so it isn't always the "real" root. -
rootURI
The root URI of the file system. The base path specified as a file system option when the file system was created. -
capabilities
-
parentLayer
-
listenerMap
Map from FileName to an ArrayList of listeners for that file. -
fileSystemOptions
FileSystemOptions used for configuration -
useCount
How many fileObjects are handed out -
cacheKey
-
openStreams
open streams counter for this file system
-
-
Constructor Details
-
AbstractFileSystem
AbstractFileSystem()Only provided for Serializable subclasses. -
AbstractFileSystem
protected AbstractFileSystem(FileName rootFileName, FileObject parentLayer, FileSystemOptions fileSystemOptions)
-
-
Method Details
-
init
Initializes this component.- Specified by:
initin interfaceVfsComponent- Overrides:
initin classAbstractVfsComponent- Throws:
FileSystemException- if an error occurs.
-
close
public void close()Closes this component.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceVfsComponent- Overrides:
closein classAbstractVfsComponent
-
closeCommunicationLink
public void closeCommunicationLink()Closes the underlying link used to access the files. -
doCloseCommunicationLink
protected void doCloseCommunicationLink()Closes the underlying link used to access the files. -
createFile
Creates a file object.This method is called only if the requested file is not cached.
- Parameters:
name- name referencing the new file.- Returns:
- new created FileObject.
- Throws:
Exception- might throw an Exception, which is then wrapped in FileSystemException.
-
addCapabilities
Adds the capabilities of this file system.- Parameters:
caps- collections of Capabilities, can be immutable.
-
getRootName
Returns the name of the root of this file system.- Specified by:
getRootNamein interfaceFileSystem- Returns:
- the root FileName.
-
getRootURI
Returns the root URI specified for this file System.- Specified by:
getRootURIin interfaceFileSystem- Returns:
- The root URI used in this file system.
- Since:
- 2.0
-
putFileToCache
Adds a file object to the cache.- Parameters:
file- the file to add.
-
getFilesCache
-
getFileFromCache
Returns a cached file.- Parameters:
name- name to search for.- Returns:
- file object or null if not found.
-
removeFileFromCache
Removes a cached file.- Parameters:
name- The file name to remove.
-
hasCapability
Determines if this file system has a particular capability.- Specified by:
hasCapabilityin interfaceFileSystem- Parameters:
capability- the Capability to check for.- Returns:
- true if the FileSystem has the Capability, false otherwise.
-
getAttribute
Retrieves the attribute with the specified name. The default implementation simply throws an exception.- Specified by:
getAttributein interfaceFileSystem- Parameters:
attrName- The name of the attribute.- Returns:
- the Object associated with the attribute or null if no object is.
- Throws:
FileSystemException- if an error occurs.- See Also:
-
setAttribute
Sets the attribute with the specified name. The default implementation simply throws an exception.- Specified by:
setAttributein interfaceFileSystem- Parameters:
attrName- the attribute name.value- The object to associate with the attribute.- Throws:
FileSystemException- if an error occurs.- See Also:
-
getParentLayer
Returns the parent layer if this is a layered file system.- Specified by:
getParentLayerin interfaceFileSystem- Returns:
- The FileObject for the parent layer.
- Throws:
FileSystemException- if an error occurs.
-
getRoot
Returns the root file of this file system.- Specified by:
getRootin interfaceFileSystem- Returns:
- The root FileObject of the FileSystem
- Throws:
FileSystemException- if an error occurs.
-
resolveFile
Finds a file in this file system.- Specified by:
resolveFilein interfaceFileSystem- Parameters:
nameStr- The name of the file to resolve.- Returns:
- The located FileObject or null if none could be located.
- Throws:
FileSystemException- if an error occurs.
-
resolveFile
Finds a file in this file system.- Specified by:
resolveFilein interfaceFileSystem- Parameters:
name- The name of the file to locate.- Returns:
- The located FileObject or null if none could be located.
- Throws:
FileSystemException- if an error occurs.
-
resolveFile
- Throws:
FileSystemException
-
decorateFileObject
- Throws:
FileSystemException
-
replicateFile
Creates a temporary local copy of a file and its descendants.- Specified by:
replicateFilein interfaceFileSystem- Parameters:
file- The FileObject to replicate.selector- The FileSelector.- Returns:
- The replicated File.
- Throws:
FileSystemException- if an error occurs.
-
getFileSystemOptions
Returns the FileSystemOptions used to instantiate this file system.- Specified by:
getFileSystemOptionsin interfaceFileSystem- Returns:
- the FileSystemOptions.
-
getFileSystemManager
Returns the FileSystemManager used to instantiate this file system.- Specified by:
getFileSystemManagerin interfaceFileSystem- Returns:
- the FileSystemManager.
-
getLastModTimeAccuracy
public double getLastModTimeAccuracy()Returns the accuracy of the last modification time.- Specified by:
getLastModTimeAccuracyin interfaceFileSystem- Returns:
- ms 0 perfectly accurate, >0 might be off by this value e.g. sftp 1000ms
-
doReplicateFile
Creates a temporary local copy of a file and its descendants.- Parameters:
file- the start of the tree.selector- selection what to do with childs.- Returns:
- replicated root file.
- Throws:
Exception- any Exception is wrapped as FileSystemException.
-
addJunction
Adds a junction to this file system.- Specified by:
addJunctionin interfaceFileSystem- Parameters:
junctionPoint- The junction point.targetFile- The target to add.- Throws:
FileSystemException- if an error occurs.
-
removeJunction
Removes a junction from this file system.- Specified by:
removeJunctionin interfaceFileSystem- Parameters:
junctionPoint- The junction point.- Throws:
FileSystemException- if an error occurs
-
addListener
Adds a listener on a file in this file system.- Specified by:
addListenerin interfaceFileSystem- Parameters:
file- The FileObject to be monitored.listener- The FileListener
-
removeListener
Removes a listener from a file in this file system.- Specified by:
removeListenerin interfaceFileSystem- Parameters:
file- The FileObject to be monitored.listener- The FileListener
-
fireFileCreated
Fires a file create event.- Parameters:
file- The FileObject that was created.
-
fireFileDeleted
Fires a file delete event.- Parameters:
file- The FileObject that was deleted.
-
fireFileChanged
Fires a file changed event.This will only happen if you monitor the file using
FileMonitor.- Parameters:
file- The FileObject that changed.
-
isReleaseable
public boolean isReleaseable()Returns true if no file is using this FileSystem.- Returns:
- true if no file is using this FileSystem.
-
freeResources
void freeResources() -
fireEvent
Fires an event. -
fileObjectHanded
-
fileObjectDestroyed
-
setCacheKey
-
getCacheKey
FileSystemKey getCacheKey() -
streamOpened
void streamOpened() -
streamClosed
void streamClosed() -
notifyAllStreamsClosed
protected void notifyAllStreamsClosed()Called after all file-objects closed their streams. -
isOpen
public boolean isOpen()Checks if this file system has open streams.- Returns:
- true if the FileSystem has open streams.
-