Package org.ghost4j.util
Class DiskStore
- java.lang.Object
-
- org.ghost4j.util.DiskStore
-
public class DiskStore extends java.lang.Object
Singleton class used to store and retrieve files to / from a temporary disk storage.
-
-
Constructor Summary
Constructors Modifier Constructor Description private
DiskStore()
Private constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.File
addFile(java.lang.String key)
Add a file to the store.java.lang.String
generateUniqueKey()
Generates a unique diskstore key.java.io.File
getFile(java.lang.String key)
Retrieve a File from a store key.static DiskStore
getInstance()
Access to the shared instance.void
removeFile(java.lang.String key)
Remove a file from the store.
-
-
-
Field Detail
-
ROOT_PATH
public static final java.lang.String ROOT_PATH
-
instance
private static DiskStore instance
Shared instance.
-
map
private final java.util.Map<java.lang.String,java.io.File> map
Map used to store references to temprorary files.
-
-
Method Detail
-
getInstance
public static DiskStore getInstance()
Access to the shared instance.- Returns:
- The shared DiskStore instance.
-
generateUniqueKey
public java.lang.String generateUniqueKey()
Generates a unique diskstore key. Use the JVM PID and UUID.- Returns:
- A unique key as string
-
getFile
public java.io.File getFile(java.lang.String key)
Retrieve a File from a store key. If key is unknown, null is returned.- Parameters:
key
- Unique file resource identifier.- Returns:
- File or null (if not found).
-
removeFile
public void removeFile(java.lang.String key) throws java.io.IOException
Remove a file from the store. This also deleted the temporary file from the file system.- Parameters:
key
- Unique file resource identifier.- Throws:
java.io.IOException
- In case the file cannot be deleted.
-
addFile
public java.io.File addFile(java.lang.String key)
Add a file to the store.- Parameters:
key
- File unique identifier.- Returns:
- The generated (empty) file.
-
-