Package org.apache.commons.vfs2.provider
Class DelegateFileObject<AFS extends AbstractFileSystem>
java.lang.Object
org.apache.commons.vfs2.provider.AbstractFileObject<AFS>
org.apache.commons.vfs2.provider.DelegateFileObject<AFS>
- Type Parameters:
AFS
- A subclass of AbstractFileSystem.
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Comparable<FileObject>
,Iterable<FileObject>
,FileListener
,FileObject
public class DelegateFileObject<AFS extends AbstractFileSystem>
extends AbstractFileObject<AFS>
implements FileListener
A file backed by another file.
TODO - Extract subclass that overlays the children.
-
Field Summary
Fields inherited from class org.apache.commons.vfs2.provider.AbstractFileObject
DEFAULT_BUFFER_SIZE
Fields inherited from interface org.apache.commons.vfs2.FileObject
EMPTY_ARRAY
-
Constructor Summary
ConstructorsConstructorDescriptionDelegateFileObject
(AbstractFileName fileName, AFS fileSystem, FileObject fileObject) Constructs a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
attachChild
(FileName baseName, FileType type) Adds a child to this file.void
close()
Close the delegated file.protected void
Creates this file as a folder.protected void
doDelete()
Deletes the file.Returns the attributes of this file.protected Certificate[]
Returns the certificates of this file.protected FileContentInfo
Gets file content info.protected long
Returns the size of the file content (in bytes).protected InputStream
doGetInputStream
(int bufferSize) Creates an input stream to read the file content from.protected long
Returns the last-modified time of this file.protected OutputStream
doGetOutputStream
(boolean bAppend) Creates an output stream to write the file content to.protected RandomAccessContent
Creates access to the file for random I/O.protected FileType
Determines the type of the file, returns null if the file does not exist.protected boolean
Determines if this file is executable.protected boolean
Determines if this file is hidden.protected boolean
Determines if this file can be read.protected boolean
Determines if this file can be written to.protected String[]
Lists the children of the file.protected void
doRemoveAttribute
(String attrName) Removes an attribute of this file.protected void
doRename
(FileObject newFile) Renames the file.protected void
doSetAttribute
(String attrName, Object value) Sets an attribute of this file.protected boolean
doSetLastModifiedTime
(long modtime) Sets the last-modified time of this file.void
fileChanged
(FileChangeEvent event) Called when a file is changed.void
fileCreated
(FileChangeEvent event) Called when a file is created.void
fileDeleted
(FileChangeEvent event) Called when a file is deleted.Gets access to the delegated file.void
refresh()
Refresh file information.void
setFile
(FileObject fileObject) Attaches or detaches the target file.Methods inherited from class org.apache.commons.vfs2.provider.AbstractFileObject
canRenameTo, childrenChanged, compareTo, copyFrom, createFile, createFolder, delete, delete, deleteAll, doAttach, doCreateFileContent, doDetach, doGetInputStream, doIsSameFile, doIsSymbolicLink, doListChildrenResolved, doSetExecutable, doSetReadable, doSetWritable, endOutput, exists, finalize, findFiles, findFiles, getAbstractFileSystem, getChild, getChildren, getContent, getFileContentInfoFactory, getFileOperations, getFileSystem, getInputStream, getInputStream, getName, getOutputStream, getOutputStream, getParent, getPublicURIString, getRandomAccessContent, getType, getURL, handleChanged, handleCreate, handleDelete, holdObject, injectType, isAttached, isContentOpen, isExecutable, isFile, isFolder, isHidden, isReadable, isSameFile, isSymbolicLink, isWriteable, iterator, listFiles, moveTo, notifyAllStreamsClosed, onChange, onChildrenChanged, resolveFile, resolveFile, setExecutable, setReadable, setWritable, toString
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.commons.vfs2.FileObject
getPath, getURI
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
DelegateFileObject
public DelegateFileObject(AbstractFileName fileName, AFS fileSystem, FileObject fileObject) throws FileSystemException Constructs a new instance.- Parameters:
fileName
- the file name.fileSystem
- the file system.fileObject
- My file object.- Throws:
FileSystemException
- For subclasses to throw.
-
-
Method Details
-
attachChild
Adds a child to this file.- Parameters:
baseName
- The base FileName.type
- The FileType.- Throws:
Exception
- if an error occurs.
-
close
Close the delegated file.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceFileObject
- Overrides:
close
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Throws:
FileSystemException
- if an error occurs.- See Also:
-
doCreateFolder
Creates this file as a folder.- Overrides:
doCreateFolder
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Throws:
Exception
- if an error occurs.
-
doDelete
Deletes the file.- Overrides:
doDelete
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Throws:
Exception
- if an error occurs.
-
doGetAttributes
Returns the attributes of this file.- Overrides:
doGetAttributes
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Returns:
- The attributes of the file.
- Throws:
Exception
- if an error occurs.
-
doGetCertificates
Returns the certificates of this file.- Overrides:
doGetCertificates
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Returns:
- The certificates used to sign the file.
- Throws:
Exception
- if an error occurs.
-
doGetContentInfo
Gets file content info.- Returns:
- the file content info of the delegee.
- Throws:
Exception
- Any thrown Exception is wrapped in FileSystemException.- Since:
- 2.0
-
doGetContentSize
Returns the size of the file content (in bytes). Is only called ifdoGetType()
returnsFileType.FILE
.- Specified by:
doGetContentSize
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Returns:
- The size of the file in bytes.
- Throws:
Exception
- if an error occurs.
-
doGetInputStream
Creates an input stream to read the file content from.- Overrides:
doGetInputStream
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Parameters:
bufferSize
- Buffer size hint.- Returns:
- An InputStream to read the file content.
- Throws:
Exception
- if an error occurs.
-
doGetLastModifiedTime
Returns the last-modified time of this file.- Overrides:
doGetLastModifiedTime
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Returns:
- The last modification time.
- Throws:
Exception
- if an error occurs.
-
doGetOutputStream
Creates an output stream to write the file content to.- Overrides:
doGetOutputStream
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Parameters:
bAppend
- true if the file should be appended to, false if it should be overwritten.- Returns:
- An OutputStream to write to the file.
- Throws:
Exception
- if an error occurs.
-
doGetRandomAccessContent
Creates access to the file for random I/O.- Overrides:
doGetRandomAccessContent
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Parameters:
mode
- The mode to access the file.- Returns:
- The RandomAccessContext.
- Throws:
Exception
- if an error occurs.- Since:
- 2.0
-
doGetType
Determines the type of the file, returns null if the file does not exist.- Specified by:
doGetType
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Returns:
- the type of the file.
- Throws:
FileSystemException
-
doIsExecutable
Determines if this file is executable.- Overrides:
doIsExecutable
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Returns:
- true if the file is executable, false otherwise.
- Throws:
FileSystemException
-
doIsHidden
Determines if this file is hidden.- Overrides:
doIsHidden
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Returns:
- true if the file is hidden, false otherwise.
- Throws:
FileSystemException
-
doIsReadable
Determines if this file can be read.- Overrides:
doIsReadable
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Returns:
- true if the file is readable, false otherwise.
- Throws:
FileSystemException
-
doIsWriteable
Determines if this file can be written to.- Overrides:
doIsWriteable
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Returns:
- true if the file is writable.
- Throws:
FileSystemException
-
doListChildren
Lists the children of the file.- Specified by:
doListChildren
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Returns:
- a possible empty String array if the file is a directory or null or an exception if the file is not a directory or can't be read.
- Throws:
Exception
- if an error occurs.
-
doRemoveAttribute
Removes an attribute of this file.- Overrides:
doRemoveAttribute
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Parameters:
attrName
- The name of the attribute to remove.- Throws:
Exception
- if an error occurs.- Since:
- 2.0
-
doRename
Renames the file.- Overrides:
doRename
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Parameters:
newFile
- the new location/name.- Throws:
Exception
- Any thrown Exception is wrapped in FileSystemException.- Since:
- 2.0
-
doSetAttribute
Sets an attribute of this file.- Overrides:
doSetAttribute
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Parameters:
attrName
- The attribute name.value
- The value to be associated with the attribute name.- Throws:
Exception
- if an error occurs.
-
doSetLastModifiedTime
Sets the last-modified time of this file.- Overrides:
doSetLastModifiedTime
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Parameters:
modtime
- The last modification time.- Returns:
- true if the time was set.
- Throws:
Exception
- Any Exception thrown is wrapped in FileSystemException.- Since:
- 2.0
-
fileChanged
Called when a file is changed.This will only happen if you monitor the file using
FileMonitor
.- Specified by:
fileChanged
in interfaceFileListener
- Parameters:
event
- The FileChangeEvent.- Throws:
Exception
- if an error occurs.
-
fileCreated
Called when a file is created.- Specified by:
fileCreated
in interfaceFileListener
- Parameters:
event
- The FileChangeEvent.- Throws:
Exception
- if an error occurs.
-
fileDeleted
Called when a file is deleted.- Specified by:
fileDeleted
in interfaceFileListener
- Parameters:
event
- The FileChangeEvent.- Throws:
Exception
- if an error occurs.
-
getDelegateFile
Gets access to the delegated file.- Returns:
- The FileObject.
- Since:
- 2.0
-
refresh
Refresh file information.- Specified by:
refresh
in interfaceFileObject
- Overrides:
refresh
in classAbstractFileObject<AFS extends AbstractFileSystem>
- Throws:
FileSystemException
- if an error occurs.- Since:
- 2.0
-
setFile
Attaches or detaches the target file.- Parameters:
fileObject
- The FileObject.- Throws:
Exception
- if an error occurs.
-