org.peace_tools.core
Class FileInfo

java.lang.Object
  extended by org.peace_tools.core.FileInfo

public class FileInfo
extends java.lang.Object

This is a simple class that is used to encapsulate information about a given file. This class was introduced to enable handing back consistent information about files both on local and remote servers.


Field Summary
private  int attributes
          The various attributes defining the file.
static int DIR_ATTRIB
          Bit value indicating if this entry is a directory.
static int EXEC_ATTRIB
          Bit value indicating if this entry is executable.
static int FILE_ATTRIB
          Bit value indicating if this entry is a regular file.
private  long lastModified
          A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs
private  java.lang.String path
          The absolute path to the file referenced by this file attribute.
static int READ_ATTRIB
          Bit value indicating if this entry is readable.
private  long size
          The size of the file in bytes.
static int WRITE_ATTRIB
          Bit value indicating if this entry is writable.
 
Constructor Summary
FileInfo(java.lang.String absolutePath, long lastModified, long size, int attributes)
          Create a complete file information class with all the information.
 
Method Summary
 boolean canExecute()
          Determine if this entry is executable.
 boolean canRead()
          Determine if this entry is readable.
 boolean canWrite()
          Determine if this entry is writable.
 boolean exists()
          Determine if this entry exists.
 long getLastModified()
          Returns the time that the file denoted by this abstract file information was last modified.
 java.lang.String getPath()
          The path to the file represented by this object.
 long getSize()
          The size of the file in bytes.
 boolean isDirectory()
          Determine if this entry is a directory.
 boolean isFile()
          Determine if this entry is a regular file.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DIR_ATTRIB

public static final int DIR_ATTRIB
Bit value indicating if this entry is a directory. If this bit value is set in the file attributes then this entry is a directory.

See Also:
Constant Field Values

FILE_ATTRIB

public static final int FILE_ATTRIB
Bit value indicating if this entry is a regular file. If this bit value is set in the file attributes then this entry is a regular file.

See Also:
Constant Field Values

READ_ATTRIB

public static final int READ_ATTRIB
Bit value indicating if this entry is readable. If this bit value is set in the file attributes then this entry can be read by the user.

See Also:
Constant Field Values

WRITE_ATTRIB

public static final int WRITE_ATTRIB
Bit value indicating if this entry is writable. If this bit value is set in the file attributes then this entry can be written to by the user.

See Also:
Constant Field Values

EXEC_ATTRIB

public static final int EXEC_ATTRIB
Bit value indicating if this entry is executable. If this bit value is set in the file attributes then this entry can be executed by the user.

See Also:
Constant Field Values

path

private final java.lang.String path
The absolute path to the file referenced by this file attribute. This value is set in the constructor.


lastModified

private final long lastModified
A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs


size

private long size
The size of the file in bytes. This value is -1 if the file does not exist.


attributes

private int attributes
The various attributes defining the file. These attributes are built by bitwise OR-ing together the various attributes defined in this class (ex: FileInfo.FILE_ATTRIB | FileInfo.READ_ATTRIB). If the file does not exist then the attributes must be 0.

Constructor Detail

FileInfo

public FileInfo(java.lang.String absolutePath,
                long lastModified,
                long size,
                int attributes)
Create a complete file information class with all the information. This constructor must be used to create a complete object that contains all the associated information regarding a given file entry.

Parameters:
absolutePath - The absolute path to the given file on a given host.
lastModified - A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs.
size - The size of the file in bytes. This value may be meaningful only for regular files.
attributes - The various attributes defining the file. These attributes are built by bitwise OR-ing together the various attributes defined in this class (ex: FileInfo.FILE_ATTRIB | FileInfo.READ_ATTRIB). If the file does not exist then the attributes must be 0.
Method Detail

getPath

public java.lang.String getPath()
The path to the file represented by this object.

Returns:
The absolute path to the file.

getSize

public long getSize()
The size of the file in bytes.

Returns:
The size of the file in bytes. If the file does not exist then this method returns -1.

exists

public boolean exists()
Determine if this entry exists.

Returns:
This method returns true if the file corresponding to this abstract entry exists.

isDirectory

public boolean isDirectory()
Determine if this entry is a directory.

Returns:
This method returns true if the entry is a directory. The return value is valid only if the entry exists.

isFile

public boolean isFile()
Determine if this entry is a regular file.

Returns:
This method returns true if the entry is a regular file. The return value is valid only if the entry exists.

canRead

public boolean canRead()
Determine if this entry is readable.

Returns:
This method returns true if the entry is readable by the user. The return value is valid only if the entry exists.

canWrite

public boolean canWrite()
Determine if this entry is writable.

Returns:
This method returns true if the entry is writable by the user. The return value is valid only if the entry exists.

canExecute

public boolean canExecute()
Determine if this entry is executable.

Returns:
This method returns true if the entry is executable by the user. The return value is valid only if the entry exists.

getLastModified

public long getLastModified()
Returns the time that the file denoted by this abstract file information was last modified.

Returns:
A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist.

toString

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