Class EncodingSupport

java.lang.Object
io.jenkins.plugins.configsplice.engine.EncodingSupport

public final class EncodingSupport extends Object
Encoding detection and admission control (SRS section 10.3).

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.

  • Method Details

    • detectBom

      public static EncodingSupport.Bom detectBom(byte[] bytes)
      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

      public static void requireSupportedBom(EncodingSupport.Bom bom) throws SpliceException
      Rejects any BOM other than none or UTF-8.
      Throws:
      SpliceException - with ErrorCode.UNSUPPORTED_ENCODING
    • requireSupportedXmlDeclaration

      public static void requireSupportedXmlDeclaration(String text) throws SpliceException
      Validates the encoding pseudo-attribute of an XML declaration, when present.

      Accepted: no declaration, a declaration without encoding, or encoding naming UTF-8 in any ASCII letter case with either quote style. Everything else — including us-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

      public static Charset charset()
      Convenience for tests and callers that already hold text: the UTF-8 charset used throughout.