Class SourceDocument
This class owns the only byte/character boundary in the engine. Locators work purely
in char offsets against text(); render(String) turns spliced text back
into bytes with the original BOM restored.
Decoding is strict on purpose. The default new String(bytes, UTF_8) silently replaces
malformed sequences with U+FFFD, which would mean writing back a file whose untouched bytes had
changed — a direct violation of the exact-preservation guarantee (SRS section 10.4) and a
plausible way to corrupt a config file the plugin was only supposed to read.
-
Method Summary
Modifier and TypeMethodDescriptionbom()static SourceDocumentof(byte[] bytes) Detects the encoding, admits only UTF-8, and decodes strictly.byte[]The original file bytes exactly as read, including any BOM.byte[]Re-encodesnewTextto bytes, restoring the original BOM.booleanTrue when decoding and re-encoding the document is byte-exact.text()The decoded document text, excluding any BOM.
-
Method Details
-
of
Detects the encoding, admits only UTF-8, and decodes strictly.- Throws:
SpliceException-ErrorCode.UNSUPPORTED_ENCODINGfor a non-UTF-8 BOM or malformed UTF-8
-
text
The decoded document text, excluding any BOM. -
bom
-
originalBytes
public byte[] originalBytes()The original file bytes exactly as read, including any BOM. -
render
Re-encodesnewTextto bytes, restoring the original BOM.Rendering the unmodified
text()must reproduceoriginalBytes()exactly;rendersIdentically()asserts that round-trip and is exercised by every fixture. -
rendersIdentically
public boolean rendersIdentically()True when decoding and re-encoding the document is byte-exact.Strict decoding should make this unconditionally true for every document we accept; it is asserted rather than assumed because it underpins the exact-preservation oracle.
-