Class EncodingInfo


  • public class EncodingInfo
    extends Object
    Xerces' getEncodingName() method of org.apache.xerces.impl.XMLEntityManager ) returns an array with name of encoding scheme and endianness. I decided to create a separate class incapsulating encoding metadata. The may idea behind this is the fact that we will most probably need to save this info somewhere and use it later when writing the response. Beside that, using class makes related code more clear.
    • Constructor Detail

      • EncodingInfo

        public EncodingInfo()
        Non-arg constructor to use in a few cases when you need a blank instance of EncodingInfo. It cant' be used right after creation and should be populated first via either setters or specific charset detection methods.
      • EncodingInfo

        public EncodingInfo​(String encoding,
                            Boolean isBigEndian)
        Constructor that takes name of the encoding scheme and endianness - results of autodetection in getEncodingName. BOM is considered missing if object is constructed this way.
        Parameters:
        encoding - Name of the autodetected encoding scheme.
        isBigEndian -

        Detected byte order of the data. true if order is big-endian, false if little-endian, and null if byte order is not relevant for this encoding scheme.

      • EncodingInfo

        public EncodingInfo​(String encoding,
                            Boolean isBigEndian,
                            boolean hasBOM)
        Constructor that takes name of the encoding scheme and endianness - results of autodetection in getEncodingName(). Also presence of Byte Order Mark should be specified explicitly.
        Parameters:
        encoding - Name of the autodetected encoding scheme.
        isBigEndian -

        Detected byte order of the data. true if order is big-endian, false if little-endian, and null if byte order is not relevant for this encoding scheme.

        hasBOM - true if BOM is present, false otherwise.
    • Method Detail

      • getEncoding

        public String getEncoding()
        Returns current encoding scheme (or charset).
      • setEncoding

        public void setEncoding​(String encoding)
        Sets new value of stored encoding (charset?) name.
      • isBigEndian

        public Boolean isBigEndian()
        Accessor for fIsBigEndian. Should we define a mutator too?
      • hasBOM

        public boolean hasBOM()
        Accessor for fHasBOM. Imho mutator is not required.
      • copyFrom

        public void copyFrom​(EncodingInfo encInfo)
        Copies property values from another EncodingInfo instance. Strange enough, but sometimes such behavior is preferred to simple assignment or cloning. More specifically, this method is currently used (at least it was :) in XmlCharsetDetector.getCharsetAwareReader (other two ways simply don't work).
        Parameters:
        encInfo - source object which properties should be mirrored in this instance
      • toString

        public String toString()
        Returns current state of this instance in human-readable form.
        Overrides:
        toString in class Object