oscript.fs
Class AbstractAbstractFile

java.lang.Object
  extended by oscript.fs.AbstractAbstractFile
All Implemented Interfaces:
java.io.Serializable, AbstractFile
Direct Known Subclasses:
InputStreamFile

public abstract class AbstractAbstractFile
extends java.lang.Object
implements AbstractFile, java.io.Serializable

Abstract implementation of AbstractFile... hmm, the naming scheme isn't working out so well here, because AbstractFile. isn't a good name for an interface.

Author:
Rob Clark (rob@ti.com)
See Also:
Serialized Form

Constructor Summary
AbstractAbstractFile(java.lang.String path, boolean temp)
          Class Constructor.
 
Method Summary
 boolean canRead()
          Is it possible to read from this file.
 boolean canWrite()
          Is it possible to write to this file.
 boolean createNewFile()
          Create a new empty file, if it does not yet exist.
 boolean delete()
          Delete this file.
 boolean equals(java.lang.Object obj)
           
 boolean exists()
          Tests whether the file denoted by this abstract pathname exists.
 java.lang.String getExtension()
          Get the extension, which indicates the type of file.
 java.lang.String getName()
          Get the name of this file, which is the last component of the complete path.
 java.io.OutputStream getOutputStream(boolean append)
          Get an output stream to write to this file.
 java.lang.String getPath()
          Get the file path, which globally identifies the file.
 int hashCode()
           
 boolean isDirectory()
          Test whether this file is a directory.
 boolean isFile()
          Test whether this file is a regular file.
 long lastModified()
          Return the time of last modification.
 long length()
          should be overriden to not provide a bogus answer
 boolean mkdir()
          If this file does not exist, create it as a directory.
 boolean mkdirs()
          If this file does not exist, create it as a directory.
 java.lang.String toString()
           
 void touch()
          Update the timestamp on this file to the current time.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface oscript.fs.AbstractFile
getInputStream
 

Constructor Detail

AbstractAbstractFile

public AbstractAbstractFile(java.lang.String path,
                            boolean temp)
Class Constructor. If this file is created as a temporary file (ie. temp is true), then the path is interpreted as a relative path, or filename with no path prefix, and the file is created with a unique directory path, and the file will not equals(java.lang.Object) any other file object.

Parameters:
path - the file name
temp - is this a unique temporary file
Method Detail

canWrite

public boolean canWrite()
Is it possible to write to this file.

Specified by:
canWrite in interface AbstractFile

canRead

public boolean canRead()
Is it possible to read from this file.

Specified by:
canRead in interface AbstractFile

exists

public boolean exists()
Tests whether the file denoted by this abstract pathname exists.

Specified by:
exists in interface AbstractFile
Returns:
true iff the file exists

isDirectory

public boolean isDirectory()
Test whether this file is a directory.

Specified by:
isDirectory in interface AbstractFile
Returns:
true iff this file is a directory

isFile

public boolean isFile()
Test whether this file is a regular file. A file is a regular file if it is not a directory.

Specified by:
isFile in interface AbstractFile
Returns:
true iff this file is a regular file.

lastModified

public long lastModified()
Return the time of last modification. The meaning of these value is not so important, but the implementation must ensure that a higher value is returned for the more recent version of a given element. Ie. if at some point this returns X, an AbstractFile representing the same "file", but created at a later time, should return X if the file has not been modified, or >X if the file has been modified.

Specified by:
lastModified in interface AbstractFile
Returns:
larger value indicates more recent modification

length

public long length()
should be overriden to not provide a bogus answer

Specified by:
length in interface AbstractFile

createNewFile

public boolean createNewFile()
                      throws java.io.IOException
Create a new empty file, if it does not yet exist.

Specified by:
createNewFile in interface AbstractFile
Returns:
true iff the file does not exist and was successfully created.
Throws:
java.io.IOException - if error

touch

public void touch()
           throws java.io.IOException
Update the timestamp on this file to the current time.

Specified by:
touch in interface AbstractFile
Throws:
java.io.IOException - if error

delete

public boolean delete()
               throws java.io.IOException
Delete this file. If this file is a directory, then the directory must be empty.

Specified by:
delete in interface AbstractFile
Returns:
true iff the directory is successfully deleted.
Throws:
java.io.IOException - if error

mkdir

public boolean mkdir()
              throws java.io.IOException
If this file does not exist, create it as a directory.

Specified by:
mkdir in interface AbstractFile
Returns:
true iff directory successfully created
Throws:
java.io.IOException

mkdirs

public boolean mkdirs()
               throws java.io.IOException
If this file does not exist, create it as a directory. All necessary parent directories are also created. If this operation fails, it may have successfully created some or all of the parent directories.

Specified by:
mkdirs in interface AbstractFile
Returns:
true iff directory successfully created
Throws:
java.io.IOException

getOutputStream

public java.io.OutputStream getOutputStream(boolean append)
                                     throws java.io.IOException
Get an output stream to write to this file.

Specified by:
getOutputStream in interface AbstractFile
Returns:
output stream
Throws:
java.io.IOException - if canWrite returns false
See Also:
canWrite()

getExtension

public java.lang.String getExtension()
Get the extension, which indicates the type of file. Usually the extension is part of the filename, ie. if the extension was os, the filename would end with .os.

Specified by:
getExtension in interface AbstractFile
Returns:
a string indicating the type of file

getPath

public java.lang.String getPath()
Get the file path, which globally identifies the file.

Specified by:
getPath in interface AbstractFile
Returns:
a unique string
See Also:
getName()

getName

public java.lang.String getName()
Get the name of this file, which is the last component of the complete path.

Specified by:
getName in interface AbstractFile
Returns:
the file name
See Also:
getPath()

toString

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

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

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