Package com.oss.storage
Class OSSStorageManager
java.lang.Object
com.oss.storage.OSSStorageManager
- All Implemented Interfaces:
StorageManager
This class implements the default storage manager that uses a disk file
to store the content octets of the storage. Each allocation request
results in a temporary file being created in the working directory of
the storage manager. The temporary file name consists of the prefix,
ordinal number and the suffix (e.g., oss12345.tmp, where "oss" is the
prefix, ".tmp" is the suffix and the "12345" is the ordinal number,
used to make the name unique).
- Since:
- ASN.1/Java 1.4-beta A
-
Field Summary
Fields inherited from interface com.oss.asn1.StorageManager
STORAGE_BYTES, STORAGE_CHARS, STORAGE_OBJECTS
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionallocate
(int kind) Allocate a storage of a given kind.void
close()
Terminate the storage manager and release any external resources, that are in use.static File
Create a temporary file.static boolean
Get current setting of the boolean flag, that requests automatic deletion of temporary files created by the allocate().static StorageManager
Return an instance of OSSStorageManager.static String
Get prefix to be used in generating the file's name.static String
Get suffix to be used in generating the file's name.static String
Return the name of the directory, used by the StorageManager to create the files.static void
setDeleteFilesOnExit
(boolean doDelete) Set the boolean flag, that requests automatic deletion of temporary files, created by the allocate().static void
Set prefix to use in generating the file's name.static void
Set suffix to use in generating the file's name.static void
setWorkingDirectory
(String workingDirectory, boolean create) Set the name of the directory to create the files.
-
Constructor Details
-
OSSStorageManager
public OSSStorageManager()
-
-
Method Details
-
getWorkingDirectory
Return the name of the directory, used by the StorageManager to create the files.- Returns:
- current setting of the working directory.
-
setWorkingDirectory
Set the name of the directory to create the files. If theworkingDirectory
argument isnull
then the system dependant default temporary-file directory will be used as a working directory for the storage manager. The default temporary-file directory is specified by the system property "java.io.tmpdir".- Parameters:
workingDirectory
- the name of the directory ornull
if the default temporary-file directory is to be used.create
- instructs the storage manager to create the directory if it does not exist (including intermediate directories).- Throws:
IOException
- if thecreate
isfalse
and the directory does not exist or the if creation of the directory has failed.
-
getPrefix
Get prefix to be used in generating the file's name.- Returns:
- file name prefix.
-
setPrefix
Set prefix to use in generating the file's name.- Parameters:
prefix
- file name prefix.
-
getSuffix
Get suffix to be used in generating the file's name.- Returns:
- file name suffix (file extension).
-
setSuffix
Set suffix to use in generating the file's name. The suffix is appended to the generated name "as is" (no dot '.' is inserted before the suffix when the name is generated).- Parameters:
suffix
- file name suffix.
-
getDeleteFilesOnExit
public static boolean getDeleteFilesOnExit()Get current setting of the boolean flag, that requests automatic deletion of temporary files created by the allocate(). The deletion is attempted when the virtual machine terminates.- Returns:
- true if temporary files were set to be deleted.
-
setDeleteFilesOnExit
public static void setDeleteFilesOnExit(boolean doDelete) Set the boolean flag, that requests automatic deletion of temporary files, created by the allocate(). When thedoDelete
istrue
, all temporary files that were created by the storage manager after the invocation of the setDeleteFilesOnExit() will be deleted when the virtual machine terminates.- Parameters:
doDelete
- true if temporary files should be automatically deleted.
-
generateName
Create a temporary file. The name of the file has the format:wd/PNS
, where 'wd' is the working directory, 'P' - prefix, 'N' - ordinal number and 'S' - suffix.- Returns:
File
object for the name generated.- Throws:
IOException
- if the creation of the temporary file has failed.
-
allocate
Allocate a storage of a given kind.- Specified by:
allocate
in interfaceStorageManager
- Parameters:
kind
- type of the storage to allocate.- Returns:
- allocated storage object.
- Throws:
StorageException
- if the caller requested the storage of an unknown kind.
-
close
public void close()Terminate the storage manager and release any external resources, that are in use.- Specified by:
close
in interfaceStorageManager
-
getInstance
Return an instance of OSSStorageManager.- Returns:
- shared instance.
-