Class XmlStreamReader.Builder
- All Implemented Interfaces:
IOSupplier<XmlStreamReader>
- Enclosing class:
- XmlStreamReader
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();
- Since:
- 2.12.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionget()
Constructs a new instance.setCharset
(String charset) Sets the Charset.setCharset
(Charset charset) Sets the Charset.setHttpContentType
(String httpContentType) setLenient
(boolean lenient) Methods inherited from class org.apache.commons.io.build.AbstractStreamBuilder
getBufferSize, getBufferSizeDefault, getCharSequence, getCharset, getCharsetDefault, getInputStream, getOpenOptions, getOutputStream, getPath, getWriter, setBufferSize, setBufferSize, setBufferSizeChecker, setBufferSizeDefault, setBufferSizeMax, setCharsetDefault, setOpenOptions
Methods inherited from class org.apache.commons.io.build.AbstractOriginSupplier
checkOrigin, getOrigin, hasOrigin, newByteArrayOrigin, newCharSequenceOrigin, newFileOrigin, newFileOrigin, newInputStreamOrigin, newOutputStreamOrigin, newPathOrigin, newPathOrigin, newReaderOrigin, newURIOrigin, newWriterOrigin, setByteArray, setCharSequence, setFile, setFile, setInputStream, setOrigin, setOutputStream, setPath, setPath, setReader, setURI, setWriter
Methods inherited from class org.apache.commons.io.build.AbstractSupplier
asThis
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.commons.io.function.IOSupplier
asSupplier
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
get
Constructs a new instance.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
.- Returns:
- a new instance.
- Throws:
UnsupportedOperationException
- if the origin cannot provide an InputStream.IOException
- thrown if there is a problem reading the stream.XmlStreamReaderException
- thrown if the charset encoding could not be determined according to the specification.- See Also:
-
setCharset
Description copied from class:AbstractStreamBuilder
Sets the Charset.Subclasses may ignore this setting.
- Overrides:
setCharset
in classAbstractStreamBuilder<XmlStreamReader,
XmlStreamReader.Builder> - Parameters:
charset
- the Charset, null resets to the default.- Returns:
- this.
-
setCharset
Description copied from class:AbstractStreamBuilder
Sets the Charset.Subclasses may ignore this setting.
- Overrides:
setCharset
in classAbstractStreamBuilder<XmlStreamReader,
XmlStreamReader.Builder> - Parameters:
charset
- the Charset name, null resets to the default.- Returns:
- this.
-
setHttpContentType
-
setLenient
-