org.aeonscope.io
Class FileInfo

java.lang.Object
  extended by org.aeonscope.io.FileInfo
All Implemented Interfaces:
IFileInfo, IJDOMProducer

public class FileInfo
extends Object
implements IFileInfo

The default file information implementation.

Author:
Brooke Kuhlmann

Field Summary
static String ATTR_DATE
          The element attribute: date.
static String ATTR_LABEL
          The element attribute: label.
static String ATTR_MD5SUM
          The element attribute: checksum.
static String ATTR_NAME
          The element attribute: name.
static String ATTR_SIZE
          The element attribute: size.
static String ATTR_TIME
          The element attribute: time.
static String ATTR_TYPE
          The element attribute: type.
static String DEFAULT_DATE_FORMAT
          The default date format.
static String DEFAULT_TIME_FORMAT
          The default time format.
static String QMARK
          The default value, rather being null, for file information that is not defined, does not exist, or is simply unknown.
static String TYPE_DIR
          The directory type.
static String TYPE_FILE
          The file type.
static String TYPE_UNKNOWN
          The directory type.
 
Constructor Summary
FileInfo()
          Constructs a null file where the type is "?".
FileInfo(File file)
          Constructs a new file based upon the given file setting the file type equal to the file extension (if found).
FileInfo(String filePath)
          Constructs a new file based upon the given file path setting the file type equal to the file extension (if found).
 
Method Summary
 org.jdom.Element asElement()
          Renders the file name, label, type, size, date, and time attribute information as an XML element.
 org.jdom.Element asElementWithMD5Sum()
          This method does everything that the asElement() does except adds MD5 checksum attribute information to the element.
 String getBasename()
          Answers the base name of the file (i.e.
 String getElementName()
          The element name based on whether the file is a file, directory, or unknown.
 String getExtension()
          Answers the file extension.

Example: "example.txt" yields "txt".

 File getFile()
          Answers the associated file.
 String getLabel()
          The file label which is computed by capitalizing the first letter of the file base name.
 String getLastModifiedDate()
          Answers the last modified file date using the user defined or default format.
 String getLastModifiedTime()
          Answers the last modified file time using the user defined or default format.
 String getMD5Sum()
          Answers the MD5, 32-character hex checksum of a file only as calculation on a directory is excluded.
 String getName()
          Answers the name of the file.
 String getParent()
          Answers the parent path of the file.

Example: "/path/to/file/example.txt" yields "/path/to/file".

 String getPath()
          Answers the path to the file.

Example: "/file/path/example.txt" yields "/file/path/example.txt".

 String getSize()
          Answer the size of the file in human readable format or, in the case of directory, the size is a summation of all files and sub-directories.

Examples: 3 bytes, 12 KB, 10 MB, etc.

 String getType()
          The type of file.
 void setDateFormat(String format)
          Sets the format to use for displaying the date.

Example: yyyy-MM-dd

 void setFile(File file)
          Sets the file based upon the given file.
 void setFile(String path)
          Sets the file based on the given file path.
 void setTimeFormat(String format)
          Sets the format to use for displaying the time.

Example: HH:mm:ss

 String toString()
          The file name + size + checksum + date + time as a string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_FILE

public static final String TYPE_FILE
The file type.

See Also:
Constant Field Values

TYPE_DIR

public static final String TYPE_DIR
The directory type.

See Also:
Constant Field Values

TYPE_UNKNOWN

public static final String TYPE_UNKNOWN
The directory type.

See Also:
Constant Field Values

ATTR_NAME

public static final String ATTR_NAME
The element attribute: name.

See Also:
Constant Field Values

ATTR_LABEL

public static final String ATTR_LABEL
The element attribute: label.

See Also:
Constant Field Values

ATTR_TYPE

public static final String ATTR_TYPE
The element attribute: type.

See Also:
Constant Field Values

ATTR_SIZE

public static final String ATTR_SIZE
The element attribute: size.

See Also:
Constant Field Values

ATTR_MD5SUM

public static final String ATTR_MD5SUM
The element attribute: checksum.

See Also:
Constant Field Values

ATTR_DATE

public static final String ATTR_DATE
The element attribute: date.

See Also:
Constant Field Values

ATTR_TIME

public static final String ATTR_TIME
The element attribute: time.

See Also:
Constant Field Values

QMARK

public static final String QMARK
The default value, rather being null, for file information that is not defined, does not exist, or is simply unknown.

See Also:
Constant Field Values

DEFAULT_DATE_FORMAT

public static final String DEFAULT_DATE_FORMAT
The default date format.

See Also:
Constant Field Values

DEFAULT_TIME_FORMAT

public static final String DEFAULT_TIME_FORMAT
The default time format.

See Also:
Constant Field Values
Constructor Detail

FileInfo

public FileInfo()
Constructs a null file where the type is "?".


FileInfo

public FileInfo(String filePath)
Constructs a new file based upon the given file path setting the file type equal to the file extension (if found).

Parameters:
filePath - The path to the file.

FileInfo

public FileInfo(File file)
Constructs a new file based upon the given file setting the file type equal to the file extension (if found).

Parameters:
file - The file.
Method Detail

getFile

public File getFile()
Description copied from interface: IFileInfo
Answers the associated file.

Specified by:
getFile in interface IFileInfo
Returns:
The associated file, otherwise null.
See Also:
IFileInfo.getFile()

getName

public String getName()
Description copied from interface: IFileInfo
Answers the name of the file.

Specified by:
getName in interface IFileInfo
Returns:
The file name if known, otherwise "?".
See Also:
IFileInfo.getName()

getElementName

public String getElementName()
Description copied from interface: IFileInfo
The element name based on whether the file is a file, directory, or unknown. Used when rendering the file information as an XML element.

Specified by:
getElementName in interface IFileInfo
Returns:
The element name as "file" or "directory", otherwise "unknown" if unable to determine.
See Also:
IFileInfo.getElementName()

getLabel

public String getLabel()
Description copied from interface: IFileInfo
The file label which is computed by capitalizing the first letter of the file base name.

Specified by:
getLabel in interface IFileInfo
Returns:
The file label, otherwise "?" if unknown.
See Also:
IFileInfo.getLabel()

getType

public String getType()
Description copied from interface: IFileInfo
The type of file. By default, the type is determined by file extension or, in the case of a directory, "directory" is used instead.

Specified by:
getType in interface IFileInfo
Returns:
The file type, otherwise "?" if unknown.
See Also:
IFileInfo.getType()

getBasename

public String getBasename()
Description copied from interface: IFileInfo
Answers the base name of the file (i.e. the file name minus the extension).

Example: "example.txt" yields "example".

Specified by:
getBasename in interface IFileInfo
Returns:
The file base name if known, otherwise "?".
See Also:
IFileInfo.getBasename()

getExtension

public String getExtension()
Description copied from interface: IFileInfo
Answers the file extension.

Example: "example.txt" yields "txt".

Specified by:
getExtension in interface IFileInfo
Returns:
The file extension, otherwise "?".
See Also:
IFileInfo.getExtension()

getParent

public String getParent()
Description copied from interface: IFileInfo
Answers the parent path of the file.

Example: "/path/to/file/example.txt" yields "/path/to/file".

Specified by:
getParent in interface IFileInfo
Returns:
The parent path, otherwise "?".
See Also:
IFileInfo.getParent()

getPath

public String getPath()
Description copied from interface: IFileInfo
Answers the path to the file.

Example: "/file/path/example.txt" yields "/file/path/example.txt".

Specified by:
getPath in interface IFileInfo
Returns:
The file path, otherwise "?".
See Also:
IFileInfo.getPath()

getSize

public String getSize()
Description copied from interface: IFileInfo
Answer the size of the file in human readable format or, in the case of directory, the size is a summation of all files and sub-directories.

Examples: 3 bytes, 12 KB, 10 MB, etc.

Specified by:
getSize in interface IFileInfo
Returns:
The size of a file or directory structure.
See Also:
IFileInfo.getSize()

getMD5Sum

public String getMD5Sum()
Description copied from interface: IFileInfo
Answers the MD5, 32-character hex checksum of a file only as calculation on a directory is excluded.

Specified by:
getMD5Sum in interface IFileInfo
Returns:
The file checksum, otherwise "?".
See Also:
IFileInfo.getMD5Sum()

getLastModifiedDate

public String getLastModifiedDate()
Description copied from interface: IFileInfo
Answers the last modified file date using the user defined or default format.

Specified by:
getLastModifiedDate in interface IFileInfo
Returns:
The formatted date, otherwise "?".
See Also:
IFileInfo.getLastModifiedDate()

getLastModifiedTime

public String getLastModifiedTime()
Description copied from interface: IFileInfo
Answers the last modified file time using the user defined or default format.

Specified by:
getLastModifiedTime in interface IFileInfo
Returns:
The formatted time, otherwise "?".
See Also:
IFileInfo.getLastModifiedTime()

setDateFormat

public void setDateFormat(String format)
Description copied from interface: IFileInfo
Sets the format to use for displaying the date.

Example: yyyy-MM-dd

Specified by:
setDateFormat in interface IFileInfo
Parameters:
format - The date format.
See Also:
IFileInfo.setDateFormat(java.lang.String)

setTimeFormat

public void setTimeFormat(String format)
Description copied from interface: IFileInfo
Sets the format to use for displaying the time.

Example: HH:mm:ss

Specified by:
setTimeFormat in interface IFileInfo
Parameters:
format - The time format.
See Also:
IFileInfo.setTimeFormat(java.lang.String)

setFile

public void setFile(String path)
Description copied from interface: IFileInfo
Sets the file based on the given file path.

Specified by:
setFile in interface IFileInfo
Parameters:
path - The file path to set.
See Also:
IFileInfo.setFile(java.lang.String)

setFile

public void setFile(File file)
Description copied from interface: IFileInfo
Sets the file based upon the given file.

Specified by:
setFile in interface IFileInfo
Parameters:
file - The file.
See Also:
IFileInfo.setFile(java.io.File)

toString

public String toString()
The file name + size + checksum + date + time as a string.

Overrides:
toString in class Object
See Also:
Object.toString()

asElement

public org.jdom.Element asElement()
Renders the file name, label, type, size, date, and time attribute information as an XML element. A "?" is used for unknown attributes.

Specified by:
asElement in interface IJDOMProducer
Returns:
A JDOM element.
See Also:
IJDOMProducer.asElement()

asElementWithMD5Sum

public org.jdom.Element asElementWithMD5Sum()
This method does everything that the asElement() does except adds MD5 checksum attribute information to the element. Keep in mind that computing the checksum on a file, especially multiple files, can be an expensive operation. Use with caution.

Returns:
The XML element.