com.togethersoft.openapi.vfs
Interface VirtualFile


public interface VirtualFile
extends PropertyMap

This class represents a file (or directory) of VirtualFileSystem. Like java.io.File, the instance of
VirtualFile can correspond to unexistent file. Files of VFS are cached and not necessarily are written or even
exists on disk. Different instances of VirtualFile can represent same file.
Each instance has a Context; however the contexts are not used currently.

VirtualFile has a number of properties. Custom properties are not supported now. The predefined properties
are listed in VirtualFileProperty.

Author:
TogetherSoft

Method Summary
 voidaddVirtualFileListener(VirtualFileListener listener, int depth)
          Adds VirtualFileListener to a file
 VirtualFileEnumerationchildren()
          Returns children of invoking VirtualFile, which must be directory.
 VirtualFileEnumerationchildren(VirtualFileFilter filter)
          Extension of children (UnatyPredicate).
 VirtualFilecopy(VirtualFile newParent, boolean overwrite)
          Copies VirtualFile to another directory.
 voidcreate(VirtualFileType fileType, boolean overwrite)
          Creates file or directory if it didn't exist yet.
 voiddelete()
          Deletes file from memory and disk.
 voiddiscardCache()
          Discards any changes made to cache but do not reload file from disk.
 voiddiscardCache(Depth depth)
          Discards any changes made to cache but do not reload file from disk.
 booleanexists()
          Returns true if the file exists either on disk or in memory.
 voidexternalUpdate(Depth depth)
          Not supported now Checks timestamps of file(s) on disk and (re)load their contents if file(s) were updated.
 byte[]getArrayOfBytes()
          Reads the whole file, saving cache if needed, and returns the read array of bytes.
 VirtualFilegetChild(String shortName)
          Does exactly the same as VirtualFileManager method getVirtualFile(VirtualFile parent, String
relativePath, VirtualFileContext context)
, but with default context.
 VirtualFileContextgetContext()
          Return instnace of Context, assigned to this VirtualFile
 StringgetExtension()
           
 StringgetFullName()
          Shortcut for FILE_FULL_NAME property getting.
 InputStreamgetInputStream()
           
 OutputStreamgetOutputStream()
          Returns output stream.
 VirtualFilegetParent()
           
 StringgetPathRelativeTo(VirtualFile from)
          *
 intgetPermission()
          Shortcut for FILE_PERMISSION property getting.
 ReadergetReader()
           
 StringgetShortName()
          Shortcut for FILE_SHORT_NAME property getting.
 VirtualFileTypegetType()
          Shortcut for FILE_TYPE property getting.
 VirtualFilegetUniqueChild(String prefix, String extension)
          Gets unique child named on the base of prefix and extension
 StringgetUrl()
          Shortcut for FILE_URL property getting.
 VirtualFileManagergetVirtualFileManager()
          Returns VirtualFileManager instance
 WritergetWriter()
          Returns Writer for VirtualFile.
 booleanhasChild(String name)
          Checks if the file has child named name
 booleanisAncestorOf(VirtualFile descendant)
           
 booleanisCacheDirty()
          Returns true if changes were made to cache since file was opened or cache saved/discarded.
 VirtualFilemove(VirtualFile newParent, boolean overwrite)
          Moves the VirtualFile to another virtual file which must exist and be a directory.
 voidremoveVirtualFileListener(VirtualFileListener listener)
          Removes listener
 voidsaveCache()
          Save all changes in cache to disk.
 voidsaveCache(Depth depth)
          Save all changes in cache to disk.
 voidsetArrayOfBytes(byte[] array)
          Notice: (in current realization) in any case, only value of array would be used in VFS.
 voidsetShortName(String newName)
          Shortcut for FILE_SHORT_NAME property setting.
 voidtouchContent()
          Increases the internal cache age by one, that is file is treated as modified.

Methods inherited from interface com.togethersoft.openapi.util.propertyMap.PropertyMap
addProperty, addPropertyMapListener, canAddProperty, canSetPropertyValue, getPropertyValue, getPropertyValue, isPropertyReadable, isPropertyWritable, properties, properties, removePropertyMapListener, setPropertyValue

Method Detail

addVirtualFileListener

public void addVirtualFileListener(VirtualFileListener listener, int depth)
Adds VirtualFileListener to a file

children

public VirtualFileEnumeration children()
throws java.io.IOException
Returns children of invoking VirtualFile, which must be directory. Children are returned as enumeration of
VirtualFiles. The child can exists either on disk or in memory.
Returns: enumerations of all created files in directory.
Throws:
IOException when list of children cannot be obtained. Eg, when this
isn't directory at all.

children

public VirtualFileEnumeration children(VirtualFileFilter filter)
throws java.io.IOException
Extension of children (UnatyPredicate). The child will be included in childlist only if
filer.accept(VirtualFile) method returns true.
Returns: enumerations of all created files in directory.
Throws:
IOException when list of children cannot be obtained. Eg, when this isn't directory.

copy

public VirtualFile copy(VirtualFile newParent, boolean overwrite)
throws java.io.IOException
Copies VirtualFile to another directory.
See comments for move(...) method.
Parameters:
newParent destination directory;
overwrite specifies, if existent file can be overwritten;
Returns: VirtualFile of copied file.
Throws:
IOException if copying was unsuccessful.

create

public void create(VirtualFileType fileType, boolean overwrite)
throws java.io.IOException
Creates file or directory if it didn't exist yet.
Currently file is physically created at the same time it is created in VFS.
Parameters:
overwrite specifies, if existent file should be overwritten
Throws:
IOException if file wasn't created for any reason.

delete

public void delete()
throws java.io.IOException
Deletes file from memory and disk. If applied to directory, deletes whole branch silently. If operation was successful,
VirtualFile became unexistent, i.e. exists method returns false.

discardCache

public void discardCache()
throws java.io.IOException
Discards any changes made to cache but do not reload file from disk.

discardCache

public void discardCache(Depth depth)
throws java.io.IOException
Discards any changes made to cache but do not reload file from disk.

Bugs:


  1. Some manipulations with archive files can cause StackOverflowError in this method with depth == Depth.INFINITY .
Parameters:
depth defines, if the command should be recursive.

exists

public boolean exists()
Returns true if the file exists either on disk or in memory.

externalUpdate

public void externalUpdate(Depth depth)
throws java.io.IOException
Not supported now Checks timestamps of file(s) on disk and (re)load their contents if file(s) were updated.
Simultanious modification file in memory and on disk causes conflict, which is solved by mean of
VirtualFileErrorUI
Parameters:
depth defines, if the command should be recursive.

getArrayOfBytes

public byte[] getArrayOfBytes()
throws java.io.IOException
Reads the whole file, saving cache if needed, and returns the read array of bytes.
Notice, that in current realization returned value can (or cannot) be reference to the very VFS file cache
so modification of this array may cause file cache modification.
Returns: contents of file as array of bytes
Throws:
IOException when applied to directory.

getChild

public VirtualFile getChild(String shortName)
Does exactly the same as VirtualFileManager method getVirtualFile(VirtualFile parent, String
relativePath, VirtualFileContext context)
, but with default context.

getContext

public VirtualFileContext getContext()
Return instnace of Context, assigned to this VirtualFile

getExtension

public String getExtension()

getFullName

public String getFullName()
Shortcut for FILE_FULL_NAME property getting.

getInputStream

public InputStream getInputStream()
throws java.io.IOException
Returns: InputStream which can be used to read file contents.
Throws:
IOException when applied to directory.

getOutputStream

public OutputStream getOutputStream()
throws java.io.IOException
Returns output stream. It should be closed in order to allow flushing. Opened stream always works for
rewriting file content.
Throws:
IOException when applied to directory.

getParent

public VirtualFile getParent()
Returns: VirtualFile for parent directory or null when applied to root directory.

getPathRelativeTo

public String getPathRelativeTo(VirtualFile from)
*
Returns: Path relative to VirtualFile gived as a parameter. Note that relative path
is the same whether FILE_TYPE of it is VirtualFileType.DIRECTORY or
VirtualFileType.FILE

getPermission

public int getPermission()
Shortcut for FILE_PERMISSION property getting.

getReader

public Reader getReader()
throws java.io.IOException
Returns: Reader which can be used to read file contents.
Throws:
IOException when applied to directory.

getShortName

public String getShortName()
Shortcut for FILE_SHORT_NAME property getting.

getType

public VirtualFileType getType()
Shortcut for FILE_TYPE property getting.

getUniqueChild

public VirtualFile getUniqueChild(String prefix, String extension)
throws java.io.IOException
Gets unique child named on the base of prefix and extension
Returns: VirtualFile object representing file named prefixNUMBER.extension.

getUrl

public String getUrl()
Shortcut for FILE_URL property getting.

getVirtualFileManager

public VirtualFileManager getVirtualFileManager()
Returns VirtualFileManager instance

getWriter

public Writer getWriter()
throws java.io.IOException
Returns Writer for VirtualFile. It should be closed in order to allow flushing. Opened writer
always works for rewriting file content.
Throws:
IOException when applied to directory.

hasChild

public boolean hasChild(String name)
Checks if the file has child named name

isAncestorOf

public boolean isAncestorOf(VirtualFile descendant)
Returns: true if invoking object is ancestor of descendant.

isCacheDirty

public boolean isCacheDirty()
Returns true if changes were made to cache since file was opened or cache saved/discarded.

move

public VirtualFile move(VirtualFile newParent, boolean overwrite)
throws java.io.IOException
Moves the VirtualFile to another virtual file which must exist and be a directory.
  • Files can be actually written anew, so no attributes (eg. timestamps) are guarantied to be preserved after moving.
    Parameters:
    newParent destination directory;
    overwrite specifies, if existent file can be overwritten;
    Throws:
    IOException if VirtualFile cannot be moved.
    returns VirtualFile of file in its new location.

  • removeVirtualFileListener

    public void removeVirtualFileListener(VirtualFileListener listener)
    Removes listener

    saveCache

    public void saveCache()
    throws java.io.IOException
    Save all changes in cache to disk.

    saveCache

    public void saveCache(Depth depth)
    throws java.io.IOException
    Save all changes in cache to disk.
    Parameters:
    depth defines, if the command should be recursive.

    setArrayOfBytes

    public void setArrayOfBytes(byte[] array)
    throws java.io.IOException
    Notice: (in current realization) in any case, only value of array would be used in VFS. Unlike
    getArrayOfBytes, original instance of array can be modified free without influence VFS cache system.
    Throws:
    IOException when applied to directory.

    setShortName

    public void setShortName(String newName)
    throws java.io.IOException
    Shortcut for FILE_SHORT_NAME property setting.

    touchContent

    public void touchContent()
    Increases the internal cache age by one, that is file is treated as modified.