Package org.rapidcontext.core.storage
Class ZipStorage
java.lang.Object
org.rapidcontext.core.storage.StorableObject
org.rapidcontext.core.storage.Storage
org.rapidcontext.core.storage.ZipStorage
- All Implemented Interfaces:
Comparable<Storage>
- Direct Known Subclasses:
PluginZipStorage
A persistent data storage and retrieval handler based on a ZIP
file. This class will read both Java property files and binary
files depending on the file extension. The property files are
converted to dictionary object on retrieval.
Note: This storage is read-only. Unpack the ZIP file and use a DirStorage for read-write access.
- Version:
- 1.0
-
Field Summary
Modifier and TypeFieldDescriptionThe ZIP entries and index map.static final String
The dictionary key for the ZIP file location.The ZIP storage paths (identity) map.protected ZipFile
The ZIP file used for locating resources.Fields inherited from class org.rapidcontext.core.storage.Storage
EXT_ALL, EXT_JSON, EXT_PROPERTIES, EXT_XML, EXT_YAML, KEY_MOUNT_OVERLAY_PATH, KEY_MOUNT_OVERLAY_PRIO, KEY_MOUNT_PATH, KEY_MOUNT_TIME, KEY_READWRITE, PATH_STORAGEINFO
Fields inherited from class org.rapidcontext.core.storage.StorableObject
dict, KEY_ACTIVATED_TIME, KEY_CLASSNAME, KEY_ID, KEY_TYPE, PREFIX_COMPUTED, PREFIX_HIDDEN
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
Destroys this object.final File
file()
Returns the ZIP file being read by this storage.final void
init()
Initializes this object.Loads an object from the specified location.protected Path
locatePath
(Path path) Searches for an existing path in the ZIP file.Searches for an object at the specified location and returns metadata about the object if found.void
Removes an object or an index at the specified location.void
Stores an object at the specified location.Methods inherited from class org.rapidcontext.core.storage.Storage
compareTo, isReadWrite, load, localPath, mountOverlayPath, mountOverlayPrio, mountTime, objectName, objectPath, path, query, serialize, serializedPath, setMountInfo, unserialize
Methods inherited from class org.rapidcontext.core.storage.StorableObject
activate, activatedTime, id, isActive, isModified, passivate, serialize, sterilize, toString, type
-
Field Details
-
KEY_FILE
The dictionary key for the ZIP file location. The value stored is a file object.- See Also:
-
zip
The ZIP file used for locating resources. -
paths
The ZIP storage paths (identity) map. This is used to normalize paths for case-insensitive matching. HashMap objects don't allow fast access to hash keys or entries (only values), so a separate map is required. -
entries
The ZIP entries and index map. Indexed by the storage path and linked to either the Index or the ZipEntry objects.
-
-
Constructor Details
-
ZipStorage
Creates a new read-only ZIP file storage.- Parameters:
zipFile
- the ZIP file to use- Throws:
IOException
- if the ZIP couldn't be opened properly
-
-
Method Details
-
init
public final void init()Initializes this object. This method locates all the ZIP file entries and creates all the index objects.- Overrides:
init
in classStorableObject
-
destroy
Destroys this object. This method is used to free any resources used when this object is no longer used.- Overrides:
destroy
in classStorableObject
- Throws:
StorageException
- if the destruction failed
-
file
Returns the ZIP file being read by this storage.- Returns:
- the ZIP file being read
-
lookup
Searches for an object at the specified location and returns metadata about the object if found. The path may locate either an index or a specific object. -
load
Loads an object from the specified location. The path may locate either an index or a specific object. In case of an index, the data returned is an index dictionary listing of all objects in it. -
store
Stores an object at the specified location. The path must locate a particular object or file, since direct manipulation of indices is not supported. Any previous data at the specified path will be overwritten or removed. Note that only dictionaries and files can be stored in a file storage.- Specified by:
store
in classStorage
- Parameters:
path
- the storage locationdata
- the data to store- Throws:
StorageException
- if the data couldn't be written
-
remove
Removes an object or an index at the specified location. If the path refers to an index, all contained objects and indices will be removed recursively.- Specified by:
remove
in classStorage
- Parameters:
path
- the storage location- Throws:
StorageException
- if the data couldn't be removed
-
locatePath
Searches for an existing path in the ZIP file. If no exact match is found, the storage data file extensions are tried for a match.- Parameters:
path
- the storage location- Returns:
- an existing path in the ZIP file, or null if no match was found
-