Class Encodability

java.lang.Object
dev.omnist.codec.Encodability

public final class Encodability extends Object
Rule C-9 of omnist-spec section 7.3: every writer fails with write.unsupported-value, and unconditionally, on a string value or an edge label that has no UTF-8 encoding. In Java that is a lone surrogate: a high surrogate not followed by a low one, or a low surrogate not preceded by a high one. A valid surrogate pair (an astral code point) and U+FFFD are ordinary text.

A writer must not emit such a string in any spelling, raw or as an escape, because a reader of the output (a UTF-8 sink) could not accept it. The check is a fast pass that builds no path (allEncodable(dev.omnist.document.Document)); only when it finds a failure does firstFailure(dev.omnist.document.Document) walk the document again, in document order, to build the Document path of the node holding the string, or, for a label, of the node holding the edge (a path cannot quote a label).

  • Method Details

    • isEncodable

      public static boolean isEncodable(String s)
      Whether s has a UTF-8 encoding, that is, holds no lone surrogate.
      Parameters:
      s - the string
      Returns:
      true if every surrogate is half of a valid pair
    • allEncodable

      public static boolean allEncodable(Document doc)
      The fast pass: whether every edge label and string value of doc has a UTF-8 encoding. Builds no path and recurses on no Java stack, so a very deep document is safe.
      Parameters:
      doc - the document
      Returns:
      true if nothing in it is unencodable
    • refusal

      public static WriteException refusal(Document doc)
      The C-9 refusal for a document that holds a string value or an edge label with no UTF-8 encoding: a WriteException whose report has one write.unsupported-value error at the Document path of the first offending node. Call it only for such a document.
      Parameters:
      doc - the document that was being written
      Returns:
      the exception to throw