org.apache.commons.vfs2.provider
Class DelegateFileObject

java.lang.Object
  extended by org.apache.commons.vfs2.provider.AbstractFileObject
      extended by org.apache.commons.vfs2.provider.DelegateFileObject
All Implemented Interfaces:
FileListener, FileObject

public class DelegateFileObject
extends AbstractFileObject
implements FileListener

A file backed by another file.

Author:
Commons VFS team
To Do:
Extract subclass that overlays the children

Constructor Summary
DelegateFileObject(AbstractFileName name, AbstractFileSystem fileSystem, FileObject file)
           
 
Method Summary
 void attachChild(FileName baseName, FileType type)
          Adds a child to this file.
 void close()
          Close the delegated file.
protected  void doCreateFolder()
          Creates this file as a folder.
protected  void doDelete()
          Deletes the file.
protected  Map<String,Object> doGetAttributes()
          Returns the attributes of this file.
protected  Certificate[] doGetCertificates()
          Returns the certificates of this file.
protected  FileContentInfo doGetContentInfo()
           
protected  long doGetContentSize()
          Returns the size of the file content (in bytes).
protected  InputStream doGetInputStream()
          Creates an input stream to read the file content from.
protected  long doGetLastModifiedTime()
          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 doGetRandomAccessContent(RandomAccessMode mode)
          Creates access to the file for random i/o.
protected  FileType doGetType()
          Determines the type of the file, returns null if the file does not exist.
protected  boolean doIsHidden()
          Determines if this file is hidden.
protected  boolean doIsReadable()
          Determines if this file can be read.
protected  boolean doIsWriteable()
          Determines if this file can be written to.
protected  String[] doListChildren()
          Lists the children of the file.
protected  void doRemoveAttribute(String atttrName)
          Removes an attribute of this file.
protected  void doRename(FileObject newFile)
          Renames the file.
protected  void doSetAttribute(String atttrName, 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.
 FileObject getDelegateFile()
          Get access to the delegated file.
 void refresh()
          Refresh file information.
 void setFile(FileObject file)
          Attaches or detaches the target file.
 
Methods inherited from class org.apache.commons.vfs2.provider.AbstractFileObject
canRenameTo, childrenChanged, copyFrom, createFile, createFolder, delete, delete, doAttach, doCreateFileContent, doDetach, doIsSameFile, doListChildrenResolved, endOutput, exists, finalize, findFiles, findFiles, getChild, getChildren, getContent, getFileContentInfoFactory, getFileOperations, getFileSystem, getInputStream, getName, getOutputStream, getOutputStream, getParent, getRandomAccessContent, getType, getURL, handleChanged, handleCreate, handleDelete, holdObject, injectType, isAttached, isContentOpen, isHidden, isReadable, isSameFile, isWriteable, moveTo, notifyAllStreamsClosed, onChange, onChildrenChanged, resolveFile, resolveFile, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DelegateFileObject

public DelegateFileObject(AbstractFileName name,
                          AbstractFileSystem 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 Exception
Adds a child to this file.

Parameters:
baseName - The base FileName.
type - The FileType.
Throws:
Exception - if an error occurs.

setFile

public void setFile(FileObject file)
             throws Exception
Attaches or detaches the target file.

Parameters:
file - The FileObject.
Throws:
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:
doGetType in class AbstractFileObject
Returns:
the type of the file.
Throws:
FileSystemException

doIsReadable

protected boolean doIsReadable()
                        throws FileSystemException
Determines if this file can be read.

Overrides:
doIsReadable in class AbstractFileObject
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:
doIsWriteable in class AbstractFileObject
Returns:
true if the file is writable.
Throws:
FileSystemException

doIsHidden

protected boolean doIsHidden()
                      throws FileSystemException
Determines if this file is hidden.

Overrides:
doIsHidden in class AbstractFileObject
Returns:
true if the file is hidden, false otherwise.
Throws:
FileSystemException

doListChildren

protected String[] doListChildren()
                           throws Exception
Lists the children of the file.

Specified by:
doListChildren in class AbstractFileObject
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.

doCreateFolder

protected void doCreateFolder()
                       throws Exception
Creates this file as a folder.

Overrides:
doCreateFolder in class AbstractFileObject
Throws:
Exception - if an error occurs.

doDelete

protected void doDelete()
                 throws Exception
Deletes the file.

Overrides:
doDelete in class AbstractFileObject
Throws:
Exception - if an error occurs.

doGetContentSize

protected long doGetContentSize()
                         throws Exception
Returns the size of the file content (in bytes). Is only called if doGetType() returns FileType.FILE.

Specified by:
doGetContentSize in class AbstractFileObject
Returns:
The size of the file in bytes.
Throws:
Exception - if an error occurs.

doGetAttributes

protected Map<String,Object> doGetAttributes()
                                      throws Exception
Returns the attributes of this file.

Overrides:
doGetAttributes in class AbstractFileObject
Returns:
The attributes of the file.
Throws:
Exception - if an error occurs.

doSetAttribute

protected void doSetAttribute(String atttrName,
                              Object value)
                       throws Exception
Sets an attribute of this file.

Overrides:
doSetAttribute in class AbstractFileObject
Parameters:
atttrName - The attribute name.
value - The value to be associated with the attribute name.
Throws:
Exception - if an error occurs.

doGetCertificates

protected Certificate[] doGetCertificates()
                                   throws Exception
Returns the certificates of this file.

Overrides:
doGetCertificates in class AbstractFileObject
Returns:
The certificates used to sign the file.
Throws:
Exception - if an error occurs.

doGetLastModifiedTime

protected long doGetLastModifiedTime()
                              throws Exception
Returns the last-modified time of this file.

Overrides:
doGetLastModifiedTime in class AbstractFileObject
Returns:
The last modification time.
Throws:
Exception - if an error occurs.

doSetLastModifiedTime

protected boolean doSetLastModifiedTime(long modtime)
                                 throws Exception
Sets the last-modified time of this file.

Overrides:
doSetLastModifiedTime in class AbstractFileObject
Parameters:
modtime - The last modification time.
Returns:
true if the time was set.
Throws:
Exception - if an error occurs.
Since:
2.0

doGetInputStream

protected InputStream doGetInputStream()
                                throws Exception
Creates an input stream to read the file content from.

Specified by:
doGetInputStream in class AbstractFileObject
Returns:
An InputStream to read the file content.
Throws:
Exception - if an error occurs.

doGetOutputStream

protected OutputStream doGetOutputStream(boolean bAppend)
                                  throws Exception
Creates an output stream to write the file content to.

Overrides:
doGetOutputStream in class AbstractFileObject
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.

fileCreated

public void fileCreated(FileChangeEvent event)
                 throws Exception
Called when a file is created.

Specified by:
fileCreated in interface FileListener
Parameters:
event - The FileChangeEvent.
Throws:
Exception - if an error occurs.

fileDeleted

public void fileDeleted(FileChangeEvent event)
                 throws Exception
Called when a file is deleted.

Specified by:
fileDeleted in interface FileListener
Parameters:
event - The FileChangeEvent.
Throws:
Exception - if an error occurs.

fileChanged

public void fileChanged(FileChangeEvent event)
                 throws Exception
Called when a file is changed.

This will only happen if you monitor the file using FileMonitor.

Specified by:
fileChanged in interface FileListener
Parameters:
event - The FileChangeEvent.
Throws:
Exception - if an error occurs.

close

public void close()
           throws FileSystemException
Close the delegated file.

Specified by:
close in interface FileObject
Overrides:
close in class AbstractFileObject
Throws:
FileSystemException - if an error occurs.
See Also:
FileContent.close()

refresh

public void refresh()
             throws FileSystemException
Refresh file information.

Specified by:
refresh in interface FileObject
Overrides:
refresh in class AbstractFileObject
Throws:
FileSystemException - if an error occurs.
Since:
2.0

doGetContentInfo

protected FileContentInfo doGetContentInfo()
                                    throws Exception
Throws:
Exception
Since:
2.0

doRename

protected void doRename(FileObject newFile)
                 throws Exception
Renames the file.

Overrides:
doRename in class AbstractFileObject
Parameters:
newFile - A FileObject with the new file name.
Throws:
Exception - if an error occurs.
Since:
2.0

doRemoveAttribute

protected void doRemoveAttribute(String atttrName)
                          throws Exception
Removes an attribute of this file.

Overrides:
doRemoveAttribute in class AbstractFileObject
Parameters:
atttrName - The name of the attribute to remove.
Throws:
Exception - if an error occurs.
Since:
2.0

doGetRandomAccessContent

protected RandomAccessContent doGetRandomAccessContent(RandomAccessMode mode)
                                                throws Exception
Creates access to the file for random i/o.

Overrides:
doGetRandomAccessContent in class AbstractFileObject
Parameters:
mode - The mode to access the file.
Returns:
The RandomAccessContext.
Throws:
Exception - if an error occurs.
Since:
2.0


Copyright © 2002-2012 The Apache Software Foundation. All Rights Reserved.