Class BlobKeys
BlobStore
implementations that apply a blobStoreKeyPrefix (S3, GCS, Azure);
forPersistedFile(BlobStore, java.nio.file.Path) additionally governs
the key for EVERY store other than FilesystemBlobStore.
Object stores are NOT filesystems: their keys are opaque strings in which
/ is only a display convention. Two shapes that a filesystem
tolerates cause trouble as object names, and only one of them is fatal:
- a DOUBLED
//— FATAL. Produced whenever a prefix that already ends in/is concatenated with a key that begins with one. MinIO rejects it outright with HTTP 400 "Object name contains unsupported characters", so the write never lands; - a LEADING
/— accepted, but undesirable. It is a legal byte in an S3 object name andgetround-trips the very same key, so writes and reads DO work; the cost is that/a/bis a distinct name froma/band most path-like tools cannot browse to it. When the leading/came from an absolute local path, as the persisted document's key once did, the object was also named after the writing container's filesystem layout, so an instance that resolved that path differently looked under a different name and silently found nothing.
blobStoreKeyPrefix is empty, ends in /, ends
without one, or (mistakenly) starts with one.-
Method Summary
Modifier and TypeMethodDescriptionstatic StringforPersistedFile(BlobStore blobStore, Path filePath) Derives the object-store key under which a persisted document is stored.static StringJoins a configured key prefix and a blob key into an object-store key with EXACTLY one separator between them, no leading separator, and no repeated separators anywhere.static StringNormalizes a key: drops any leading separator and collapses runs of separators into one.static StringnormalizePrefix(String keyPrefix) Normalizes a prefix: asnormalize(String)but also drops any trailing separator, so callers can append exactly one themselves.static StringstripPrefix(String keyPrefix, String storeKey) Reversesjoin(String, String), recovering the NORMALISED blob key from an object-store key.
-
Method Details
-
join
Joins a configured key prefix and a blob key into an object-store key with EXACTLY one separator between them, no leading separator, and no repeated separators anywhere.Examples (prefix, key) → result:
("", "expectations.json") → "expectations.json" ("mockserver", "expectations.json") → "mockserver/expectations.json" ("mockserver/", "expectations.json") → "mockserver/expectations.json" ("/mockserver/", "/expectations.json") → "mockserver/expectations.json" ("mockserver/", "") → "mockserver/"The empty-key case keeps the trailing separator on purpose: the only caller that passes an empty key islist(""), which must scope the listing to the prefix rather than to every key that merely starts with the same characters.- Parameters:
keyPrefix- the configuredblobStoreKeyPrefix(may be null or empty)key- the blob key (may be null or empty)- Returns:
- a valid object-store key
-
stripPrefix
Reversesjoin(String, String), recovering the NORMALISED blob key from an object-store key. It is an inverse only modulo that normalisation:stripPrefix(p, join(p, "/x.json"))returnsx.json, not/x.json. Keys that do not carry the prefix are returned unchanged, matching the tolerant behaviour of the previousstartsWith-based implementations.- Parameters:
keyPrefix- the configuredblobStoreKeyPrefix(may be null or empty)storeKey- the object-store key as returned by the cloud SDK- Returns:
- the blob key without the prefix
-
forPersistedFile
Derives the object-store key under which a persisted document is stored.For the
FilesystemBlobStorethe key IS the file path, so the absolute path is kept — the store resolves it back to the very file the pre-blob-store direct-I/O implementation wrote.For every other store the key is the FILE NAME alone. Embedding the absolute local path in a cloud object name produced an invalid key (a leading
/, doubled up to//by any prefix ending in a separator, which MinIO rejects with HTTP 400) and tied the object name to the writing container's filesystem layout, so an instance started from a different directory silently restored nothing.- Parameters:
blobStore- the store the key is destined forfilePath- the configured local persistence path- Returns:
- the key to use with
blobStore
-
normalize
Normalizes a key: drops any leading separator and collapses runs of separators into one. A trailing separator is preserved because callers use it to scope alistto a logical folder.- Parameters:
key- the key to normalize (may be null)- Returns:
- the normalized key, never null
-
normalizePrefix
Normalizes a prefix: asnormalize(String)but also drops any trailing separator, so callers can append exactly one themselves.- Parameters:
keyPrefix- the prefix to normalize (may be null)- Returns:
- the normalized prefix, never null and never ending in a separator
-