xml

## Class XMLBytesDecoder

- java.lang.Object
- - xml.XMLBytesDecoder

-     public class XMLBytesDecoder
      extends java.lang.Object

  Supports the decoding of a given byte array, assumed to contain encoded XML, to give an XML String, taking account of some common UCS encodings. Specifically, attempts are made to recognize UTF-16, with or without a Byte-Order-Mark [BOM], UTF-8 with a BOM, and, failing any of these, taking account of an explicit encoding spec. in an XML declaration.

  Before 2007-02 this class was called `XMLBytesConverter`.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `XMLBytesDecoder(byte[] inb)` Constructs a decoder for the given byte array, using the standard XML default encoding (UTF-8).
    `XMLBytesDecoder(byte[] inb, java.lang.String dfltenc)` Constructs a decoder for the given byte array, using the given default encoding.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `explicitEncoding(java.lang.String xml)` If the given text starts with an XML declaration and that declaration explicitly specifies an encoding, then returns that encoding; otherwise returns `null`.
    `java.lang.String` | `explicitXMLEncoding()` If this decoder's text starts with an XML declaration and that declaration explicitly specifies an encoding, then returns that encoding; otherwise returns `null`.
    `java.lang.String` | `getXMLString()` Returns the decoded XML string.
    `static void` | `main(java.lang.String[] args)` Test method: attempts to convert the data in the file whose path is given by the sole argument, and lists the result on standard output.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### XMLBytesDecoder

          public XMLBytesDecoder(byte[] inb)
                          throws java.io.IOException

      Constructs a decoder for the given byte array, using the standard XML default encoding (UTF-8).
      Throws:
        `java.io.IOException`

    - #### XMLBytesDecoder

          public XMLBytesDecoder(byte[] inb,
                                 java.lang.String dfltenc)
                          throws java.io.IOException

      Constructs a decoder for the given byte array, using the given default encoding.
      Throws:
        `java.io.IOException`

  - ### Method Detail

    - #### main

          public static void main(java.lang.String[] args)
                           throws java.io.IOException

      Test method: attempts to convert the data in the file whose path is given by the sole argument, and lists the result on standard output.
      Throws:
        `java.io.IOException`

    - #### getXMLString

          public java.lang.String getXMLString()

      Returns the decoded XML string.

    - #### explicitXMLEncoding

          public java.lang.String explicitXMLEncoding()

      If this decoder's text starts with an XML declaration and that declaration explicitly specifies an encoding, then returns that encoding; otherwise returns `null`.

    - #### explicitEncoding

          public static java.lang.String explicitEncoding(java.lang.String xml)

      If the given text starts with an XML declaration and that declaration explicitly specifies an encoding, then returns that encoding; otherwise returns `null`.