Class FileWatcher

java.lang.Object
org.simpleframework.common.buffer.FileWatcher
All Implemented Interfaces:
FileFilter

class FileWatcher extends Object implements 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 final long
    This is the duration the files created will exist for.
    private final String
    This is the prefix for the temporary files created.
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    boolean
    accept(File file)
    This determines if the file provided is an acceptable file for deletion.
    private boolean
    accept(File file, String name)
    This determines if the file provided is an acceptable file for deletion.
    private void
    clean(File path)
    When this method is invoked the files that match the pattern of the temporary files are evaluated for deletion.
    This will create a temporary file which can be used as a buffer for FileBuffer objects.
    private File
    create(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 Details

    • prefix

      private final 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 Details

    • FileWatcher

      public FileWatcher(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(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 Details

    • create

      public File create() throws 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:
      IOException
    • create

      private File create(String prefix) throws 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:
      IOException
    • clean

      private void clean(File path) throws 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:
      IOException
    • accept

      public boolean accept(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 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(File file, 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