java.lang.Object
org.bzdev.io.DelayedRandomAccessFile
Class to provide delayed opening of a file output stream.
This class is intended to allow classes that have permission to
open a file for reading to delay opening the file until a later
time. The file may be opened by a class that has weaker permissions.
An example of when this class may be useful is when an application has to open a long list of files, perhaps passed to the application on the command line, and these files have to be processed later (the original use case was one in which the files are processed with a security manager installed, but security managers are not available in recent versions of Java). Each java virtual machine has a limit on the number of files that can be simultaneously opened, so opening all the files (if there are enough of them) all at once will not work. This class avoids that issue by allowing permissions to be checked when the constructor is called and then actually opening the file when it is needed (at a later time).
-
Constructor Summary
ConstructorsConstructorDescriptionDelayedRandomAccessFile
(File file, String mode) Constructor given a file Themode
argument has the same values and meaning as the second argument to the constructors forRandomAccessFile
.DelayedRandomAccessFile
(String name, String mode) Constructor given a file name. -
Method Summary
-
Constructor Details
-
DelayedRandomAccessFile
Constructor given a file name. Themode
argument has the same values and meaning as the second argument to the constructors forRandomAccessFile
.- Parameters:
name
- the name of the file to openmode
- the access mode- Throws:
FileNotFoundException
- the file could not be found- See Also:
-
DelayedRandomAccessFile
Constructor given a file Themode
argument has the same values and meaning as the second argument to the constructors forRandomAccessFile
.RandomAccessFile
.- Parameters:
file
- the file to openmode
- the access mode- Throws:
FileNotFoundException
- the file could not be found
-
-
Method Details
-
open
Open the file specified by a constructor. Security tests for permission to open the file were performed when the constructor was called. This method can be called at most one time. The file actually opened is the file with the same canonical path name as the file passed to the constructor.- Returns:
- the output stream for reading the file
- Throws:
FileNotFoundException
- the file could not be found
-