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 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.
|
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.
|
public XMLBytesDecoder(byte[] inb) throws java.io.IOException
java.io.IOException
public XMLBytesDecoder(byte[] inb, java.lang.String dfltenc) throws java.io.IOException
java.io.IOException
public static void main(java.lang.String[] args) throws java.io.IOException
java.io.IOException
public java.lang.String getXMLString()
public java.lang.String explicitXMLEncoding()
null
.public static java.lang.String explicitEncoding(java.lang.String xml)
null
.