public static class XmlStreamReader.Builder extends org.apache.commons.io.build.AbstractStreamBuilder<XmlStreamReader,XmlStreamReader.Builder>
XmlStreamWriter
instance.
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();
Constructor and Description |
---|
Builder() |
Modifier and Type | Method and Description |
---|---|
XmlStreamReader |
get()
Constructs a new instance.
|
XmlStreamReader.Builder |
setCharset(java.nio.charset.Charset charset) |
XmlStreamReader.Builder |
setCharset(java.lang.String charset) |
XmlStreamReader.Builder |
setHttpContentType(java.lang.String httpContentType) |
XmlStreamReader.Builder |
setLenient(boolean lenient) |
getCharset, setBufferSize, setBufferSize, setOpenOptions
setByteArray, setCharSequence, setFile, setFile, setInputStream, setOutputStream, setPath, setPath, setReader, setURI, setWriter
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
asSupplier
public XmlStreamReader get() throws java.io.IOException
This builder use the aspect InputStream, OpenOption[], httpContentType, lenient, and defaultEncoding.
You must provide an origin that can be converted to an InputStream by this builder, otherwise, this call will throw an
UnsupportedOperationException
.
java.lang.UnsupportedOperationException
- if the origin cannot provide an InputStream.java.io.IOException
- thrown if there is a problem reading the stream.XmlStreamReaderException
- thrown if the charset encoding could not be determined according to the specification.AbstractStreamBuilder.getInputStream()
public XmlStreamReader.Builder setCharset(java.nio.charset.Charset charset)
setCharset
in class org.apache.commons.io.build.AbstractStreamBuilder<XmlStreamReader,XmlStreamReader.Builder>
public XmlStreamReader.Builder setCharset(java.lang.String charset)
setCharset
in class org.apache.commons.io.build.AbstractStreamBuilder<XmlStreamReader,XmlStreamReader.Builder>
public XmlStreamReader.Builder setHttpContentType(java.lang.String httpContentType)
public XmlStreamReader.Builder setLenient(boolean lenient)
Copyright © 2010 - 2023 Adobe. All Rights Reserved