oscript.fs
Interface AbstractFile

All Known Implementing Classes:
AbstractAbstractFile, AbstractFileSystem.BogusFile

public interface AbstractFile

An interface to be implemented by something that can implement file-like operations. Ie read as a stream, write as a stream.

Author:
Rob Clark (rob@ti.com)

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 exists()
          Tests whether this file exists.
 java.lang.String getExtension()
          Get the extension, which indicates the type of file.
 java.io.InputStream getInputStream()
          Get an input stream to read from this 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.
 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()
          Return the length of the file in bytes.
 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.
 void touch()
          Update the timestamp on this file to the current time.
 

Method Detail

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Get an input stream to read from this file.

Returns:
input stream
Throws:
IOException - if canRead returns true
See Also:
canRead()

getOutputStream

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

Returns:
output stream
Throws:
IOException - if canWrite returns false
See Also:
canWrite()

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.

Returns:
larger value indicates more recent modification

length

public long length()
Return the length of the file in bytes.


canRead

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


canWrite

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


exists

public boolean exists()
Tests whether this file exists.

Returns:
true iff the file exists

isDirectory

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

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.

Returns:
true iff this file is a regular file.

createNewFile

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

Returns:
true iff the file does not exist and was successfully created.
Throws:
IOException - if error

touch

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

Throws:
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.

Returns:
true iff the directory is successfully deleted.
Throws:
IOException - if error

mkdir

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

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.

Returns:
true iff directory successfully created
Throws:
java.io.IOException

getPath

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

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.

Returns:
the file name
See Also:
getPath()

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.

Returns:
a string indicating the type of file