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
,LocalFileSystem
,RamFileSystem
,SftpFileSystem
,TarFileSystem
,UrlFileSystem
,VirtualFileSystem
,ZipFileSystem
public abstract class AbstractFileSystem extends AbstractVfsComponent implements FileSystem
A partialFileSystem
implementation.
-
-
Field Summary
Fields Modifier and Type Field Description private FileSystemKey
cacheKey
private java.util.Collection<Capability>
capabilities
private static FileListener[]
EMPTY_FILE_LISTENER_ARRAY
private FileSystemOptions
fileSystemOptions
FileSystemOptions used for configurationprivate java.util.Map<FileName,java.util.ArrayList<FileListener>>
listenerMap
Map from FileName to an ArrayList of listeners for that file.private static org.apache.commons.logging.Log
LOG
private java.util.concurrent.atomic.AtomicInteger
openStreams
open streams counter for this file systemprivate FileObject
parentLayer
private FileName
rootName
The "root" of the file system.private java.lang.String
rootURI
The root URI of the file system.private java.util.concurrent.atomic.AtomicLong
useCount
How many fileObjects are handed out
-
Constructor Summary
Constructors Modifier Constructor Description (package private)
AbstractFileSystem()
Only provided for Serializable subclasses.protected
AbstractFileSystem(FileName rootFileName, FileObject parentLayer, FileSystemOptions fileSystemOptions)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
addCapabilities(java.util.Collection<Capability> caps)
Adds the capabilities of this file system.void
addJunction(java.lang.String junctionPoint, FileObject targetFile)
Adds a junction to this file system.void
addListener(FileObject file, FileListener listener)
Adds a listener on a file in this file system.void
close()
Closes this component.void
closeCommunicationLink()
Closes the underlying link used to access the files.protected abstract FileObject
createFile(AbstractFileName name)
Creates a file object.protected FileObject
decorateFileObject(FileObject file)
protected void
doCloseCommunicationLink()
Closes the underlying link used to access the files.protected java.io.File
doReplicateFile(FileObject file, FileSelector selector)
Creates a temporary local copy of a file and its descendants.(package private) void
fileObjectDestroyed(FileObject fileObject)
(package private) void
fileObjectHanded(FileObject fileObject)
private void
fireEvent(AbstractFileChangeEvent event)
Fires an event.void
fireFileChanged(FileObject file)
Fires a file changed event.void
fireFileCreated(FileObject file)
Fires a file create event.void
fireFileDeleted(FileObject file)
Fires a file delete event.(package private) void
freeResources()
java.lang.Object
getAttribute(java.lang.String attrName)
Retrieves the attribute with the specified name.(package private) FileSystemKey
getCacheKey()
protected FileObject
getFileFromCache(FileName name)
Returns a cached file.private FilesCache
getFilesCache()
FileSystemManager
getFileSystemManager()
Returns the FileSystemManager used to instantiate this file system.FileSystemOptions
getFileSystemOptions()
Returns the FileSystemOptions used to instantiate this file system.double
getLastModTimeAccuracy()
Returns the accuracy of the last modification time.FileObject
getParentLayer()
Returns the parent layer if this is a layered file system.FileObject
getRoot()
Returns the root file of this file system.FileName
getRootName()
Returns the name of the root of this file system.java.lang.String
getRootURI()
Returns the root URI specified for this file System.boolean
hasCapability(Capability capability)
Determines if this file system has a particular capability.void
init()
Initializes this component.boolean
isOpen()
Checks if this file system has open streams.boolean
isReleaseable()
Returns true if no file is using this FileSystem.protected void
notifyAllStreamsClosed()
Called after all file-objects closed their streams.protected void
putFileToCache(FileObject file)
Adds a file object to the cache.protected void
removeFileFromCache(FileName name)
Removes a cached file.void
removeJunction(java.lang.String junctionPoint)
Removes a junction from this file system.void
removeListener(FileObject file, FileListener listener)
Removes a listener from a file in this file system.java.io.File
replicateFile(FileObject file, FileSelector selector)
Creates a temporary local copy of a file and its descendants.FileObject
resolveFile(java.lang.String nameStr)
Finds a file in this file system.FileObject
resolveFile(FileName name)
Finds a file in this file system.private FileObject
resolveFile(FileName name, boolean useCache)
void
setAttribute(java.lang.String attrName, java.lang.Object value)
Sets the attribute with the specified name.(package private) void
setCacheKey(FileSystemKey cacheKey)
(package private) void
streamClosed()
(package private) void
streamOpened()
-
Methods inherited from class org.apache.commons.vfs2.provider.AbstractVfsComponent
getContext, getLogger, setContext, setLogger
-
-
-
-
Field Detail
-
EMPTY_FILE_LISTENER_ARRAY
private static final FileListener[] EMPTY_FILE_LISTENER_ARRAY
-
LOG
private static final org.apache.commons.logging.Log LOG
-
rootName
private final FileName rootName
The "root" of the file system. This is always "/" so it isn't always the "real" root.
-
rootURI
private final java.lang.String rootURI
The root URI of the file system. The base path specified as a file system option when the file system was created.
-
capabilities
private final java.util.Collection<Capability> capabilities
-
parentLayer
private final FileObject parentLayer
-
listenerMap
private final java.util.Map<FileName,java.util.ArrayList<FileListener>> listenerMap
Map from FileName to an ArrayList of listeners for that file.
-
fileSystemOptions
private final FileSystemOptions fileSystemOptions
FileSystemOptions used for configuration
-
useCount
private final java.util.concurrent.atomic.AtomicLong useCount
How many fileObjects are handed out
-
cacheKey
private FileSystemKey cacheKey
-
openStreams
private final java.util.concurrent.atomic.AtomicInteger openStreams
open streams counter for this file system
-
-
Constructor Detail
-
AbstractFileSystem
AbstractFileSystem()
Only provided for Serializable subclasses.
-
AbstractFileSystem
protected AbstractFileSystem(FileName rootFileName, FileObject parentLayer, FileSystemOptions fileSystemOptions)
-
-
Method Detail
-
init
public void init() throws FileSystemException
Initializes this component.- Specified by:
init
in interfaceVfsComponent
- Overrides:
init
in classAbstractVfsComponent
- Throws:
FileSystemException
- if an error occurs.
-
close
public void close()
Closes this component.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceVfsComponent
- Overrides:
close
in 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
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.
-
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.
-
getRootName
public FileName getRootName()
Returns the name of the root of this file system.- Specified by:
getRootName
in interfaceFileSystem
- Returns:
- the root FileName.
-
getRootURI
public java.lang.String getRootURI()
Returns the root URI specified for this file System.- Specified by:
getRootURI
in interfaceFileSystem
- Returns:
- The root URI used in this file system.
- Since:
- 2.0
-
putFileToCache
protected void putFileToCache(FileObject file)
Adds a file object to the cache.- Parameters:
file
- the file to add.
-
getFilesCache
private FilesCache getFilesCache()
-
getFileFromCache
protected FileObject getFileFromCache(FileName name)
Returns a cached file.- Parameters:
name
- name to search for.- Returns:
- file object or null if not found.
-
removeFileFromCache
protected void removeFileFromCache(FileName name)
Removes a cached file.- Parameters:
name
- The file name to remove.
-
hasCapability
public boolean hasCapability(Capability capability)
Determines if this file system has a particular capability.- Specified by:
hasCapability
in interfaceFileSystem
- Parameters:
capability
- the Capability to check for.- Returns:
- true if the FileSystem has the Capability, false otherwise.
-
getAttribute
public java.lang.Object getAttribute(java.lang.String attrName) throws FileSystemException
Retrieves the attribute with the specified name. The default implementation simply throws an exception.- Specified by:
getAttribute
in 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)
-
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:
setAttribute
in 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)
-
getParentLayer
public FileObject getParentLayer() throws FileSystemException
Returns the parent layer if this is a layered file system.- Specified by:
getParentLayer
in interfaceFileSystem
- Returns:
- The FileObject for the parent layer.
- Throws:
FileSystemException
- if an error occurs.
-
getRoot
public FileObject getRoot() throws FileSystemException
Returns the root file of this file system.- Specified by:
getRoot
in interfaceFileSystem
- Returns:
- The root FileObject of the FileSystem
- 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:
resolveFile
in 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
public FileObject resolveFile(FileName name) throws FileSystemException
Finds a file in this file system.- Specified by:
resolveFile
in 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
private FileObject resolveFile(FileName name, boolean useCache) throws FileSystemException
- Throws:
FileSystemException
-
decorateFileObject
protected FileObject decorateFileObject(FileObject file) throws FileSystemException
- Throws:
FileSystemException
-
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:
replicateFile
in interfaceFileSystem
- Parameters:
file
- The FileObject to replicate.selector
- The FileSelector.- Returns:
- The replicated File.
- Throws:
FileSystemException
- if an error occurs.
-
getFileSystemOptions
public FileSystemOptions getFileSystemOptions()
Returns the FileSystemOptions used to instantiate this file system.- Specified by:
getFileSystemOptions
in interfaceFileSystem
- Returns:
- the FileSystemOptions.
-
getFileSystemManager
public FileSystemManager getFileSystemManager()
Returns the FileSystemManager used to instantiate this file system.- Specified by:
getFileSystemManager
in interfaceFileSystem
- Returns:
- the FileSystemManager.
-
getLastModTimeAccuracy
public double getLastModTimeAccuracy()
Returns the accuracy of the last modification time.- Specified by:
getLastModTimeAccuracy
in interfaceFileSystem
- Returns:
- ms 0 perfectly accurate, >0 might be off by this value e.g. sftp 1000ms
-
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 childs.- Returns:
- replicated root file.
- Throws:
java.lang.Exception
- any Exception is wrapped as FileSystemException.
-
addJunction
public void addJunction(java.lang.String junctionPoint, FileObject targetFile) throws FileSystemException
Adds a junction to this file system.- Specified by:
addJunction
in interfaceFileSystem
- Parameters:
junctionPoint
- The junction point.targetFile
- The target to add.- Throws:
FileSystemException
- if an error occurs.
-
removeJunction
public void removeJunction(java.lang.String junctionPoint) throws FileSystemException
Removes a junction from this file system.- Specified by:
removeJunction
in interfaceFileSystem
- Parameters:
junctionPoint
- The junction point.- 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:
addListener
in interfaceFileSystem
- Parameters:
file
- The FileObject to be monitored.listener
- The FileListener
-
removeListener
public void removeListener(FileObject file, FileListener listener)
Removes a listener from a file in this file system.- Specified by:
removeListener
in interfaceFileSystem
- Parameters:
file
- The FileObject to be monitored.listener
- The FileListener
-
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.
-
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.
-
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
private void fireEvent(AbstractFileChangeEvent event)
Fires an event.
-
fileObjectHanded
void fileObjectHanded(FileObject fileObject)
-
fileObjectDestroyed
void fileObjectDestroyed(FileObject fileObject)
-
setCacheKey
void setCacheKey(FileSystemKey cacheKey)
-
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.
-
-