Class HTMLEncoder


  • class HTMLEncoder
    extends Encoder

    HTMLEncoder -- an encoder for HTML contexts. Currently most HTML-based contexts are properly handled by XMLEncoder. The remaining HTML-specific context of "unquoted attributes" could not be added to the XMLEncoder without slowing it down. This class implements that remaining context: unquoted attribute values.

    Note: because this context is likely small strings, and hopefully rarely used, no effort was put into optimizing this encoder.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static char[] AMP
      Encoding for '&'.
      private static int ENCODE_AFFIX_CHAR_COUNT
      Number of characters in the encoding prefix and suffix when using decimal numeric encodings of the form "&#...;".
      private static char[] GT
      Encoding for '>'.
      private static char[] LT
      Encoding for '<'.
      private static char[] TAB
      Encoding for '\t'.
    • Constructor Summary

      Constructors 
      Constructor Description
      HTMLEncoder()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static int append​(char[] src, char[] out, int j)
      Appends a source array verbatim to the output array.
      (package private) static int encode​(int codePoint, char[] out, int j)
      Appends the numerically encoded version of codePoint to the output buffer.
      (package private) java.nio.charset.CoderResult encodeArrays​(java.nio.CharBuffer input, java.nio.CharBuffer output, boolean endOfInput)
      The core encoding loop used when both the input and output buffers are array backed.
      (package private) int firstEncodedOffset​(java.lang.String input, int off, int len)
      Scans the input string for the first character index that requires encoding.
      (package private) int maxEncodedLength​(int n)
      Returns the maximum encoded length (in chars) of an input sequence of n characters.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ENCODE_AFFIX_CHAR_COUNT

        private static final int ENCODE_AFFIX_CHAR_COUNT
        Number of characters in the encoding prefix and suffix when using decimal numeric encodings of the form "&#...;".
        See Also:
        Constant Field Values
      • TAB

        private static final char[] TAB
        Encoding for '\t'.
      • AMP

        private static final char[] AMP
        Encoding for '&'.
      • LT

        private static final char[] LT
        Encoding for '<'.
      • GT

        private static final char[] GT
        Encoding for '>'.
    • Constructor Detail

      • HTMLEncoder

        HTMLEncoder()
    • Method Detail

      • maxEncodedLength

        int maxEncodedLength​(int n)
        Description copied from class: Encoder
        Returns the maximum encoded length (in chars) of an input sequence of n characters.
        Specified by:
        maxEncodedLength in class Encoder
        Parameters:
        n - the number of characters of input
        Returns:
        the worst-case number of characters required to encode
      • firstEncodedOffset

        int firstEncodedOffset​(java.lang.String input,
                               int off,
                               int len)
        Description copied from class: Encoder
        Scans the input string for the first character index that requires encoding. If the entire input does not require encoding then the length is returned. This method is used by the Encode.forXYZ methods to return input strings unchanged when possible.
        Specified by:
        firstEncodedOffset in class Encoder
        Parameters:
        input - the input to check for encoding
        off - the offset of the first character to check
        len - the number of characters to check
        Returns:
        the index of the first character to encode. The return value will be off+len if no characters in the input require encoding.
      • append

        static int append​(char[] src,
                          char[] out,
                          int j)
        Appends a source array verbatim to the output array. Caller must insure there is enough space in the array for the output.
        Parameters:
        src - the characters to copy
        out - the output buffer
        j - the offset where to write in the output buffer
        Returns:
        j + src.length
      • encode

        static int encode​(int codePoint,
                          char[] out,
                          int j)
        Appends the numerically encoded version of codePoint to the output buffer. Caller must insure there is enough space for the output.
        Parameters:
        codePoint - the character to encode
        out - the output buffer
        j - the offset where to write in the output buffer
        Returns:
        j + the encoded length.
      • encodeArrays

        java.nio.charset.CoderResult encodeArrays​(java.nio.CharBuffer input,
                                                  java.nio.CharBuffer output,
                                                  boolean endOfInput)
        Description copied from class: Encoder
        The core encoding loop used when both the input and output buffers are array backed. The loop is expected to fetch the arrays and interact with the arrays directly for performance.
        Overrides:
        encodeArrays in class Encoder
        Parameters:
        input - the input buffer.
        output - the output buffer.
        endOfInput - when true, this is the last input to encode
        Returns:
        UNDERFLOW or OVERFLOW