Class FileLister

  • All Implemented Interfaces:
    adams.core.AdditionalInformationHandler, adams.core.ArrayProvider, adams.core.AtomicMoveSupporter, adams.core.CleanUpHandler, adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.QuickInfoSupporter, adams.core.ShallowCopySupporter<AbstractRatInput>, adams.core.SizeOfHandler, adams.core.Stoppable, adams.core.StoppableWithFeedback, RatInput, Serializable

    public class FileLister
    extends AbstractRatInput
    implements adams.core.AtomicMoveSupporter, adams.core.ArrayProvider
    Polls files in a directory and forwards them.
    It can skip files that are currently flagged as 'in use'.
    Moving files to the specified target directory will continue, even if errors are occurred with some files (NB: you may end up with a very large error message if all files from a large list of files are failing).

    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -source <adams.core.io.PlaceholderDirectory> (property: source)
        The directory to watch for incoming files.
        default: ${CWD}
     
    -regexp <adams.core.base.BaseRegExp> (property: regExp)
        The regular expression that the files must match.
        default: .*
     
    -max-files <int> (property: maxFiles)
        The maximum number of files to list; -1 for unlimited.
        default: -1
        minimum: -1
     
    -sorting <NO_SORTING|SORT_BY_NAME|SORT_BY_LAST_MODIFIED> (property: sorting)
        The type of sorting to perform.
        default: NO_SORTING
     
    -sort-descending <boolean> (property: sortDescending)
        If enabled, the sort direction is descending.
        default: false
     
    -wait-list <int> (property: waitList)
        The number of milli-seconds to wait after listing the files.
        default: 0
        minimum: 0
     
    -move-files <boolean> (property: moveFiles)
        If enabled, the files get moved to the specified directory first before 
        being transmitted (with their new filename).
        default: false
     
    -skip-in-use <boolean> (property: skipInUse)
        If enabled, then files are that currently 'in use' get removed from the 
        list.
        default: false
     
    -check <adams.core.io.fileuse.AbstractFileUseCheck> (property: check)
        If scheme to use checking the 'in use' state of a file.
        default: adams.core.io.fileuse.Default
     
    -atomic-move <boolean> (property: atomicMove)
        If true, then an atomic move operation will be attempted (NB: not supported 
        by all operating systems).
        default: false
     
    -target <adams.core.io.PlaceholderDirectory> (property: target)
        The directory to move the files to before transmitting their names.
        default: ${CWD}
     
    -output-array <boolean> (property: outputArray)
        If enabled, the files get output as array rather than one-by-one.
        default: false
     
    -report-moving-errors <boolean> (property: reportMovingErrors)
        If enabled, errors encountered while moving files get reported rather than
        just logged as warnings.
        default: false
     
    Version:
    $Revision$
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_Lister

        protected adams.core.io.lister.LocalDirectoryLister m_Lister
        the lister for listing the files.
      • m_Files

        protected List<String> m_Files
        the located files.
      • m_WaitList

        protected int m_WaitList
        the waiting period in msec after listing the files.
      • m_MoveFiles

        protected boolean m_MoveFiles
        whether to move the files before transmitting them.
      • m_SkipInUse

        protected boolean m_SkipInUse
        whether to skip 'in-use' files.
      • m_Check

        protected adams.core.io.fileuse.AbstractFileUseCheck m_Check
        the 'in use' check scheme.
      • m_AtomicMove

        protected boolean m_AtomicMove
        whether to perform an atomic move.
      • m_Target

        protected adams.core.io.PlaceholderDirectory m_Target
        the directory to move the files to.
      • m_OutputArray

        protected boolean m_OutputArray
        whether to output an array instead of single items.
      • m_ReportMovingErrors

        protected boolean m_ReportMovingErrors
        whether to return errors when moving files.
    • Constructor Detail

      • FileLister

        public FileLister()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing the object.
        Specified by:
        globalInfo in interface adams.core.GlobalInfoSupporter
        Specified by:
        globalInfo in class adams.core.option.AbstractOptionHandler
        Returns:
        a description suitable for displaying in the gui
      • defineOptions

        public void defineOptions()
        Adds options to the internal list of options.
        Specified by:
        defineOptions in interface adams.core.option.OptionHandler
        Overrides:
        defineOptions in class adams.core.option.AbstractOptionHandler
      • setLoggingLevel

        public void setLoggingLevel​(adams.core.logging.LoggingLevel value)
        Sets the logging level.
        Specified by:
        setLoggingLevel in interface adams.core.logging.LoggingLevelHandler
        Overrides:
        setLoggingLevel in class adams.core.option.AbstractOptionHandler
        Parameters:
        value - the level
      • setSource

        public void setSource​(adams.core.io.PlaceholderDirectory value)
        Sets the incoming directory.
        Parameters:
        value - the incoming directory
      • getSource

        public adams.core.io.PlaceholderDirectory getSource()
        Returns the incoming directory.
        Returns:
        the incoming directory.
      • sourceTipText

        public String sourceTipText()
        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​(adams.core.base.BaseRegExp value)
        Sets the regular expression for the files.
        Parameters:
        value - the regular expression
      • getRegExp

        public adams.core.base.BaseRegExp getRegExp()
        Returns the regular expression for the files.
        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.
      • setMaxFiles

        public void setMaxFiles​(int value)
        Sets the maximum number of files to list.
        Parameters:
        value - the maximum, -1 for unlimited
      • getMaxFiles

        public int getMaxFiles()
        Returns the maximum number of files to list.
        Returns:
        the maximum, -1 for unlimited
      • maxFilesTipText

        public String maxFilesTipText()
        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​(adams.core.io.lister.Sorting value)
        Sets the sorting type.
        Parameters:
        value - the sorting
      • getSorting

        public adams.core.io.lister.Sorting getSorting()
        Returns the sorting type.
        Returns:
        the 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 in descending manner.
        Parameters:
        value - true if desending sort manner
      • getSortDescending

        public boolean getSortDescending()
        Returns whether to sort in descending manner.
        Returns:
        true if descending sort manner
      • 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.
      • setWaitList

        public void setWaitList​(int value)
        Sets the number of milli-seconds to wait after listing the files.
        Parameters:
        value - the number of milli-seconds
      • getWaitList

        public int getWaitList()
        Returns the number of milli-seconds to wait after listing the files.
        Returns:
        the number of milli-seconds
      • waitListTipText

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

        public void setMoveFiles​(boolean value)
        Sets whether to move the files to the specified target directory before transmitting them.
        Parameters:
        value - true if to move files
      • getMoveFiles

        public boolean getMoveFiles()
        Returns whether to move the files to the specified target directory before transmitting them.
        Returns:
        true if to move files
      • moveFilesTipText

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

        public void setSkipInUse​(boolean value)
        Sets whether to skip files that are currently in use.
        Parameters:
        value - if true then 'in-use' files are skipped
      • getSkipInUse

        public boolean getSkipInUse()
        Returns whether to skip files that are currently in use.
        Returns:
        true if to skip 'in-use' files
      • skipInUseTipText

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

        public void setCheck​(adams.core.io.fileuse.AbstractFileUseCheck value)
        Sets the file 'in use' check scheme.
        Parameters:
        value - the check scheme
      • getCheck

        public adams.core.io.fileuse.AbstractFileUseCheck getCheck()
        Returns the file 'in use' check scheme.
        Returns:
        the check scheme
      • checkTipText

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

        public void setAtomicMove​(boolean value)
        Sets whether to attempt atomic move operation.
        Specified by:
        setAtomicMove in interface adams.core.AtomicMoveSupporter
        Parameters:
        value - if true then attempt atomic move operation
      • getAtomicMove

        public boolean getAtomicMove()
        Returns whether to attempt atomic move operation.
        Specified by:
        getAtomicMove in interface adams.core.AtomicMoveSupporter
        Returns:
        true if to attempt atomic move operation
      • atomicMoveTipText

        public String atomicMoveTipText()
        Returns the tip text for this property.
        Specified by:
        atomicMoveTipText in interface adams.core.AtomicMoveSupporter
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setTarget

        public void setTarget​(adams.core.io.PlaceholderDirectory value)
        Sets the move-to directory.
        Parameters:
        value - the move-to directory
      • getTarget

        public adams.core.io.PlaceholderDirectory getTarget()
        Returns the move-to directory.
        Returns:
        the move-to directory.
      • targetTipText

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

        public void setOutputArray​(boolean value)
        Sets whether to generate data as array or as single objects.
        Specified by:
        setOutputArray in interface adams.core.ArrayProvider
        Parameters:
        value - true if output is an array
      • getOutputArray

        public boolean getOutputArray()
        Returns whether to generate the as array or as single objects.
        Specified by:
        getOutputArray in interface adams.core.ArrayProvider
        Returns:
        true if output is an array
      • outputArrayTipText

        public String outputArrayTipText()
        Returns the tip text for this property.
        Specified by:
        outputArrayTipText in interface adams.core.ArrayProvider
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setReportMovingErrors

        public void setReportMovingErrors​(boolean value)
        Sets whether to report errors encountered while moving files rather than just logging them as warnings.
        Parameters:
        value - true if to report
      • getReportMovingErrors

        public boolean getReportMovingErrors()
        Returns whether to report errors encountered while moving files rather than just logging them as warnings.
        Returns:
        true if to report
      • reportMovingErrorsTipText

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

        public String getQuickInfo()
        Returns a quick info about the actor, which will be displayed in the GUI.
        Specified by:
        getQuickInfo in interface adams.core.QuickInfoSupporter
        Overrides:
        getQuickInfo in class AbstractRatInput
        Returns:
        null if no info available, otherwise short string
      • check

        public String check()
        Hook method for performing checks. Makes sure that directories exist.
        Overrides:
        check in class AbstractRatInput
        Returns:
        null if successful, otherwise error message
      • doReceive

        protected String doReceive()
        Performs the actual reception of data.
        Specified by:
        doReceive in class AbstractRatInput
        Returns:
        null if successful, otherwise error message