Class EncodingSupport
Version 1.0 reads and writes UTF-8 only, with or without a BOM. Everything else is detected and rejected before parsing, so an unsupported file is never partially understood and never written back. This is a safety property, not a convenience one: silently transcoding a file, or decoding it with the wrong charset and re-encoding it, would corrupt bytes the user never asked us to touch.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic Charsetcharset()Convenience for tests and callers that already hold text: the UTF-8 charset used throughout.static EncodingSupport.BomdetectBom(byte[] bytes) Detects a byte order mark.static voidRejects any BOM other than none or UTF-8.static voidValidates theencodingpseudo-attribute of an XML declaration, when present.
-
Method Details
-
detectBom
Detects a byte order mark.UTF-32 signatures are tested before UTF-16 because the UTF-32LE mark begins with the UTF-16LE mark; testing in the other order would misclassify a UTF-32LE file as UTF-16LE.
-
requireSupportedBom
Rejects any BOM other than none or UTF-8.- Throws:
SpliceException- withErrorCode.UNSUPPORTED_ENCODING
-
requireSupportedXmlDeclaration
Validates theencodingpseudo-attribute of an XML declaration, when present.Accepted: no declaration, a declaration without
encoding, orencodingnaming UTF-8 in any ASCII letter case with either quote style. Everything else — includingus-ascii, which would round-trip harmlessly today but silently break the first time a non-ASCII replacement is written — is rejected per SRS section 10.3.A UTF-16/UTF-32 declaration paired with a UTF-8 BOM is covered by the same rejection, so the "BOM/declaration conflict" requirement needs no separate check while only UTF-8 is supported.
- Throws:
SpliceException
-
charset
Convenience for tests and callers that already hold text: the UTF-8 charset used throughout.
-