Package org.apache.commons.vfs2.provider
Class AbstractFileSystem
- java.lang.Object
-
- org.apache.commons.vfs2.provider.AbstractVfsComponent
-
- org.apache.commons.vfs2.provider.AbstractFileSystem
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,FileSystem,VfsComponent
- Direct Known Subclasses:
CompressedFileFileSystem,FtpFileSystem,Http4FileSystem,HttpFileSystem,LocalFileSystem,RamFileSystem,SftpFileSystem,TarFileSystem,UrlFileSystem,VirtualFileSystem,ZipFileSystem
public abstract class AbstractFileSystem extends AbstractVfsComponent implements FileSystem
A partialFileSystemimplementation.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractFileSystem(FileName rootName, FileObject parentLayer, FileSystemOptions fileSystemOptions)Constructs a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidaddCapabilities(java.util.Collection<Capability> caps)Adds the capabilities of this file system.voidaddJunction(java.lang.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.voidcloseCommunicationLink()Closes the underlying link used to access the files.protected abstract FileObjectcreateFile(AbstractFileName name)Creates a file object.protected FileObjectdecorateFileObject(FileObject file)Decorates the given file object.protected voiddoCloseCommunicationLink()Closes the underlying link used to access the files.protected java.io.FiledoReplicateFile(FileObject file, FileSelector selector)Creates a temporary local copy of a file and its descendants.voidfireFileChanged(FileObject file)Fires a file changed event.voidfireFileCreated(FileObject file)Fires a file create event.voidfireFileDeleted(FileObject file)Fires a file delete event.java.lang.ObjectgetAttribute(java.lang.String attrName)Gets the attribute with the specified name.protected FileObjectgetFileFromCache(FileName name)Gets a cached file.FileSystemManagergetFileSystemManager()Gets the FileSystemManager used to instantiate this file system.FileSystemOptionsgetFileSystemOptions()Gets the FileSystemOptions used to instantiate this file system.doublegetLastModTimeAccuracy()Gets the accuracy of the last modification time.FileObjectgetParentLayer()Gets the parent layer if this is a layered file system.FileObjectgetRoot()Gets the root file of this file system.FileNamegetRootName()Gets the name of the root of this file system.java.lang.StringgetRootURI()Gets the root URI specified for this file System.booleanhasCapability(Capability capability)Tests whether this file system has a particular capability.voidinit()Initializes this component.booleanisOpen()Tests whether this file system has open streams.booleanisReleaseable()Tests whether any files are using this FileSystem.protected voidnotifyAllStreamsClosed()Called 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(java.lang.String junctionPoint)Removes a junction from this file system.voidremoveListener(FileObject file, FileListener listener)Removes a listener from a file in this file system.java.io.FilereplicateFile(FileObject file, FileSelector selector)Creates a temporary local copy of a file and its descendants.FileObjectresolveFile(java.lang.String nameStr)Finds a file in this file system.FileObjectresolveFile(FileName name)Finds a file in this file system.voidsetAttribute(java.lang.String attrName, java.lang.Object value)Sets the attribute with the specified name.-
Methods inherited from class org.apache.commons.vfs2.provider.AbstractVfsComponent
getContext, getLogger, setContext, setLogger
-
-
-
-
Constructor Detail
-
AbstractFileSystem
protected AbstractFileSystem(FileName rootName, FileObject parentLayer, FileSystemOptions fileSystemOptions)
Constructs a new instance.- Parameters:
rootName- The root file name of this file system.parentLayer- The parent layer of this file system.fileSystemOptions- Options to build this file system.
-
-
Method Detail
-
addCapabilities
protected abstract void addCapabilities(java.util.Collection<Capability> caps)
Adds the capabilities of this file system.- Parameters:
caps- collections of Capabilities, can be immutable.
-
addJunction
public void addJunction(java.lang.String junctionPoint, FileObject targetFile) throws FileSystemException
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.
-
addListener
public void addListener(FileObject file, FileListener listener)
Adds a listener on a file in this file system.- Specified by:
addListenerin interfaceFileSystem- Parameters:
file- The FileObject to be monitored.listener- The FileListener
-
close
public void close()
Closes this component.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceVfsComponent- Overrides:
closein classAbstractVfsComponent
-
closeCommunicationLink
public void closeCommunicationLink()
Closes the underlying link used to access the files.
-
createFile
protected abstract FileObject createFile(AbstractFileName name) throws java.lang.Exception
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:
java.lang.Exception- might throw an Exception, which is then wrapped in FileSystemException.
-
decorateFileObject
protected FileObject decorateFileObject(FileObject file) throws FileSystemException
Decorates the given file object.- Parameters:
file- the file object.- Returns:
- the decorated file object.
- Throws:
FileSystemException- if a file system error occurs.
-
doCloseCommunicationLink
protected void doCloseCommunicationLink()
Closes the underlying link used to access the files.
-
doReplicateFile
protected java.io.File doReplicateFile(FileObject file, FileSelector selector) throws java.lang.Exception
Creates a temporary local copy of a file and its descendants.- Parameters:
file- the start of the tree.selector- selection what to do with children.- Returns:
- replicated root file.
- Throws:
java.lang.Exception- any Exception is wrapped as FileSystemException.
-
fireFileChanged
public void fireFileChanged(FileObject file)
Fires a file changed event.This will only happen if you monitor the file using
FileMonitor.- Parameters:
file- The FileObject that changed.
-
fireFileCreated
public void fireFileCreated(FileObject file)
Fires a file create event.- Parameters:
file- The FileObject that was created.
-
fireFileDeleted
public void fireFileDeleted(FileObject file)
Fires a file delete event.- Parameters:
file- The FileObject that was deleted.
-
getAttribute
public java.lang.Object getAttribute(java.lang.String attrName) throws FileSystemException
Gets 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:
FileContent.getAttribute(java.lang.String)
-
getFileFromCache
protected FileObject getFileFromCache(FileName name)
Gets a cached file.- Parameters:
name- name to search for.- Returns:
- file object or null if not found.
-
getFileSystemManager
public FileSystemManager getFileSystemManager()
Gets the FileSystemManager used to instantiate this file system.- Specified by:
getFileSystemManagerin interfaceFileSystem- Returns:
- the FileSystemManager.
-
getFileSystemOptions
public FileSystemOptions getFileSystemOptions()
Gets the FileSystemOptions used to instantiate this file system.- Specified by:
getFileSystemOptionsin interfaceFileSystem- Returns:
- the FileSystemOptions.
-
getLastModTimeAccuracy
public double getLastModTimeAccuracy()
Gets the accuracy of the last modification time.- Specified by:
getLastModTimeAccuracyin interfaceFileSystem- Returns:
- milliseconds, 0 means perfectly accurate,
> 0might be off by this value, for examnple, sftp is 1000 milliseconds.
-
getParentLayer
public FileObject getParentLayer() throws FileSystemException
Gets 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
public FileObject getRoot() throws FileSystemException
Gets the root file of this file system.- Specified by:
getRootin interfaceFileSystem- Returns:
- The root FileObject of the FileSystem
- Throws:
FileSystemException- if an error occurs.
-
getRootName
public FileName getRootName()
Gets the name of the root of this file system.- Specified by:
getRootNamein interfaceFileSystem- Returns:
- the root FileName.
-
getRootURI
public java.lang.String getRootURI()
Gets the root URI specified for this file System.- Specified by:
getRootURIin interfaceFileSystem- Returns:
- The root URI used in this file system.
- Since:
- 2.0
-
hasCapability
public boolean hasCapability(Capability capability)
Tests whether 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.
-
init
public void init() throws FileSystemException
Initializes this component.- Specified by:
initin interfaceVfsComponent- Overrides:
initin classAbstractVfsComponent- Throws:
FileSystemException- if an error occurs.
-
isOpen
public boolean isOpen()
Tests whether this file system has open streams.- Returns:
- true if the FileSystem has open streams.
-
isReleaseable
public boolean isReleaseable()
Tests whether any files are using this FileSystem.- Returns:
- whether any files are using this FileSystem.
-
notifyAllStreamsClosed
protected void notifyAllStreamsClosed()
Called after all file-objects closed their streams.
-
putFileToCache
protected void putFileToCache(FileObject file)
Adds a file object to the cache.- Parameters:
file- the file to add.
-
removeFileFromCache
protected void removeFileFromCache(FileName name)
Removes a cached file.- Parameters:
name- The file name to remove.
-
removeJunction
public void removeJunction(java.lang.String junctionPoint) throws FileSystemException
Removes a junction from this file system.- Specified by:
removeJunctionin interfaceFileSystem- Parameters:
junctionPoint- The junction point.- Throws:
FileSystemException- if an error occurs
-
removeListener
public void removeListener(FileObject file, FileListener listener)
Removes a listener from a file in this file system.- Specified by:
removeListenerin interfaceFileSystem- Parameters:
file- The FileObject to be monitored.listener- The FileListener
-
replicateFile
public java.io.File replicateFile(FileObject file, FileSelector selector) throws FileSystemException
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.
-
resolveFile
public FileObject resolveFile(FileName name) throws FileSystemException
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
public FileObject resolveFile(java.lang.String nameStr) throws FileSystemException
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.
-
setAttribute
public void setAttribute(java.lang.String attrName, java.lang.Object value) throws FileSystemException
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:
FileContent.setAttribute(java.lang.String, java.lang.Object)
-
-