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:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Comparable<FileObject>,java.lang.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.
-
-
Constructor Summary
Constructors Constructor Description DelegateFileObject(AbstractFileName name, AFS fileSystem, FileObject file)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidattachChild(FileName baseName, FileType type)Adds a child to this file.voidclose()Close the delegated file.protected voiddoCreateFolder()Creates this file as a folder.protected voiddoDelete()Deletes the file.protected java.util.Map<java.lang.String,java.lang.Object>doGetAttributes()Returns the attributes of this file.protected java.security.cert.Certificate[]doGetCertificates()Returns the certificates of this file.protected FileContentInfodoGetContentInfo()Return file content info.protected longdoGetContentSize()Returns the size of the file content (in bytes).protected java.io.InputStreamdoGetInputStream()Creates an input stream to read the file content from.protected longdoGetLastModifiedTime()Returns the last-modified time of this file.protected java.io.OutputStreamdoGetOutputStream(boolean bAppend)Creates an output stream to write the file content to.protected RandomAccessContentdoGetRandomAccessContent(RandomAccessMode mode)Creates access to the file for random i/o.protected FileTypedoGetType()Determines the type of the file, returns null if the file does not exist.protected booleandoIsExecutable()Determines if this file is executable.protected booleandoIsHidden()Determines if this file is hidden.protected booleandoIsReadable()Determines if this file can be read.protected booleandoIsWriteable()Determines if this file can be written to.protected java.lang.String[]doListChildren()Lists the children of the file.protected voiddoRemoveAttribute(java.lang.String atttrName)Removes an attribute of this file.protected voiddoRename(FileObject newFile)Renames the file.protected voiddoSetAttribute(java.lang.String atttrName, java.lang.Object value)Sets an attribute of this file.protected booleandoSetLastModifiedTime(long modtime)Sets the last-modified time of this file.voidfileChanged(FileChangeEvent event)Called when a file is changed.voidfileCreated(FileChangeEvent event)Called when a file is created.voidfileDeleted(FileChangeEvent event)Called when a file is deleted.FileObjectgetDelegateFile()Get access to the delegated file.voidrefresh()Refresh file information.voidsetFile(FileObject file)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, doIsSameFile, doListChildrenResolved, doSetExecutable, doSetReadable, doSetWritable, endOutput, exists, finalize, findFiles, findFiles, getAbstractFileSystem, getChild, getChildren, getContent, getFileContentInfoFactory, getFileOperations, getFileSystem, getInputStream, getName, getOutputStream, getOutputStream, getParent, getPublicURIString, getRandomAccessContent, getType, getURL, handleChanged, handleCreate, handleDelete, holdObject, injectType, isAttached, isContentOpen, isExecutable, isFile, isFolder, isHidden, isReadable, isSameFile, isWriteable, iterator, listFiles, moveTo, notifyAllStreamsClosed, onChange, onChildrenChanged, resolveFile, resolveFile, setExecutable, setReadable, setWritable, toString
-
-
-
-
Constructor Detail
-
DelegateFileObject
public DelegateFileObject(AbstractFileName name, AFS fileSystem, FileObject file) throws FileSystemException
- Throws:
FileSystemException
-
-
Method Detail
-
getDelegateFile
public FileObject getDelegateFile()
Get access to the delegated file.- Returns:
- The FileObject.
- Since:
- 2.0
-
attachChild
public void attachChild(FileName baseName, FileType type) throws java.lang.Exception
Adds a child to this file.- Parameters:
baseName- The base FileName.type- The FileType.- Throws:
java.lang.Exception- if an error occurs.
-
setFile
public void setFile(FileObject file) throws java.lang.Exception
Attaches or detaches the target file.- Parameters:
file- The FileObject.- Throws:
java.lang.Exception- if an error occurs.
-
doGetType
protected FileType doGetType() throws FileSystemException
Determines the type of the file, returns null if the file does not exist.- Specified by:
doGetTypein classAbstractFileObject<AFS extends AbstractFileSystem>- Returns:
- the type of the file.
- Throws:
FileSystemException
-
doIsReadable
protected boolean doIsReadable() throws FileSystemException
Determines if this file can be read.- Overrides:
doIsReadablein classAbstractFileObject<AFS extends AbstractFileSystem>- Returns:
- true if the file is readable, false otherwise.
- Throws:
FileSystemException
-
doIsWriteable
protected boolean doIsWriteable() throws FileSystemException
Determines if this file can be written to.- Overrides:
doIsWriteablein classAbstractFileObject<AFS extends AbstractFileSystem>- Returns:
- true if the file is writable.
- Throws:
FileSystemException
-
doIsExecutable
protected boolean doIsExecutable() throws FileSystemException
Determines if this file is executable.- Overrides:
doIsExecutablein classAbstractFileObject<AFS extends AbstractFileSystem>- Returns:
- true if the file is executable, false otherwise.
- Throws:
FileSystemException
-
doIsHidden
protected boolean doIsHidden() throws FileSystemException
Determines if this file is hidden.- Overrides:
doIsHiddenin classAbstractFileObject<AFS extends AbstractFileSystem>- Returns:
- true if the file is hidden, false otherwise.
- Throws:
FileSystemException
-
doListChildren
protected java.lang.String[] doListChildren() throws java.lang.Exception
Lists the children of the file.- Specified by:
doListChildrenin 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:
java.lang.Exception- if an error occurs.
-
doCreateFolder
protected void doCreateFolder() throws java.lang.Exception
Creates this file as a folder.- Overrides:
doCreateFolderin classAbstractFileObject<AFS extends AbstractFileSystem>- Throws:
java.lang.Exception- if an error occurs.
-
doDelete
protected void doDelete() throws java.lang.Exception
Deletes the file.- Overrides:
doDeletein classAbstractFileObject<AFS extends AbstractFileSystem>- Throws:
java.lang.Exception- if an error occurs.
-
doGetContentSize
protected long doGetContentSize() throws java.lang.Exception
Returns the size of the file content (in bytes). Is only called ifdoGetType()returnsFileType.FILE.- Specified by:
doGetContentSizein classAbstractFileObject<AFS extends AbstractFileSystem>- Returns:
- The size of the file in bytes.
- Throws:
java.lang.Exception- if an error occurs.
-
doGetAttributes
protected java.util.Map<java.lang.String,java.lang.Object> doGetAttributes() throws java.lang.Exception
Returns the attributes of this file.- Overrides:
doGetAttributesin classAbstractFileObject<AFS extends AbstractFileSystem>- Returns:
- The attributes of the file.
- Throws:
java.lang.Exception- if an error occurs.
-
doSetAttribute
protected void doSetAttribute(java.lang.String atttrName, java.lang.Object value) throws java.lang.Exception
Sets an attribute of this file.- Overrides:
doSetAttributein classAbstractFileObject<AFS extends AbstractFileSystem>- Parameters:
atttrName- The attribute name.value- The value to be associated with the attribute name.- Throws:
java.lang.Exception- if an error occurs.
-
doGetCertificates
protected java.security.cert.Certificate[] doGetCertificates() throws java.lang.Exception
Returns the certificates of this file.- Overrides:
doGetCertificatesin classAbstractFileObject<AFS extends AbstractFileSystem>- Returns:
- The certificates used to sign the file.
- Throws:
java.lang.Exception- if an error occurs.
-
doGetLastModifiedTime
protected long doGetLastModifiedTime() throws java.lang.Exception
Returns the last-modified time of this file.- Overrides:
doGetLastModifiedTimein classAbstractFileObject<AFS extends AbstractFileSystem>- Returns:
- The last modification time.
- Throws:
java.lang.Exception- if an error occurs.
-
doSetLastModifiedTime
protected boolean doSetLastModifiedTime(long modtime) throws java.lang.Exception
Sets the last-modified time of this file.- Overrides:
doSetLastModifiedTimein classAbstractFileObject<AFS extends AbstractFileSystem>- Parameters:
modtime- The last modification time.- Returns:
- true if the time was set.
- Throws:
java.lang.Exception- Any Exception thrown is wrapped in FileSystemException.- Since:
- 2.0
-
doGetInputStream
protected java.io.InputStream doGetInputStream() throws java.lang.Exception
Creates an input stream to read the file content from.- Specified by:
doGetInputStreamin classAbstractFileObject<AFS extends AbstractFileSystem>- Returns:
- An InputStream to read the file content.
- Throws:
java.lang.Exception- if an error occurs.
-
doGetOutputStream
protected java.io.OutputStream doGetOutputStream(boolean bAppend) throws java.lang.Exception
Creates an output stream to write the file content to.- Overrides:
doGetOutputStreamin 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:
java.lang.Exception- if an error occurs.
-
fileCreated
public void fileCreated(FileChangeEvent event) throws java.lang.Exception
Called when a file is created.- Specified by:
fileCreatedin interfaceFileListener- Parameters:
event- The FileChangeEvent.- Throws:
java.lang.Exception- if an error occurs.
-
fileDeleted
public void fileDeleted(FileChangeEvent event) throws java.lang.Exception
Called when a file is deleted.- Specified by:
fileDeletedin interfaceFileListener- Parameters:
event- The FileChangeEvent.- Throws:
java.lang.Exception- if an error occurs.
-
fileChanged
public void fileChanged(FileChangeEvent event) throws java.lang.Exception
Called when a file is changed.This will only happen if you monitor the file using
FileMonitor.- Specified by:
fileChangedin interfaceFileListener- Parameters:
event- The FileChangeEvent.- Throws:
java.lang.Exception- if an error occurs.
-
close
public void close() throws FileSystemException
Close the delegated file.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceFileObject- Overrides:
closein classAbstractFileObject<AFS extends AbstractFileSystem>- Throws:
FileSystemException- if an error occurs.- See Also:
FileContent.close()
-
refresh
public void refresh() throws FileSystemException
Refresh file information.- Specified by:
refreshin interfaceFileObject- Overrides:
refreshin classAbstractFileObject<AFS extends AbstractFileSystem>- Throws:
FileSystemException- if an error occurs.- Since:
- 2.0
-
doGetContentInfo
protected FileContentInfo doGetContentInfo() throws java.lang.Exception
Return file content info.- Returns:
- the file content info of the delegee.
- Throws:
java.lang.Exception- Any thrown Exception is wrapped in FileSystemException.- Since:
- 2.0
-
doRename
protected void doRename(FileObject newFile) throws java.lang.Exception
Renames the file.- Overrides:
doRenamein classAbstractFileObject<AFS extends AbstractFileSystem>- Parameters:
newFile- the new location/name.- Throws:
java.lang.Exception- Any thrown Exception is wrapped in FileSystemException.- Since:
- 2.0
-
doRemoveAttribute
protected void doRemoveAttribute(java.lang.String atttrName) throws java.lang.Exception
Removes an attribute of this file.- Overrides:
doRemoveAttributein classAbstractFileObject<AFS extends AbstractFileSystem>- Parameters:
atttrName- The name of the attribute to remove.- Throws:
java.lang.Exception- if an error occurs.- Since:
- 2.0
-
doGetRandomAccessContent
protected RandomAccessContent doGetRandomAccessContent(RandomAccessMode mode) throws java.lang.Exception
Creates access to the file for random i/o.- Overrides:
doGetRandomAccessContentin classAbstractFileObject<AFS extends AbstractFileSystem>- Parameters:
mode- The mode to access the file.- Returns:
- The RandomAccessContext.
- Throws:
java.lang.Exception- if an error occurs.- Since:
- 2.0
-
-