Package org.apache.commons.vfs2.impl
Class SynchronizedFileObject
java.lang.Object
org.apache.commons.vfs2.impl.DecoratedFileObject
org.apache.commons.vfs2.impl.SynchronizedFileObject
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Comparable<FileObject>
,Iterable<FileObject>
,FileObject
This decorator synchronizes all access to the FileObject.
-
Field Summary
Fields inherited from interface org.apache.commons.vfs2.FileObject
EMPTY_ARRAY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this file, and its content.void
copyFrom
(FileObject srcFile, FileSelector selector) Copies another file, and all its descendants, to this file.void
Creates this file, if it does not exist.void
Creates this folder, if it does not exist.boolean
delete()
Deletes this file.int
delete
(FileSelector selector) Deletes all descendants of this file that match a selector.boolean
exists()
Determines if this file exists.findFiles
(FileSelector selector) Finds the set of matching descendants of this file, in depthwise order.void
findFiles
(FileSelector selector, boolean depthwise, List<FileObject> selected) Finds the set of matching descendants of this file.Gets a child of this file.Gets a lists of children of this file.Gets this file's content.getType()
Gets this file's type.boolean
Determines if this file is executable.boolean
isHidden()
Determines if this file is hidden.boolean
Determines if this file can be read.boolean
Determines if this file can be written to.void
moveTo
(FileObject destFile) Move this file.resolveFile
(String path) Finds a file, relative to this file.resolveFile
(String name, NameScope scope) Finds a file relative to this file.boolean
setExecutable
(boolean executable, boolean ownerOnly) Sets the owner's (or everybody's) write permission.boolean
setReadable
(boolean readable, boolean ownerOnly) Sets the owner's (or everybody's) read permission.boolean
setWritable
(boolean writable, boolean ownerOnly) Sets the owner's (or everybody's) write permission.Methods inherited from class org.apache.commons.vfs2.impl.DecoratedFileObject
canRenameTo, compareTo, deleteAll, getDecoratedFileObject, getFileOperations, getFileSystem, getName, getParent, getPublicURIString, getURL, isAttached, isContentOpen, isFile, isFolder, iterator, refresh, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.commons.vfs2.FileObject
getPath, getURI, isSymbolicLink
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
SynchronizedFileObject
Constructs a new instance.- Parameters:
fileObject
- The FileObject to decorate.
-
-
Method Details
-
close
Description copied from interface:FileObject
Closes this file, and its content. This method is a hint to the implementation that it can release any resources associated with the file.The file object can continue to be used after this method is called.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceFileObject
- Overrides:
close
in classDecoratedFileObject
- Throws:
FileSystemException
- On error closing the file.- See Also:
-
copyFrom
Description copied from interface:FileObject
Copies another file, and all its descendants, to this file.If this file does not exist, it is created. Its parent folder is also created, if necessary. If this file does exist, it is deleted first.
This method is not transactional. If it fails and throws an exception, this file will potentially only be partially copied.
- Specified by:
copyFrom
in interfaceFileObject
- Overrides:
copyFrom
in classDecoratedFileObject
- Parameters:
srcFile
- The source file to copy.selector
- The selector to use to select which files to copy.- Throws:
FileSystemException
- If this file is read-only, or if the source file does not exist, or on error copying the file.
-
createFile
Description copied from interface:FileObject
Creates this file, if it does not exist. Also creates any ancestor folders which do not exist. This method does nothing if the file already exists and is a file.- Specified by:
createFile
in interfaceFileObject
- Overrides:
createFile
in classDecoratedFileObject
- Throws:
FileSystemException
- If the file already exists with the wrong type, or the parent folder is read-only, or on error creating this file or one of its ancestors.
-
createFolder
Description copied from interface:FileObject
Creates this folder, if it does not exist. Also creates any ancestor folders which do not exist. This method does nothing if the folder already exists.- Specified by:
createFolder
in interfaceFileObject
- Overrides:
createFolder
in classDecoratedFileObject
- Throws:
FileSystemException
- If the folder already exists with the wrong type, or the parent folder is read-only, or on error creating this folder or one of its ancestors.
-
delete
Description copied from interface:FileObject
Deletes this file. Does nothing if this file does not exist of if it is a folder that has children. Does not delete any descendants of this file, useFileObject.delete(FileSelector)
orFileObject.deleteAll()
for that.- Specified by:
delete
in interfaceFileObject
- Overrides:
delete
in classDecoratedFileObject
- Returns:
- true if this object has been deleted
- Throws:
FileSystemException
- If this file is a non-empty folder, or if this file is read-only, or on error deleteing this file.
-
delete
Description copied from interface:FileObject
Deletes all descendants of this file that match a selector. Does nothing if this file does not exist.This method is not transactional. If it fails and throws an exception, this file will potentially only be partially deleted.
- Specified by:
delete
in interfaceFileObject
- Overrides:
delete
in classDecoratedFileObject
- Parameters:
selector
- The selector to use to select which files to delete.- Returns:
- the number of deleted objects
- Throws:
FileSystemException
- If this file or one of its descendants is read-only, or on error deleting this file or one of its descendants.
-
exists
Description copied from interface:FileObject
Determines if this file exists.- Specified by:
exists
in interfaceFileObject
- Overrides:
exists
in classDecoratedFileObject
- Returns:
true
if this file exists,false
if not.- Throws:
FileSystemException
- On error determining if this file exists.
-
findFiles
Description copied from interface:FileObject
Finds the set of matching descendants of this file, in depthwise order.- Specified by:
findFiles
in interfaceFileObject
- Overrides:
findFiles
in classDecoratedFileObject
- Parameters:
selector
- The selector to use to select matching files.- Returns:
- The matching files. The files are returned in depthwise order (that is, a child appears in the list before its parent).
- Throws:
FileSystemException
- if an error occurs.
-
findFiles
public void findFiles(FileSelector selector, boolean depthwise, List<FileObject> selected) throws FileSystemException Description copied from interface:FileObject
Finds the set of matching descendants of this file.- Specified by:
findFiles
in interfaceFileObject
- Overrides:
findFiles
in classDecoratedFileObject
- Parameters:
selector
- the selector used to determine if the file should be selecteddepthwise
- controls the ordering in the list. e.g. deepest firstselected
- container for selected files. list needs not to be empty.- Throws:
FileSystemException
- if an error occurs.
-
getChild
Description copied from interface:FileObject
Gets a child of this file. Note that this method returnsnull
when the child does not exist. This differs fromFileObject.resolveFile(String, NameScope)
which never returns null.- Specified by:
getChild
in interfaceFileObject
- Overrides:
getChild
in classDecoratedFileObject
- Parameters:
name
- The name of the child.- Returns:
- The child, or null if there is no such child.
- Throws:
FileSystemException
- If this file does not exist, or is not a folder, or on error determining this file's children.
-
getChildren
Description copied from interface:FileObject
Gets a lists of children of this file.- Specified by:
getChildren
in interfaceFileObject
- Overrides:
getChildren
in classDecoratedFileObject
- Returns:
- An array containing the children of this file. The array is unordered. If the file does not have any children, a zero-length array is returned. This method never returns null.
- Throws:
FileSystemException
- If this file does not exist, or is not a folder, or on error listing this file's children.
-
getContent
Description copied from interface:FileObject
Gets this file's content. TheFileContent
returned by this method can be used to read and write the content of the file.This method can be called if the file does not exist, and the returned
FileContent
can be used to create the file by writing its content.- Specified by:
getContent
in interfaceFileObject
- Overrides:
getContent
in classDecoratedFileObject
- Returns:
- This file's content.
- Throws:
FileSystemException
- On error getting this file's content.
-
getType
Description copied from interface:FileObject
Gets this file's type.- Specified by:
getType
in interfaceFileObject
- Overrides:
getType
in classDecoratedFileObject
- Returns:
- One of the
FileType
constants. Never returns null. - Throws:
FileSystemException
- On error determining the file's type.
-
isExecutable
Description copied from interface:FileObject
Determines if this file is executable.- Specified by:
isExecutable
in interfaceFileObject
- Overrides:
isExecutable
in classDecoratedFileObject
- Returns:
true
if this file is executable,false
if not.- Throws:
FileSystemException
- On error determining if this file exists.
-
isHidden
Description copied from interface:FileObject
Determines if this file is hidden.- Specified by:
isHidden
in interfaceFileObject
- Overrides:
isHidden
in classDecoratedFileObject
- Returns:
true
if this file is hidden,false
if not.- Throws:
FileSystemException
- On error determining if this file exists.
-
isReadable
Description copied from interface:FileObject
Determines if this file can be read.- Specified by:
isReadable
in interfaceFileObject
- Overrides:
isReadable
in classDecoratedFileObject
- Returns:
true
if this file is readable,false
if not.- Throws:
FileSystemException
- On error determining if this file exists.
-
isWriteable
Description copied from interface:FileObject
Determines if this file can be written to.- Specified by:
isWriteable
in interfaceFileObject
- Overrides:
isWriteable
in classDecoratedFileObject
- Returns:
true
if this file is writable,false
if not.- Throws:
FileSystemException
- On error determining if this file exists.
-
moveTo
Description copied from interface:FileObject
Move this file.If the destFile exists, it is deleted first.
- Specified by:
moveTo
in interfaceFileObject
- Overrides:
moveTo
in classDecoratedFileObject
- Parameters:
destFile
- the New file name.- Throws:
FileSystemException
- If this file is read-only, or if the source file does not exist, or on error copying the file.
-
resolveFile
Description copied from interface:FileObject
Finds a file, relative to this file. Equivalent to callingresolveFile( path, NameScope.FILE_SYSTEM )
.- Specified by:
resolveFile
in interfaceFileObject
- Overrides:
resolveFile
in classDecoratedFileObject
- Parameters:
path
- The path of the file to locate. Can either be a relative path or an absolute path.- Returns:
- The file.
- Throws:
FileSystemException
- On error parsing the path, or on error finding the file.
-
resolveFile
Description copied from interface:FileObject
Finds a file relative to this file. Refer toNameScope
for a description of how names are resolved in the different scopes.- Specified by:
resolveFile
in interfaceFileObject
- Overrides:
resolveFile
in classDecoratedFileObject
- Parameters:
name
- The name to resolve.scope
- the NameScope for the file.- Returns:
- The file.
- Throws:
FileSystemException
- On error parsing the path, or on error finding the file.
-
setExecutable
Description copied from interface:FileObject
Sets the owner's (or everybody's) write permission.- Specified by:
setExecutable
in interfaceFileObject
- Overrides:
setExecutable
in classDecoratedFileObject
- Parameters:
executable
- True to allow read access, false to disallow.ownerOnly
- Iftrue
, the permission applies only to the owner; otherwise, it applies to everybody.- Returns:
- true if the operation succeeded.
- Throws:
FileSystemException
- On error determining if this file exists.
-
setReadable
Description copied from interface:FileObject
Sets the owner's (or everybody's) read permission.- Specified by:
setReadable
in interfaceFileObject
- Overrides:
setReadable
in classDecoratedFileObject
- Parameters:
readable
- True to allow read access, false to disallowownerOnly
- Iftrue
, the permission applies only to the owner; otherwise, it applies to everybody.- Returns:
- true if the operation succeeded
- Throws:
FileSystemException
- On error determining if this file exists.
-
setWritable
Description copied from interface:FileObject
Sets the owner's (or everybody's) write permission.- Specified by:
setWritable
in interfaceFileObject
- Overrides:
setWritable
in classDecoratedFileObject
- Parameters:
writable
- True to allow read access, false to disallowownerOnly
- Iftrue
, the permission applies only to the owner; otherwise, it applies to everybody.- Returns:
- true if the operation succeeded
- Throws:
FileSystemException
- On error determining if this file exists.
-