Class XmlStreamReader.Builder

All Implemented Interfaces:
IOSupplier<XmlStreamReader>
Enclosing class:
XmlStreamReader

Builds a new XmlStreamWriter. Constructs a Reader using an InputStream and the associated content-type header. This constructor is lenient regarding the encoding detection.

First it checks if the stream has BOM. If there is not BOM checks the content-type encoding. If there is not content-type encoding checks the XML prolog encoding. If there is not XML prolog encoding uses the default encoding mandated by the content-type MIME type.

If lenient detection is indicated and the detection above fails as per specifications it then attempts the following:

If the content type was 'text/html' it replaces it with 'text/xml' and tries the detection again.

Else if the XML prolog had a charset encoding that encoding is used.

Else if the content type had a charset encoding that encoding is used.

Else 'UTF-8' is used.

If lenient detection is indicated an XmlStreamReaderException is never thrown.

For example:


 XmlStreamReader r = XmlStreamReader.builder()
   .setPath(path)
   .setCharset(StandardCharsets.UTF_8)
   .get();
 
 
Since:
2.12.0
See Also: