Class DirStorage

All Implemented Interfaces:
Comparable<Storage>

public class DirStorage extends Storage
A persistent data storage and retrieval handler based on a file system directory. This class will read and write both Java property files and binary files depending on the object type provided. The property files are used for all dictionary data storage and retrieval.
Version:
1.0
  • Field Details

    • KEY_DIR

      public static final String KEY_DIR
      The dictionary key for the base directory. The value stored is a file object.
      See Also:
  • Constructor Details

    • DirStorage

      public DirStorage(File dir, boolean readWrite)
      Creates a new directory storage.
      Parameters:
      dir - the base data directory to use
      readWrite - the read write flag
  • Method Details

    • dir

      public File dir()
      Returns the base directory for the storage data files.
      Returns:
      the base directory for data files
    • lookup

      public Metadata lookup(Path path)
      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.
      Specified by:
      lookup in class Storage
      Parameters:
      path - the storage location
      Returns:
      the metadata for the object, or null if not found
    • load

      public Object load(Path path)
      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.
      Specified by:
      load in class Storage
      Parameters:
      path - the storage location
      Returns:
      the data read, or null if not found
    • store

      public void store(Path path, Object data) throws StorageException
      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 class Storage
      Parameters:
      path - the storage location
      data - the data to store
      Throws:
      StorageException - if the data couldn't be written
    • remove

      public void remove(Path path) throws StorageException
      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 class Storage
      Parameters:
      path - the storage location
      Throws:
      StorageException - if the data couldn't be removed