Class DirectoryLister

  • All Implemented Interfaces:
    AdditionalInformationHandler, ArrayProvider, CleanUpHandler, Destroyable, GlobalInfoSupporter, ForwardSlashSupporter, LoggingLevelHandler, LoggingSupporter, OptionHandler, QuickInfoSupporter, ShallowCopySupporter<Actor>, SizeOfHandler, Stoppable, StoppableWithFeedback, VariablesInspectionHandler, VariableChangeListener, Actor, ArrayProvider, ErrorHandler, OutputProducer, Serializable, Comparable

    public class DirectoryLister
    extends AbstractArrayProvider
    implements ForwardSlashSupporter
    Returns the contents of a directory (files/dirs).

    Input/output:
    - generates:
       java.lang.String


    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -name <java.lang.String> (property: name)
        The name of the actor.
        default: DirectoryLister
     
    -annotation <adams.core.base.BaseAnnotation> (property: annotations)
        The annotations to attach to this actor.
        default: 
     
    -skip <boolean> (property: skip)
        If set to true, transformation is skipped and the input token is just forwarded 
        as it is.
        default: false
     
    -stop-flow-on-error <boolean> (property: stopFlowOnError)
        If set to true, the flow execution at this level gets stopped in case this 
        actor encounters an error; the error gets propagated; useful for critical 
        actors.
        default: false
     
    -silent <boolean> (property: silent)
        If enabled, then no errors are output in the console; Note: the enclosing 
        actor handler must have this enabled as well.
        default: false
     
    -output-array <boolean> (property: outputArray)
        Whether to output the files as array or as single strings.
        default: false
     
    -dir <adams.core.io.PlaceholderDirectory> (property: watchDir)
        The directory to watch for files/directories.
        default: ${CWD}
     
    -list-dirs <boolean> (property: listDirs)
        Whether to include directories in the output.
        default: false
     
    -list-files <boolean> (property: listFiles)
        Whether to include files in the output.
        default: false
     
    -max-items <int> (property: maxItems)
        The maximum number of items (files/dirs) to return (<= 0 is unlimited).
        default: -1
     
    -regexp <adams.core.base.BaseRegExp> (property: regExp)
        The regular expression that the files/dirs must match (empty string matches 
        all).
        default: 
     
    -sorting <NO_SORTING|SORT_BY_NAME|SORT_BY_LAST_MODIFIED> (property: sorting)
        The type of sorting to perform.
        default: NO_SORTING
     
    -descending <boolean> (property: sortDescending)
        If set to true, the files are sorted in descending manner.
        default: false
     
    -recursive <boolean> (property: recursive)
        Whether to search recursively or not.
        default: false
     
    -max-depth <int> (property: maxDepth)
        The maximum depth to search in recursive mode (1 = only watch directory, 
        -1 = infinite).
        default: -1
     
    -stop-file <java.lang.String> (property: stopFile)
        The name of the file, that finishes the watching.
        default: STOP.txt
     
    -wait <int> (property: wait)
        The number of seconds to wait before polling the directory again if no elements 
        were retrieved; a value of -1 indicates that polling happens only once.
        default: -1
     
    -always-wait <boolean> (property: alwaysWait)
        If set to true, then the waiting period is enforced between polls, even 
        if there are files/dirs that could get processed.
        default: false
     
    -skip-locked <boolean> (property: skipLockedFiles)
        If set to true, locked files are skipped. Depends on the underlying OS how 
        this is implemented. Under Linux, a JVM would have to lock the file explicitly 
        via java.nio.channels.FileChannel.lock(). Simply opening it for writing 
        does not lock the file.
        default: false
     
    -min-timestamp <adams.core.base.BaseDateTime> (property: minFileTimestamp)
        The minimum file timestamp that the files can have.
        default: -INF
     
    -max-timestamp <adams.core.base.BaseDateTime> (property: maxFileTimestamp)
        The maximum file timestamp that the files can have.
        default: +INF
     
    -use-forward-slashes <boolean> (property: useForwardSlashes)
        If enabled, forward slashes are used in the output (but the '\\' prefix 
        of UNC paths is not converted).
        default: false
     
    Version:
    $Revision$
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_Wait

        protected int m_Wait
        the number of seconds to wait between polls without no entries.
      • m_AlwaysWait

        protected boolean m_AlwaysWait
        whether to always wait between polls, even if other files are still present.
      • m_PauseRequired

        protected boolean m_PauseRequired
        whether a pause before the next polling is required.
      • m_UseForwardSlashes

        protected boolean m_UseForwardSlashes
        whether to output forward slashes.
    • Constructor Detail

      • DirectoryLister

        public DirectoryLister()
    • Method Detail

      • setWatchDir

        public void setWatchDir​(PlaceholderDirectory value)
        Sets the incoming directory.
        Parameters:
        value - the incoming directory
      • getWatchDir

        public PlaceholderDirectory getWatchDir()
        Returns the incoming directory.
        Returns:
        the incoming directory.
      • watchDirTipText

        public String watchDirTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setMaxItems

        public void setMaxItems​(int value)
        Sets the maximum number of items to return.
        Parameters:
        value - the maximum number
      • getMaxItems

        public int getMaxItems()
        Returns the maximum number of items to return.
        Returns:
        the maximum number
      • maxItemsTipText

        public String maxItemsTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setRegExp

        public void setRegExp​(BaseRegExp value)
        Sets the regular expression for the files/dirs.
        Parameters:
        value - the regular expression
      • getRegExp

        public BaseRegExp getRegExp()
        Returns the regular expression for the files/dirs.
        Returns:
        the regular expression
      • regExpTipText

        public String regExpTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setStopFile

        public void setStopFile​(String value)
        Sets the name of the stop file.
        Parameters:
        value - the regular expression
      • getStopFile

        public String getStopFile()
        Returns the name of the stop file.
        Returns:
        the name
      • stopFileTipText

        public String stopFileTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setListDirs

        public void setListDirs​(boolean value)
        Sets whether to list directories.
        Parameters:
        value - true if directories are to be listed
      • getListDirs

        public boolean getListDirs()
        Returns whether directories are listed.
        Returns:
        true if directories are listed
      • listDirsTipText

        public String listDirsTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setListFiles

        public void setListFiles​(boolean value)
        Sets whether to list files.
        Parameters:
        value - true if files are to be listed
      • getListFiles

        public boolean getListFiles()
        Returns whether directories are listed.
        Returns:
        true if directories are listed
      • listFilesTipText

        public String listFilesTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setSorting

        public void setSorting​(Sorting value)
        Sets the type of sorting to perform.
        Parameters:
        value - the type of sorting
      • getSorting

        public Sorting getSorting()
        Returns the type of sorting to perform.
        Returns:
        the type of sorting
      • sortingTipText

        public String sortingTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setSortDescending

        public void setSortDescending​(boolean value)
        Sets whether to sort descendingly.
        Parameters:
        value - true if sorting in descending order
      • getSortDescending

        public boolean getSortDescending()
        Returns whether to sort descendingly.
        Returns:
        true if sorting in descending order
      • sortDescendingTipText

        public String sortDescendingTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setWait

        public void setWait​(int value)
        Sets the number of seconds to wait before polling the directory again if no elements were retrieved.
        Parameters:
        value - the number of seconds
      • getWait

        public int getWait()
        Returns the number of seconds to wait before polling the directory again if no elements were retrieved.
        Returns:
        the number of seconds
      • waitTipText

        public String waitTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setAlwaysWait

        public void setAlwaysWait​(boolean value)
        Sets whether to always wait in between polls, even if there are still other files that could get processed.
        Parameters:
        value - if true then waiting period is enforced between polls
      • getAlwaysWait

        public boolean getAlwaysWait()
        Returns whether to always wait in between polls, even if there are still other files that could get processed.
        Returns:
        true if waiting period is enforced between polls
      • alwaysWaitTipText

        public String alwaysWaitTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setRecursive

        public void setRecursive​(boolean value)
        Sets whether to search recursively.
        Parameters:
        value - true if search is recursively
      • getRecursive

        public boolean getRecursive()
        Returns whether search is recursively.
        Returns:
        true if search is recursively
      • recursiveTipText

        public String recursiveTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setMaxDepth

        public void setMaxDepth​(int value)
        Sets the maximum depth to search (in recursive mode). 1 = only watch directory, -1 = infinite.
        Parameters:
        value - the maximum number of directory levels to traverse
      • getMaxDepth

        public int getMaxDepth()
        Returns the maximum depth to search (in recursive mode). 1 = only watch directory, -1 = infinite.
        Returns:
        the maximum number of directory levels to traverse
      • maxDepthTipText

        public String maxDepthTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • 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 using java.nio.channels.FileChannel.lock(), since simply opening it for writing does not lock it.
        Parameters:
        value - if true then locked files are skipped
      • getSkipLockedFiles

        public boolean getSkipLockedFiles()
        Returns whether to skip locked files.
        Returns:
        true if locked files are skipped
      • skipLockedFilesTipText

        public String skipLockedFilesTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setMinFileTimestamp

        public void setMinFileTimestamp​(BaseDateTime value)
        Sets the minimum file timestamp that the files have to have.
        Parameters:
        value - the minimum file timestamp
      • getMinFileTimestamp

        public BaseDateTime getMinFileTimestamp()
        Returns the minimum file timestamp that the files have to have.
        Returns:
        the minimum file timestamp
      • minFileTimestampTipText

        public String minFileTimestampTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setMaxFileTimestamp

        public void setMaxFileTimestamp​(BaseDateTime value)
        Sets the maximum file timestamp that the files have to have.
        Parameters:
        value - the maximum file timestamp
      • getMaxFileTimestamp

        public BaseDateTime getMaxFileTimestamp()
        Returns the maximum file timestamp that the files have to have.
        Returns:
        the maximum file timestamp
      • maxFileTimestampTipText

        public String maxFileTimestampTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setUseForwardSlashes

        public void setUseForwardSlashes​(boolean value)
        Sets whether to use forward slashes in the output.
        Specified by:
        setUseForwardSlashes in interface ForwardSlashSupporter
        Parameters:
        value - if true then use forward slashes
      • getUseForwardSlashes

        public boolean getUseForwardSlashes()
        Returns whether to use forward slashes in the output.
        Specified by:
        getUseForwardSlashes in interface ForwardSlashSupporter
        Returns:
        true if forward slashes are used
      • useForwardSlashesTipText

        public String useForwardSlashesTipText()
        Returns the tip text for this property.
        Specified by:
        useForwardSlashesTipText in interface ForwardSlashSupporter
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • doExecute

        protected String doExecute()
        Executes the flow item.
        Specified by:
        doExecute in class AbstractActor
        Returns:
        null if everything is fine, otherwise error message
      • isFinished

        public boolean isFinished()
        Returns whether the item has finished. The execute() will be called as long as the isFinished() method returns false.
        Specified by:
        isFinished in interface Actor
        Overrides:
        isFinished in class AbstractActor
        Returns:
        true if finished, false if further calls to execute() are necessary. Only stops when directory lister encountered the stop file or m_Wait=-1.