Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.io.monitor
Class FileEntry

    java.lang.Object
      org.apache.commons.io.monitor.FileEntry

All Implemented Interfaces:
  Serializable

    public class FileEntry

extends Object
implements Serializable

`FileEntry` represents the state of a file or directory, capturing the following `File` attributes at a point in time.

- File Name (see `File.getName()`)
- Exists - whether the file exists or not (see `File.exists()`)
- Directory - whether the file is a directory or not (see `File.isDirectory()`)
- Last Modified Date/Time (see `File.lastModified()`)
- Length (see `File.length()`) - directories treated as zero
- Children - contents of a directory (see `File.listFiles(java.io.FileFilter)`)

### Custom Implementations

If the state of additional `File` attributes is required then create a custom `FileEntry` with properties for those attributes. Override the `newChildInstance(File)` to return a new instance of the appropriate type. You may also want to override the `refresh(File)` method.

Since:
  Commons IO 2.0
See Also:
  `FileAlterationObserver`, Serialized Form

Constructor Summary
`FileEntry(File file)` Construct a new monitor for a specified `File`.
`FileEntry(FileEntry parent, File file)` Construct a new monitor for a specified `File`.

Method Summary
`FileEntry[]` | `getChildren()` Return the directory's files.
`File` | `getFile()` Return the file being monitored.
`long` | `getLastModified()` Return the last modified time from the last time it was checked.
`long` | `getLength()` Return the length.
`int` | `getLevel()` Return the level
`String` | `getName()` Return the file name.
`FileEntry` | `getParent()` Return the parent entry.
`boolean` | `isDirectory()` Indicate whether the file is a directory or not.
`boolean` | `isExists()` Indicate whether the file existed the last time it was checked.
`FileEntry` | `newChildInstance(File file)` Create a new child instance.
`boolean` | `refresh(File file)` Refresh the attributes from the `File`, indicating whether the file has changed.
`void` | `setChildren(FileEntry[] children)` Set the directory's files.
`void` | `setDirectory(boolean directory)` Set whether the file is a directory or not.
`void` | `setExists(boolean exists)` Set whether the file existed the last time it was checked.
`void` | `setLastModified(long lastModified)` Return the last modified time from the last time it was checked.
`void` | `setLength(long length)` Set the length.
`void` | `setName(String name)` Set the file name.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### FileEntry

    public FileEntry(File file)

  Construct a new monitor for a specified `File`.

  Parameters:
    `file` - The file being monitored

### FileEntry

    public FileEntry(FileEntry parent,
                     File file)

  Construct a new monitor for a specified `File`.

  Parameters:
    `parent` - The parent
    `file` - The file being monitored

Method Detail

### refresh

    public boolean refresh(File file)

  Refresh the attributes from the `File`, indicating whether the file has changed.

  This implementation refreshes the `name`, `exists`, `directory`, `lastModified` and `length` properties.

  The `exists`, `directory`, `lastModified` and `length` properties are compared for changes

  Parameters:
    `file` - the file instance to compare to
  Returns:
    `true` if the file has changed, otherwise `false`

### newChildInstance

    public FileEntry newChildInstance(File file)

  Create a new child instance.

  Custom implementations should override this method to return a new instance of the appropriate type.

  Parameters:
    `file` - The child file
  Returns:
    a new child instance

### getParent

    public FileEntry getParent()

  Return the parent entry.

  Returns:
    the parent entry

### getLevel

    public int getLevel()

  Return the level

  Returns:
    the level

### getChildren

    public FileEntry[] getChildren()

  Return the directory's files.

  Returns:
    This directory's files or an empty array if the file is not a directory or the directory is empty

### setChildren

    public void setChildren(FileEntry[] children)

  Set the directory's files.

  Parameters:
    `children` - This directory's files, may be null

### getFile

    public File getFile()

  Return the file being monitored.

  Returns:
    the file being monitored

### getName

    public String getName()

  Return the file name.

  Returns:
    the file name

### setName

    public void setName(String name)

  Set the file name.

  Parameters:
    `name` - the file name

### getLastModified

    public long getLastModified()

  Return the last modified time from the last time it was checked.

  Returns:
    the last modified time

### setLastModified

    public void setLastModified(long lastModified)

  Return the last modified time from the last time it was checked.

  Parameters:
    `lastModified` - The last modified time

### getLength

    public long getLength()

  Return the length.

  Returns:
    the length

### setLength

    public void setLength(long length)

  Set the length.

  Parameters:
    `length` - the length

### isExists

    public boolean isExists()

  Indicate whether the file existed the last time it was checked.

  Returns:
    whether the file existed

### setExists

    public void setExists(boolean exists)

  Set whether the file existed the last time it was checked.

  Parameters:
    `exists` - whether the file exists or not

### isDirectory

    public boolean isDirectory()

  Indicate whether the file is a directory or not.

  Returns:
    whether the file is a directory or not

### setDirectory

    public void setDirectory(boolean directory)

  Set whether the file is a directory or not.

  Parameters:
    `directory` - whether the file is a directory or not

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2010 The Apache Software Foundation. All Rights Reserved.