Class NetworkBodyStore
java.lang.Object
com.shaft.capture.storage.NetworkBodyStore
Persists request/response bodies as external files with SHA-256 integrity and optional truncation.
Mirrors ExternalTestDataWriter's atomic temp-file+move pattern.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReads back a body previously stored bystore(byte[], String, Path), verifying it still matches its recorded SHA-256 digest.byte[]Reads back a body's raw bytes previously stored bystore(byte[], String, Path), verifying it still matches its recorded SHA-256 digest.Stores a body as an external file and returns a BodyRef with integrity metadata.Stores a body as an external file with a configurable size cap and returns a BodyRef.
-
Constructor Details
-
NetworkBodyStore
public NetworkBodyStore()
-
-
Method Details
-
store
Stores a body as an external file and returns a BodyRef with integrity metadata. The stored file name is derived from the SHA-256 of the original full body.- Parameters:
body- raw body bytes (may be null or empty)contentType- optional media/content-type of the body, recorded as the BodyRef encodingsessionDir- directory where the body file will be stored (session-relative)- Returns:
- BodyRef with a ref to the stored file, sha256/size of original body, its encoding, and truncation flag, or null if body is null/empty
- Throws:
CaptureFormatException- if write fails
-
store
Stores a body as an external file with a configurable size cap and returns a BodyRef.- Parameters:
body- raw body bytes (may be null or empty)contentType- optional media/content-type of the body, recorded as the BodyRef encodingsessionDir- directory where the body file will be stored (session-relative)maxBodyBytes- maximum bytes to store (original body size is always recorded)- Returns:
- BodyRef with a ref to the stored file, sha256/size of original full body, its encoding, and truncation flag, or null if body is null/empty
- Throws:
CaptureFormatException- if write fails
-
read
Reads back a body previously stored bystore(byte[], String, Path), verifying it still matches its recorded SHA-256 digest. Returns an empty string for anullref, a ref whose file is missing, or a ref whose file no longer matches its digest (evidence tampering/corruption) -- callers that need bodies purely for codegen classification/rendering treat "unavailable" the same as "no body" rather than failing generation outright.- Parameters:
bodyRef- reference returned by a priorstore(byte[], String, Path)call, ornullsessionDir- directory the body was stored in (must match thestorecall)- Returns:
- the stored body decoded as UTF-8 text, or
""if unavailable
-
readBytes
Reads back a body's raw bytes previously stored bystore(byte[], String, Path), verifying it still matches its recorded SHA-256 digest. Unlikeread(BodyRef, Path), this does not assume UTF-8 text, so callers that must tell binary content apart from text (for example HAR body emission, which base64-encodes non-textual bodies) can make that call themselves from the storedBodyRef.encoding()content type instead of losing information to a lossy UTF-8 decode.- Parameters:
bodyRef- reference returned by a priorstore(byte[], String, Path)call, ornullsessionDir- directory the body was stored in (must match thestorecall)- Returns:
- the stored body's raw bytes, or an empty array if unavailable
-