Class FileWatcher
- java.lang.Object
-
- org.simpleframework.common.buffer.FileWatcher
-
- All Implemented Interfaces:
java.io.FileFilter
class FileWatcher extends java.lang.Object implements java.io.FileFilter
TheFileWatcher
object is used to create files that are to be used for file buffers. All files created by this are created in thejava.io.tmpdir
path. Temporary files created in this directory last for a configurable length of time before they are deleted.
-
-
Constructor Summary
Constructors Constructor Description FileWatcher(java.lang.String prefix)
Constructor for theFileWatcher
object.FileWatcher(java.lang.String prefix, long duration)
Constructor for theFileWatcher
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 forFileBuffer
objects.private java.io.File
create(java.lang.String prefix)
This will create a temporary file which can be used as a buffer forFileBuffer
objects.
-
-
-
Constructor Detail
-
FileWatcher
public FileWatcher(java.lang.String prefix)
Constructor for theFileWatcher
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 theFileWatcher
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 filesduration
- 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 forFileBuffer
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 thejava.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 forFileBuffer
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 thejava.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 interfacejava.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 deletionname
- this is the name of the file to be evaluated- Returns:
- this returns true if the file matches the pattern
-
-