Package adams.core.io.lister
Class LocalDirectoryLister
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.io.lister.AbstractDirectoryLister
-
- adams.core.io.lister.AbstractRecursiveDirectoryLister
-
- adams.core.io.lister.LocalDirectoryLister
-
- All Implemented Interfaces:
DirectoryLister
,RecursiveDirectoryLister
,RelativeDirectoryLister
,LoggingLevelHandler
,LoggingSupporter
,SizeOfHandler
,Stoppable
,StoppableWithFeedback
,Serializable
public class LocalDirectoryLister extends AbstractRecursiveDirectoryLister implements RelativeDirectoryLister
Lists files/dirs in a directory.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected BaseDateTime
m_MaxFileTimestamp
the maximum file timestamp ("last modified").protected BaseDateTime
m_MinFileTimestamp
the minimum file timestamp ("last modified").protected boolean
m_SkipLockedFiles
whether to skip locked files.protected String
m_StopFile
the name of the "stop file" which results in an empty list to be returned.protected boolean
m_StopFileEncountered
whether the stop file was encountered.protected boolean
m_UseRelativePaths
whether to output relative paths.-
Fields inherited from class adams.core.io.lister.AbstractRecursiveDirectoryLister
m_MaxDepth, m_Recursive
-
Fields inherited from class adams.core.io.lister.AbstractDirectoryLister
m_ListDirs, m_ListFiles, m_MaxItems, m_RegExp, m_SortDescending, m_Sorting, m_Stopped, m_WatchDir
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description LocalDirectoryLister()
Initializes the object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BaseDateTime
getMaxFileTimestamp()
Returns the maximum file timestamp ("last modified") that the files need to have.BaseDateTime
getMinFileTimestamp()
Returns the minimum file timestamp ("last modified") that the files need to have.boolean
getSkipLockedFiles()
Returns whether locked files are skipped.String
getStopFile()
Returns the name of the stop file which results in returning an empty list.boolean
getUseRelativePaths()
Returns whether to output relative paths.boolean
hasParentDirectory()
Returns whether the watch directory has a parent directory.boolean
hasStopFileEncountered()
Returns whether the stop file was encountered or not.protected boolean
isFileLocked(File file)
Checks whether the file is currently locked by another process.boolean
isLocal()
Returns whether the directory lister operates locally or remotely.String[]
list()
Returns the list of files/directories in the watched directory.FileObject[]
listObjects()
Returns the list of files/directories in the watched directory.static void
main(String[] args)
For testing only.LocalFileObject
newDirectory(String dir)
Returns a new directory relative to the watch directory.LocalFileObject
newDirectory(String parent, String dir)
Returns a new directory generated from parent and sub-directory.protected void
search(File current, List<SortContainer> files, int depth)
Performs the recursive search.void
setMaxFileTimestamp(BaseDateTime value)
Sets the maximum file timestamp ("last modified") that the files need to have.void
setMinFileTimestamp(BaseDateTime value)
Sets the minimum file timestamp ("last modified") that the files need to have.void
setSkipLockedFiles(boolean value)
Sets whether to skip locked files.void
setStopFile(String value)
Sets the name of the stop file which results in returning an empty list.void
setUseRelativePaths(boolean value)
Sets whether to output relative paths.void
setWatchDir(String value)
Sets the directory to watch.String
toString()
A string representation of the object.-
Methods inherited from class adams.core.io.lister.AbstractRecursiveDirectoryLister
getMaxDepth, getRecursive, setMaxDepth, setRecursive
-
Methods inherited from class adams.core.io.lister.AbstractDirectoryLister
getDebug, getListDirs, getListFiles, getMaxItems, getRegExp, getSortDescending, getSorting, getWatchDir, isStopped, setDebug, setListDirs, setListFiles, setMaxItems, setRegExp, setSortDescending, setSorting, stopExecution
-
Methods inherited from class adams.core.logging.CustomLoggingLevelObject
setLoggingLevel
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.io.lister.DirectoryLister
getListDirs, getListFiles, getMaxItems, getRegExp, getSortDescending, getSorting, getWatchDir, setListDirs, setListFiles, setMaxItems, setRegExp, setSortDescending, setSorting
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel, setLoggingLevel
-
Methods inherited from interface adams.core.logging.LoggingSupporter
getLogger, isLoggingEnabled
-
Methods inherited from interface adams.core.Stoppable
stopExecution
-
Methods inherited from interface adams.core.StoppableWithFeedback
isStopped
-
-
-
-
Field Detail
-
m_StopFile
protected String m_StopFile
the name of the "stop file" which results in an empty list to be returned.
-
m_StopFileEncountered
protected boolean m_StopFileEncountered
whether the stop file was encountered.
-
m_SkipLockedFiles
protected boolean m_SkipLockedFiles
whether to skip locked files.
-
m_MinFileTimestamp
protected BaseDateTime m_MinFileTimestamp
the minimum file timestamp ("last modified").
-
m_MaxFileTimestamp
protected BaseDateTime m_MaxFileTimestamp
the maximum file timestamp ("last modified").
-
m_UseRelativePaths
protected boolean m_UseRelativePaths
whether to output relative paths.
-
-
Method Detail
-
setWatchDir
public void setWatchDir(String value)
Sets the directory to watch.- Specified by:
setWatchDir
in interfaceDirectoryLister
- Overrides:
setWatchDir
in classAbstractDirectoryLister
- Parameters:
value
- the directory
-
setStopFile
public void setStopFile(String value)
Sets the name of the stop file which results in returning an empty list.- Parameters:
value
- the name of the file
-
getStopFile
public String getStopFile()
Returns the name of the stop file which results in returning an empty list.- Returns:
- the name of the file
-
setSkipLockedFiles
public void setSkipLockedFiles(boolean value)
Sets whether to skip locked files. Depends on the underlying OS, whether a file is flagged as locked. E.g., in a JVM under Linux, one would have to lock the file explicitly usingjava.nio.channels.FileChannel.lock()
, since simply opening it for writing does not lock it.- Parameters:
value
- if true then locked files will be skipped
-
getSkipLockedFiles
public boolean getSkipLockedFiles()
Returns whether locked files are skipped.- Returns:
- true if locked files are skipped
-
setMinFileTimestamp
public void setMinFileTimestamp(BaseDateTime value)
Sets the minimum file timestamp ("last modified") that the files need to have.- Parameters:
value
- the minimum timestamp
-
getMinFileTimestamp
public BaseDateTime getMinFileTimestamp()
Returns the minimum file timestamp ("last modified") that the files need to have.- Returns:
- the minimum timestamp
-
setMaxFileTimestamp
public void setMaxFileTimestamp(BaseDateTime value)
Sets the maximum file timestamp ("last modified") that the files need to have.- Parameters:
value
- the maximum timestamp
-
getMaxFileTimestamp
public BaseDateTime getMaxFileTimestamp()
Returns the maximum file timestamp ("last modified") that the files need to have.- Returns:
- the maximum timestamp
-
setUseRelativePaths
public void setUseRelativePaths(boolean value)
Sets whether to output relative paths.- Specified by:
setUseRelativePaths
in interfaceRelativeDirectoryLister
- Parameters:
value
- true if to output relative paths
-
getUseRelativePaths
public boolean getUseRelativePaths()
Returns whether to output relative paths.- Specified by:
getUseRelativePaths
in interfaceRelativeDirectoryLister
- Returns:
- true if to output relative paths
-
hasStopFileEncountered
public boolean hasStopFileEncountered()
Returns whether the stop file was encountered or not.- Returns:
- true if stop file encountered
-
isFileLocked
protected boolean isFileLocked(File file)
Checks whether the file is currently locked by another process.- Parameters:
file
- the file to check- Returns:
- true if the file is locked
-
isLocal
public boolean isLocal()
Returns whether the directory lister operates locally or remotely.- Specified by:
isLocal
in interfaceDirectoryLister
- Returns:
- true if local lister
-
hasParentDirectory
public boolean hasParentDirectory()
Returns whether the watch directory has a parent directory.- Specified by:
hasParentDirectory
in interfaceDirectoryLister
- Returns:
- true if parent directory available
-
newDirectory
public LocalFileObject newDirectory(String dir)
Returns a new directory relative to the watch directory.- Specified by:
newDirectory
in interfaceDirectoryLister
- Parameters:
dir
- the directory name- Returns:
- the new wrapper
-
newDirectory
public LocalFileObject newDirectory(String parent, String dir)
Returns a new directory generated from parent and sub-directory.- Specified by:
newDirectory
in interfaceDirectoryLister
- Parameters:
parent
- the parent directorydir
- the directory name- Returns:
- the new wrapper
-
search
protected void search(File current, List<SortContainer> files, int depth)
Performs the recursive search. Search goes deeper if != 0 (use -1 to start with for infinite search).- Parameters:
current
- the current directoryfiles
- the files collected so fardepth
- the depth indicator (searched no deeper, if 0)
-
list
public String[] list()
Returns the list of files/directories in the watched directory. In case the execution gets stopped, this method returns a 0-length array.- Specified by:
list
in interfaceDirectoryLister
- Returns:
- the list of absolute file/directory names
-
listObjects
public FileObject[] listObjects()
Returns the list of files/directories in the watched directory. In case the execution gets stopped, this method returns a 0-length array.- Specified by:
listObjects
in interfaceDirectoryLister
- Returns:
- the list of file/directory wrappers
-
toString
public String toString()
A string representation of the object.- Overrides:
toString
in classAbstractRecursiveDirectoryLister
- Returns:
- the string representation
-
-