public class Storage extends Object
Abstracts the underlying application specific storage system, unlike the FileSystemStorage
this class is a higher level abstraction. The Storage
class is designed to be very portable and as
such it has no support for staple file system capabilities such as hierarchies.
Check out a more thorough discussion of this API here
.
The sample code below shows a simple storage browser tool in action:
Constructor and Description |
---|
Storage() |
Modifier and Type | Method and Description |
---|---|
void |
clearCache()
Storage is cached for faster access, however this might cause a problem with refreshing
objects since they are not cloned.
|
void |
clearStorage()
Deletes all the files in the application storage
|
InputStream |
createInputStream(String name)
Creates an input stream to the given storage source file
|
OutputStream |
createOutputStream(String name)
Creates an output stream to the storage with the given name
|
void |
deleteStorageFile(String name)
Deletes the given file name from the storage
|
int |
entrySize(String name)
Returns the size in bytes of the given entry
|
boolean |
exists(String name)
Returns true if the given storage file exists
|
void |
flushStorageCache()
Flush the storage cache allowing implementations that cache storage objects
to store
|
static Storage |
getInstance()
Returns the storage instance or null if the storage wasn't initialized using
a call to init(String) first.
|
static boolean |
isInitialized()
Returns true if the storage is initialized
|
boolean |
isNormalizeNames()
Indicates whether characters that are typically illegal in filesystems should
be sanitized and replaced with underscore
|
String[] |
listEntries()
Lists the names of the storage files
|
Object |
readObject(String name)
Reads the object from the storage, returns null if the object isn't there
|
void |
setHardCacheSize(int size)
Indicates the caching size, storage can be pretty slow
|
void |
setNormalizeNames(boolean normalizeNames)
Indicates whether characters that are typically illegal in filesystems should
be sanitized and replaced with underscore
|
static void |
setStorageInstance(Storage s)
Allows installing a custom storage instance to provide functionality such as seamless encryption
|
boolean |
writeObject(String name,
Object o)
Writes the given object to storage assuming it is an externalizable type
or one of the supported types.
|
public void setHardCacheSize(int size)
size
- size in elements (not kb!)public static boolean isInitialized()
public static Storage getInstance()
public void clearCache()
public void flushStorageCache()
public void deleteStorageFile(String name)
name
- the name of the storage filepublic void clearStorage()
public OutputStream createOutputStream(String name) throws IOException
name
- the storage file nameIOException
public InputStream createInputStream(String name) throws IOException
name
- the name of the source fileIOException
public boolean exists(String name)
name
- the storage file namepublic String[] listEntries()
public int entrySize(String name)
name
- the name of the entrypublic boolean writeObject(String name, Object o)
Writes the given object to storage assuming it is an externalizable type or one of the supported types.
The sample below demonstrates the usage and registration of the Externalizable
interface:
name
- store nameo
- object to storepublic Object readObject(String name)
Reads the object from the storage, returns null if the object isn't there
The sample below demonstrates the usage and registration of the Externalizable
interface:
name
- name of the storepublic boolean isNormalizeNames()
public void setNormalizeNames(boolean normalizeNames)
normalizeNames
- the normalizeNames to setpublic static void setStorageInstance(Storage s)
s
- the storage instance