Class FilesystemBlobStore

java.lang.Object
org.mockserver.state.FilesystemBlobStore
All Implemented Interfaces:
AutoCloseable, BlobStore

public class FilesystemBlobStore extends Object implements BlobStore
Filesystem-backed BlobStore implementation. Blob keys are interpreted as file paths: absolute keys are used as-is; relative keys are resolved against a configurable base directory.

The write path uses the same FileOutputStream + FileChannel + FileLock pattern as the pre-existing ExpectationFileSystemPersistence, so on-disk behaviour is byte-for-byte identical to today's persistence.

Metadata is stored alongside the data file as <key>.meta using Java Properties format. When no metadata is provided, no .meta file is written.

Thread-safety: a per-key ReentrantLock serialises concurrent writes to the same key, matching the single-lock design of the original persistence classes.

  • Constructor Details

    • FilesystemBlobStore

      public FilesystemBlobStore(Path baseDir, MockServerLogger mockServerLogger)
      Creates a filesystem blob store with the given base directory. The directory is created if it does not exist.
      Parameters:
      baseDir - the base directory for relative keys
      mockServerLogger - logger for error reporting (may be null in tests)
    • FilesystemBlobStore

      public FilesystemBlobStore(MockServerLogger mockServerLogger)
      Creates a filesystem blob store using the current working directory as the base directory.
      Parameters:
      mockServerLogger - logger for error reporting (may be null in tests)
  • Method Details

    • put

      public void put(String key, byte[] data, Map<String,String> metadata)
      Description copied from interface: BlobStore
      Stores a blob, overwriting any existing blob with the same key.
      Specified by:
      put in interface BlobStore
      Parameters:
      key - the blob key (e.g. a path-like string)
      data - the binary data
      metadata - optional metadata (may be empty, must not be null)
    • get

      public Optional<Blob> get(String key)
      Description copied from interface: BlobStore
      Retrieves a blob by key.
      Specified by:
      get in interface BlobStore
      Parameters:
      key - the blob key
      Returns:
      the blob, or empty if not present
    • list

      public List<String> list(String prefix)
      Description copied from interface: BlobStore
      Lists all blob keys that start with the given prefix.
      Specified by:
      list in interface BlobStore
      Parameters:
      prefix - the key prefix (e.g. "expectations/")
      Returns:
      list of matching keys
    • delete

      public boolean delete(String key)
      Description copied from interface: BlobStore
      Deletes a blob by key.
      Specified by:
      delete in interface BlobStore
      Parameters:
      key - the blob key
      Returns:
      true if the key was present