Class FileWatcher

  • All Implemented Interfaces:
    java.io.FileFilter

    class FileWatcher
    extends java.lang.Object
    implements java.io.FileFilter
    The FileWatcher object is used to create files that are to be used for file buffers. All files created by this are created in the java.io.tmpdir path. Temporary files created in this directory last for a configurable length of time before they are deleted.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private long duration
      This is the duration the files created will exist for.
      private java.lang.String prefix
      This is the prefix for the temporary files created.
    • Constructor Summary

      Constructors 
      Constructor Description
      FileWatcher​(java.lang.String prefix)
      Constructor for the FileWatcher object.
      FileWatcher​(java.lang.String prefix, long duration)
      Constructor for the FileWatcher object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean accept​(java.io.File file)
      This determines if the file provided is an acceptable file for deletion.
      private boolean accept​(java.io.File file, java.lang.String name)
      This determines if the file provided is an acceptable file for deletion.
      private void clean​(java.io.File path)
      When this method is invoked the files that match the pattern of the temporary files are evaluated for deletion.
      java.io.File create()
      This will create a temporary file which can be used as a buffer for FileBuffer objects.
      private java.io.File create​(java.lang.String prefix)
      This will create a temporary file which can be used as a buffer for FileBuffer objects.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • prefix

        private final java.lang.String prefix
        This is the prefix for the temporary files created.
      • duration

        private final long duration
        This is the duration the files created will exist for.
    • Constructor Detail

      • FileWatcher

        public FileWatcher​(java.lang.String prefix)
        Constructor for the FileWatcher object. This will allow temporary files to exist for five minutes. After this time the will be removed from the underlying directory. Any request for a new file will result in a sweep of the temporary directory for all matching files, if they have expired they will be deleted.
        Parameters:
        prefix - this is the file name prefix for the files
      • FileWatcher

        public FileWatcher​(java.lang.String prefix,
                           long duration)
        Constructor for the FileWatcher object. This will allow temporary files to exist for a configurable length of time. After this time the will be removed from the underlying directory. Any request for a new file will result in a sweep of the temporary directory for all matching files, if they have expired they will be deleted.
        Parameters:
        prefix - this is the file name prefix for the files
        duration - this is the duration the files exist for
    • Method Detail

      • create

        public java.io.File create()
                            throws java.io.IOException
        This will create a temporary file which can be used as a buffer for FileBuffer objects. The file returned by this method will be created before it is returned, which ensures it can be used as a means to buffer bytes. All files are created in the java.io.tmpdir location, which represents the underlying file system temporary file destination.
        Returns:
        this returns a created temporary file for buffers
        Throws:
        java.io.IOException
      • create

        private java.io.File create​(java.lang.String prefix)
                             throws java.io.IOException
        This will create a temporary file which can be used as a buffer for FileBuffer objects. The file returned by this method will be created before it is returned, which ensures it can be used as a means to buffer bytes. All files are created in the java.io.tmpdir location, which represents the underlying file system temporary file destination.
        Parameters:
        prefix - this is the prefix of the file to be created
        Returns:
        this returns a created temporary file for buffers
        Throws:
        java.io.IOException
      • clean

        private void clean​(java.io.File path)
                    throws java.io.IOException
        When this method is invoked the files that match the pattern of the temporary files are evaluated for deletion. Only those files that have not been modified in the duration period can be deleted. This ensures the file system is not exhausted.
        Parameters:
        path - this is the path of the file to be evaluated
        Throws:
        java.io.IOException
      • accept

        public boolean accept​(java.io.File file)
        This determines if the file provided is an acceptable file for deletion. Acceptable files are those that match the pattern of files created by this file system object. If the file is a matching file then it is a candidate for deletion.
        Specified by:
        accept in interface java.io.FileFilter
        Parameters:
        file - this is the file to evaluate for deletion
        Returns:
        this returns true if the file matches the pattern
      • accept

        private boolean accept​(java.io.File file,
                               java.lang.String name)
        This determines if the file provided is an acceptable file for deletion. Acceptable files are those that match the pattern of files created by this file system object. If the file is a matching file then it is a candidate for deletion.
        Parameters:
        file - this is the file to evaluate for deletion
        name - this is the name of the file to be evaluated
        Returns:
        this returns true if the file matches the pattern