com.planet_ink.coffee_mud.core
Class CMFile

java.lang.Object
  extended by java.io.File
      extended by com.planet_ink.coffee_mud.core.CMFile
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<java.io.File>

public class CMFile
extends java.io.File

An object to abstractly access the CoffeeMud File System (CMFS), which is a layer of database-based files (VFS) on top of the normal systems file system. It uses the unix path system.

See Also:
Serialized Form

Nested Class Summary
static class CMFile.CMFileManager
          FileManager handler for CMFile, used by WebServer
static class CMFile.CMVFSDir
          A class to represent a VFS/database directory.
static class CMFile.CMVFSFile
           
 
Field Summary
static int FLAG_FORCEALLOW
          Flag for opening a CMFile to force allowing a given user to open despite security
static int FLAG_LOGERRORS
          Flag for opening a CMFile to suppress error logging
static int VFS_MASK_MASKSAVABLE
          Flag for a CMVFSDir object, allowing you to open it
 
Fields inherited from class java.io.File
pathSeparatorChar, separator, separatorChar
 
Constructor Summary
CMFile(java.lang.String absolutePath, MOB user)
          Constructor for a CMFS file from a full path.
CMFile(java.lang.String absolutePath, MOB user, int flagBitmap)
          Constructor for a CMFS file from a full path.
 
Method Summary
 java.lang.String author()
          Returns the author of this file, if available.
 boolean canExecute()
           
 boolean canLocalEquiv()
          Returns true if reading this file as local file is possible, or this directory is permitted.
 boolean canRead()
           
 boolean canVFSEquiv()
          Returns true if reading this file as VFS is possible, or this directory is permitted.
 boolean canWrite()
           
 int compareTo(java.io.File pathname)
           
 boolean createNewFile()
           
 boolean delete()
           
 boolean deleteAll()
          Same as delete, though it deletes both vfs and local versions of a file unless the file is specified as vfs or local.
 boolean deleteLocal()
          If permitted, deletes this file from local filesystem
 void deleteOnExit()
           
 boolean deleteVFS()
          If permitted, deletes this file from VFS (database) filesystem
 boolean demandedLocal()
          Returns true if this file was opened only as a local file, and not as a VFS file.
 boolean demandedVFS()
          Returns true if this file was opened only as a vfs file, and not as a local file.
 boolean equals(java.lang.Object obj)
           
 boolean exists()
           
 java.io.File getAbsoluteFile()
           
 java.lang.String getAbsolutePath()
           
 java.io.File getCanonicalFile()
           
 java.lang.String getCanonicalPath()
           
static CMFile[] getFileList(java.lang.String path, MOB user, boolean recurse, boolean expandDirs, java.util.Set<java.lang.String> skipDirs)
          Returns CMFiles list for a directory at a given path
 long getFreeSpace()
           
 java.lang.String getIOReadableLocalPathAndName()
          Returns the local path and name that can be used for a local file.
 java.lang.String getLocalPathAndName()
          Returns local file path and name in simple form.
 java.lang.String getName()
           
 java.lang.String getParent()
           
 CMFile getParentFile()
           
 java.lang.String getPath()
           
 java.io.InputStream getRawStream()
          Reads and returns all of the data in this file as a byte input stream.
 java.io.InputStream getTextStream()
          Reads and returns all of the data in this file as an converted text stream.
 long getTotalSpace()
           
 java.io.InputStream getUnformattedTextStream()
          Reads and returns all of the data in this file as an unconverted text stream.
 long getUsableSpace()
           
static CMFile.CMVFSDir getVFSDirectory()
          Returns the entire VFS (database file) tree.
 java.lang.String getVFSPathAndName()
          Returns the path and name of this file.
 int hashCode()
           
 boolean isAbsolute()
           
 boolean isDirectory()
           
 boolean isFile()
           
 boolean isHidden()
           
 boolean isLocalDirectory()
          If this file represents (or could represent) a local dir, true
 boolean isLocalFile()
          Returns true if writing to this will write to a local file.
 boolean isVFSDirectory()
          If this file represents (or could represent) a VFS (database) dir, returns true.
 boolean isVFSFile()
          Returns true if writing to this will write to a VFS file.
 boolean isVFSOnlyPathFile()
          If this file represents (or could represent) a VFS (database) file, because the directory path is vfs only, this returns true.
 long lastModified()
           
 long length()
           
 java.lang.String[] list()
           
 java.lang.String[] list(java.io.FilenameFilter filter)
           
 CMFile[] listFiles()
           
 java.io.File[] listFiles(java.io.FileFilter filter)
           
 java.io.File[] listFiles(java.io.FilenameFilter filter)
           
 boolean mayDeleteIfDirectory()
          If this file is a directory and the directory is empty of other stuff.
 boolean mkdir()
           
 boolean mkdirs()
           
 boolean mustOverwrite()
          Weird function.
 byte[] raw()
          Reads and returns all of the data in this file as a byte array.
 boolean renameTo(java.io.File dest)
           
 boolean saveRaw(java.lang.Object data)
          Saves the given data to local file if demanded, or vfs file if not.
 boolean saveText(java.lang.Object data)
          Saves the given text data to local file if demanded, or vfs file if not.
 boolean saveText(java.lang.Object data, boolean append)
          Saves the given text data to local file if demanded, or vfs file if not.
 boolean setExecutable(boolean executable)
           
 boolean setExecutable(boolean executable, boolean ownerOnly)
           
 boolean setLastModified(long time)
           
 boolean setReadable(boolean readable)
           
 boolean setReadable(boolean readable, boolean ownerOnly)
           
 boolean setReadOnly()
           
 boolean setWritable(boolean writable)
           
 boolean setWritable(boolean writable, boolean ownerOnly)
           
 java.lang.StringBuffer text()
          Reads and returns all of the data in this file as an converted text stringbuffer.
 java.lang.StringBuffer textUnformatted()
          Reads and returns all of the data in this file as an unconverted text stringbuffer.
 java.lang.StringBuffer textVersion(byte[] bytes)
          Converts the given bytes to a stringbuffer, if it is one, or returns null otherwise.
 java.lang.String toString()
           
static java.lang.String vfsifyFilename(java.lang.String filename)
          Converts DOS style path/names to VFS type names.
 
Methods inherited from class java.io.File
createTempFile, createTempFile, listRoots, toURI, toURL
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

VFS_MASK_MASKSAVABLE

public static final int VFS_MASK_MASKSAVABLE
Flag for a CMVFSDir object, allowing you to open it

See Also:
Constant Field Values

FLAG_LOGERRORS

public static final int FLAG_LOGERRORS
Flag for opening a CMFile to suppress error logging

See Also:
Constant Field Values

FLAG_FORCEALLOW

public static final int FLAG_FORCEALLOW
Flag for opening a CMFile to force allowing a given user to open despite security

See Also:
Constant Field Values
Constructor Detail

CMFile

public CMFile(java.lang.String absolutePath,
              MOB user)
Constructor for a CMFS file from a full path. The creating/opening user may be null to ignore user security features. Will always suppress error logging, and if a user is given, they must have permission to open/create the file.

Parameters:
absolutePath - the path to the file to open/create
user - the user to check for permissions on

CMFile

public CMFile(java.lang.String absolutePath,
              MOB user,
              int flagBitmap)
Constructor for a CMFS file from a full path. The creating/opening user may be null to ignore user security features. For flags, see FLAG_LOGERRORS and FLAG_FORCEALLOW

Parameters:
absolutePath - the path to the file to open/create
user - the user to check for permissions on
flagBitmap - bitmap flag to turn on error logging or force allow
Method Detail

getParentFile

public final CMFile getParentFile()
Overrides:
getParentFile in class java.io.File

mustOverwrite

public final boolean mustOverwrite()
Weird function. Returns true if the file is a readable non-directory, or an existing specified VFS directory.

Returns:
true under weird conditions

canExecute

public final boolean canExecute()
Overrides:
canExecute in class java.io.File

canRead

public final boolean canRead()
Overrides:
canRead in class java.io.File

canWrite

public final boolean canWrite()
Overrides:
canWrite in class java.io.File

demandedVFS

public final boolean demandedVFS()
Returns true if this file was opened only as a vfs file, and not as a local file. This is a request status.

Returns:
true if this file was opened only as a vfs file

demandedLocal

public final boolean demandedLocal()
Returns true if this file was opened only as a local file, and not as a VFS file. This is a request status.

Returns:
true if this file was opened only as a local file

isDirectory

public final boolean isDirectory()
Overrides:
isDirectory in class java.io.File

exists

public final boolean exists()
Overrides:
exists in class java.io.File

isFile

public final boolean isFile()
Overrides:
isFile in class java.io.File

lastModified

public final long lastModified()
Overrides:
lastModified in class java.io.File

author

public final java.lang.String author()
Returns the author of this file, if available.

Returns:
the author of this file

isLocalFile

public final boolean isLocalFile()
Returns true if writing to this will write to a local file. Basically if VFS is not demanded and either Local FS is demanded, or the opener can't write to VFS but can write to a local file (weird security)

Returns:
true if this cmfile is a local file for sure

isVFSFile

public final boolean isVFSFile()
Returns true if writing to this will write to a VFS file.

Returns:
true if writing to this will write to a VFS file.

canVFSEquiv

public final boolean canVFSEquiv()
Returns true if reading this file as VFS is possible, or this directory is permitted.

Returns:
true if reading this file as VFS is possible, or this directory is permitted.

canLocalEquiv

public final boolean canLocalEquiv()
Returns true if reading this file as local file is possible, or this directory is permitted.

Returns:
true if reading this file as local file is possible, or this directory is permitted.

getName

public final java.lang.String getName()
Overrides:
getName in class java.io.File

getAbsolutePath

public final java.lang.String getAbsolutePath()
Overrides:
getAbsolutePath in class java.io.File

getCanonicalPath

public final java.lang.String getCanonicalPath()
Overrides:
getCanonicalPath in class java.io.File

getLocalPathAndName

public final java.lang.String getLocalPathAndName()
Returns local file path and name in simple form.

Returns:
local file path and name

getIOReadableLocalPathAndName

public final java.lang.String getIOReadableLocalPathAndName()
Returns the local path and name that can be used for a local file. If empty, returns "."

Returns:
the local path and name

getVFSPathAndName

public final java.lang.String getVFSPathAndName()
Returns the path and name of this file.

Returns:
the path and name of this file

mayDeleteIfDirectory

public final boolean mayDeleteIfDirectory()
If this file is a directory and the directory is empty of other stuff.

Returns:
true if the file is a deletable director

deleteLocal

public final boolean deleteLocal()
If permitted, deletes this file from local filesystem

Returns:
true if deleted, false otherwise

deleteVFS

public final boolean deleteVFS()
If permitted, deletes this file from VFS (database) filesystem

Returns:
true if deleted, false otherwise

deleteAll

public final boolean deleteAll()
Same as delete, though it deletes both vfs and local versions of a file unless the file is specified as vfs or local.

Returns:
true if 2 files deleted, false otherwise

delete

public final boolean delete()
Overrides:
delete in class java.io.File

getTextStream

public final java.io.InputStream getTextStream()
Reads and returns all of the data in this file as an converted text stream. This means the line-ends are converted to mud-format.

Returns:
all of the data in this file as a stream

text

public final java.lang.StringBuffer text()
Reads and returns all of the data in this file as an converted text stringbuffer. This means the line-ends are converted to mud-format.

Returns:
all of the data in this file as a stringbuffer

getUnformattedTextStream

public final java.io.InputStream getUnformattedTextStream()
Reads and returns all of the data in this file as an unconverted text stream. This means the line-ends aren't converted to mud-format.

Returns:
all of the data in this file as a stream

textUnformatted

public final java.lang.StringBuffer textUnformatted()
Reads and returns all of the data in this file as an unconverted text stringbuffer. This means the line-ends aren't converted to mud-format.

Returns:
all of the data in this file as a stringbuffer

getRawStream

public final java.io.InputStream getRawStream()
Reads and returns all of the data in this file as a byte input stream.

Returns:
all of the data in this file as a stream

raw

public final byte[] raw()
Reads and returns all of the data in this file as a byte array.

Returns:
all of the data in this file as a byte array

textVersion

public final java.lang.StringBuffer textVersion(byte[] bytes)
Converts the given bytes to a stringbuffer, if it is one, or returns null otherwise.

Parameters:
bytes - the bytes to convert
Returns:
stringbuffer if its text, or null otherwise

saveRaw

public boolean saveRaw(java.lang.Object data)
Saves the given data to local file if demanded, or vfs file if not.

Parameters:
data - string, stringbuffer, byte[], or string convertable
Returns:
true if happened without errors, false otherwise

saveText

public boolean saveText(java.lang.Object data)
Saves the given text data to local file if demanded, or vfs file if not.

Parameters:
data - string, stringbuffer, byte[], or string convertable
Returns:
true if happened without errors, false otherwise

saveText

public boolean saveText(java.lang.Object data,
                        boolean append)
Saves the given text data to local file if demanded, or vfs file if not.

Parameters:
data - string, stringbuffer, byte[], or string convertable
append - true to append, false to overwrite
Returns:
true if happened without errors, false otherwise

mkdir

public final boolean mkdir()
Overrides:
mkdir in class java.io.File

list

public final java.lang.String[] list()
Overrides:
list in class java.io.File

isVFSDirectory

public final boolean isVFSDirectory()
If this file represents (or could represent) a VFS (database) dir, returns true.

Returns:
true if this file represents (or could represent) a VFS (database) dir

isVFSOnlyPathFile

public final boolean isVFSOnlyPathFile()
If this file represents (or could represent) a VFS (database) file, because the directory path is vfs only, this returns true.

Returns:
true if this file represents (or could represent) a VFS (database) file

isLocalDirectory

public final boolean isLocalDirectory()
If this file represents (or could represent) a local dir, true

Returns:
if this file represents (or could represent) a local dir

listFiles

public final CMFile[] listFiles()
Overrides:
listFiles in class java.io.File

getVFSDirectory

public static final CMFile.CMVFSDir getVFSDirectory()
Returns the entire VFS (database file) tree.

Returns:
the entire VFS tree.

vfsifyFilename

public static final java.lang.String vfsifyFilename(java.lang.String filename)
Converts DOS style path/names to VFS type names. Removes any VFS prefixes like :: or // Removes any prefix path separator Changes separators to /

Parameters:
filename - the filename to convert
Returns:
the converted and cleaned filename

getFileList

public static final CMFile[] getFileList(java.lang.String path,
                                         MOB user,
                                         boolean recurse,
                                         boolean expandDirs,
                                         java.util.Set<java.lang.String> skipDirs)
Returns CMFiles list for a directory at a given path

Parameters:
path - the full path of the directory to get list from
user - user, for security checks
recurse - true to recurse deep dirs, false otherwise
expandDirs - if path is a dir, return contents, otherwise self
skipDirs - if recursing dirs, this will skip listed paths
Returns:
list for a directory at a given path

compareTo

public int compareTo(java.io.File pathname)
Specified by:
compareTo in interface java.lang.Comparable<java.io.File>
Overrides:
compareTo in class java.io.File

createNewFile

public boolean createNewFile()
                      throws java.io.IOException
Overrides:
createNewFile in class java.io.File
Throws:
java.io.IOException

deleteOnExit

public void deleteOnExit()
Overrides:
deleteOnExit in class java.io.File

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.io.File

getAbsoluteFile

public java.io.File getAbsoluteFile()
Overrides:
getAbsoluteFile in class java.io.File

getCanonicalFile

public java.io.File getCanonicalFile()
Overrides:
getCanonicalFile in class java.io.File

getFreeSpace

public long getFreeSpace()
Overrides:
getFreeSpace in class java.io.File

getParent

public java.lang.String getParent()
Overrides:
getParent in class java.io.File

getPath

public java.lang.String getPath()
Overrides:
getPath in class java.io.File

getTotalSpace

public long getTotalSpace()
Overrides:
getTotalSpace in class java.io.File

getUsableSpace

public long getUsableSpace()
Overrides:
getUsableSpace in class java.io.File

hashCode

public int hashCode()
Overrides:
hashCode in class java.io.File

isAbsolute

public boolean isAbsolute()
Overrides:
isAbsolute in class java.io.File

isHidden

public boolean isHidden()
Overrides:
isHidden in class java.io.File

length

public long length()
Overrides:
length in class java.io.File

list

public java.lang.String[] list(java.io.FilenameFilter filter)
Overrides:
list in class java.io.File

listFiles

public java.io.File[] listFiles(java.io.FileFilter filter)
Overrides:
listFiles in class java.io.File

listFiles

public java.io.File[] listFiles(java.io.FilenameFilter filter)
Overrides:
listFiles in class java.io.File

mkdirs

public boolean mkdirs()
Overrides:
mkdirs in class java.io.File

renameTo

public boolean renameTo(java.io.File dest)
Overrides:
renameTo in class java.io.File

setExecutable

public boolean setExecutable(boolean executable)
Overrides:
setExecutable in class java.io.File

setExecutable

public boolean setExecutable(boolean executable,
                             boolean ownerOnly)
Overrides:
setExecutable in class java.io.File

setLastModified

public boolean setLastModified(long time)
Overrides:
setLastModified in class java.io.File

setReadable

public boolean setReadable(boolean readable)
Overrides:
setReadable in class java.io.File

setReadable

public boolean setReadable(boolean readable,
                           boolean ownerOnly)
Overrides:
setReadable in class java.io.File

setReadOnly

public boolean setReadOnly()
Overrides:
setReadOnly in class java.io.File

setWritable

public boolean setWritable(boolean writable)
Overrides:
setWritable in class java.io.File

setWritable

public boolean setWritable(boolean writable,
                           boolean ownerOnly)
Overrides:
setWritable in class java.io.File

toString

public java.lang.String toString()
Overrides:
toString in class java.io.File