tribble.search.disk
Class FFile

java.lang.Object
  extended bytribble.search.disk.FFile
All Implemented Interfaces:
DocumentI, WritableDocumentI

public class FFile
extends java.lang.Object
implements WritableDocumentI

File object.

Since:
2001-05-14
Version:
$Revision: 1.7 $ $Date: 2001/07/16 02:10:12 $
Author:
David R. Tribble (david@tribble.com).
Copyright 2001 by David R. Tribble, all rights reserved.
See Also:
FDirectory

Field Summary
protected  java.io.File m_fname
          File name.
protected  java.io.InputStream m_in
          Input stream for this file.
protected  java.io.OutputStream m_out
          Output stream for this file.
protected  FDirectory m_search
          The directory searcher that found and created this file entry.
protected static java.lang.String[] s_attrNames
          Attribute names.
static int SERIES
          Series number.
 
Constructor Summary
protected FFile(FDirectory dir, java.io.File fname)
          Constructor.
 
Method Summary
 void addAttribute(java.lang.String name)
          Add a new attribute name to this document.
 boolean canRead()
          Determine if this directory file is readable.
 boolean canWrite()
          Determine if this directory file is writable.
 boolean exists()
          Determine if this directory file exists.
 java.lang.Object getAttribute(java.lang.String key)
          Retrieve the value of an attribute for this directory file.
 java.lang.String[] getAttributeNames()
          Retrieve the attribute names for this directory file.
 java.io.InputStream getInputStream()
          Get a readable input stream for this directory file.
 java.lang.String getName()
          Retrieve the name for this directory file.
 java.io.OutputStream getOutputStream()
          Get a writable output stream for this directory file.
 java.lang.String getType()
          Retrieve the type of this directory file.
 boolean isDirectory()
          Determine if this directory file specifies a directory.
 java.util.Date lastModified()
          Determine the date that this directory file was last modified.
 long length()
          Determine the length of this directory file.
 void makeWritable(boolean flag)
          Set the contents of this directory file to be writable.
 void setAttribute(java.lang.String attr, java.lang.Object val)
          Set the value of an attribute for this document.
 void setLastModified(java.util.Date when)
          Set the date that this directory file was last modified.
 void setLength(long len)
          Set the length of the contents of this directory file.
 void setType(java.lang.String type)
          Set the type of this directory file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERIES

public static final int SERIES
Series number.

See Also:
Constant Field Values

s_attrNames

protected static final java.lang.String[] s_attrNames
Attribute names.


m_fname

protected java.io.File m_fname
File name.


m_search

protected FDirectory m_search
The directory searcher that found and created this file entry.


m_in

protected java.io.InputStream m_in
Input stream for this file.


m_out

protected java.io.OutputStream m_out
Output stream for this file.

Constructor Detail

FFile

protected FFile(FDirectory dir,
                java.io.File fname)
Constructor.

Parameters:
dir - The directory searcher that created (and owns) this file.
fname - The filename of this file.
Since:
1.2, 2001-06-15
Method Detail

exists

public boolean exists()
Determine if this directory file exists.

Specified by:
exists in interface DocumentI
Returns:
True if the file exists, otherwise false.
Since:
1.2, 2001-06-15

isDirectory

public boolean isDirectory()
Determine if this directory file specifies a directory.

Specified by:
isDirectory in interface DocumentI
Returns:
True if this file is a directory, otherwise false.
Since:
1.2, 2001-06-15

canRead

public boolean canRead()
Determine if this directory file is readable.

Specified by:
canRead in interface DocumentI
Returns:
True if this file exists and can be read, otherwise false.
Since:
1.2, 2001-06-15
See Also:
getInputStream()

canWrite

public boolean canWrite()
Determine if this directory file is writable.

Specified by:
canWrite in interface DocumentI
Returns:
True if the file exists and can be written to, otherwise false.
Since:
1.2, 2001-06-15
See Also:
getOutputStream()

makeWritable

public void makeWritable(boolean flag)
                  throws java.io.IOException
Set the contents of this directory file to be writable.

Note: Once a file has been set to be unwritable (i.e., to be read-only), it cannot be reset to writable. (This is a limitation of the underlying File class.)

Specified by:
makeWritable in interface WritableDocumentI
Parameters:
flag - True if the file is to be made writable, false if it is not.
Throws:
java.io.IOException - Thrown if the access mode of the file cannot be altered, or if some other error occurs.
Since:
1.6, 2001-07-02
See Also:
canWrite()

length

public long length()
Determine the length of this directory file.

Specified by:
length in interface DocumentI
Returns:
The length of this file, in bytes.
Since:
1.2, 2001-06-15

setLength

public void setLength(long len)
               throws java.lang.UnsupportedOperationException
Set the length of the contents of this directory file.

This operation is not supported.

Specified by:
setLength in interface WritableDocumentI
Parameters:
len - The new length (size) of this document, in units meaningful to the implementation of this interface (typically bytes).
Throws:
java.lang.UnsupportedOperationException - (unchecked) Always thrown, because this method is not implemented for this document type.
Since:
1.6, 2001-07-02
See Also:
length()

lastModified

public java.util.Date lastModified()
Determine the date that this directory file was last modified.

Specified by:
lastModified in interface DocumentI
Returns:
The date that the file was last modified, or null if the date is unknown.
Since:
1.2, 2001-06-15

setLastModified

public void setLastModified(java.util.Date when)
                     throws java.io.IOException
Set the date that this directory file was last modified.

Specified by:
setLastModified in interface WritableDocumentI
Parameters:
when - The new date that this file was last modified. If this is null, no action it taken.
Throws:
java.io.IOException - Thrown if the file time cannot be modified, or if some other error occurs.
Since:
1.6, 2001-07-02
See Also:
lastModified()

getName

public java.lang.String getName()
Retrieve the name for this directory file.

Specified by:
getName in interface DocumentI
Returns:
The filename (pathname) of this directory file.
Since:
1.2, 2001-06-15

getType

public java.lang.String getType()
Retrieve the type of this directory file.

Specified by:
getType in interface DocumentI
Returns:
The type of the file (which is the filename extension or suffix, which can be empty ""). Such a type name is typically suitable for display by some user interface.
Since:
1.2, 2001-06-15

setType

public void setType(java.lang.String type)
             throws java.lang.UnsupportedOperationException
Set the type of this directory file.

This operation is not supported.

Specified by:
setType in interface WritableDocumentI
Parameters:
type - The new type of this document (which can be anything meaningfully interpreted as a document type, typically a filename extension or suffix). Such a type name is typically suitable for display by some user interface.
Throws:
java.lang.UnsupportedOperationException - (unchecked) Always thrown, because this method is not implemented for this document type.
Since:
1.6, 2001-07-02
See Also:
getType()

getAttributeNames

public java.lang.String[] getAttributeNames()
Retrieve the attribute names for this directory file.

Specified by:
getAttributeNames in interface DocumentI
Returns:
An array containing the names of the attributes associated with this file, or null if it has none.
Throws:
java.lang.Exception - Thrown if the information about the file is unobtainable, or if some other error occurs.
Since:
1.5, 2001-06-30
See Also:
DocumentI.getAttribute(java.lang.String), DocumentI.setAttribute(java.lang.String, java.lang.Object)

addAttribute

public void addAttribute(java.lang.String name)
                  throws java.lang.UnsupportedOperationException
Add a new attribute name to this document.

This operation is not supported.

Specified by:
addAttribute in interface WritableDocumentI
Parameters:
name - The name of a new attribute to associate with this document.
Throws:
java.lang.UnsupportedOperationException - (unchecked) Always thrown, because this method is not implemented for this document type.
Since:
1.6, 2001-07-02
See Also:
getAttribute(java.lang.String), setAttribute(java.lang.String, java.lang.Object), getAttributeNames()

getAttribute

public java.lang.Object getAttribute(java.lang.String key)
Retrieve the value of an attribute for this directory file.

Specified by:
getAttribute in interface DocumentI
Parameters:
key - The name of an attribute associated with this directory file. The following attribute names are supported:
    "file"          File
    "fullpath"      String
    "length"        Long
    "modified"      Date
    "name"          String
    "parent"        String
    "path"          String 
Returns:
The value of the specified attribute, or null if this file has no such attribute. Note that the value is returned as a generic Object, meaning that it must be cast into the appropriate type.
Throws:
java.lang.Exception - Thrown if the information about the file is unobtainable, or if some other error occurs.
Since:
1.5, 2001-06-30
See Also:
DocumentI.getAttributeNames()

setAttribute

public void setAttribute(java.lang.String attr,
                         java.lang.Object val)
                  throws java.lang.UnsupportedOperationException
Set the value of an attribute for this document. This method is not supported.

Specified by:
setAttribute in interface DocumentI
Parameters:
attr - The name of an attribute associated with this document.
val - The new value of the specified attribute.
Throws:
java.lang.UnsupportedOperationException - (unchecked) Always thrown, because this method is not implemented for this document type.
Since:
1.5, 2001-06-30
See Also:
DocumentI.getAttributeNames()

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Get a readable input stream for this directory file.

Specified by:
getInputStream in interface DocumentI
Returns:
An input stream, from which the data contents of this directory file can be read.
Throws:
java.io.IOException - Thrown if the file cannot be accessed, or if some other error occurs.
Since:
1.1, 2001-05-14

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Get a writable output stream for this directory file.

Specified by:
getOutputStream in interface WritableDocumentI
Returns:
An output stream, to which the data contents of this directory file can be written.
Throws:
java.io.IOException - Thrown if the file cannot be accessed, or if some other error occurs.
Since:
1.1, 2001-05-14
See Also:
DocumentI.getInputStream()