Class XmlStreamReader.Builder
- All Implemented Interfaces:
- IOSupplier<XmlStreamReader>
- Enclosing class:
- XmlStreamReader
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:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionget()Builds a newXmlStreamWriter.setCharset(String charset) Sets the Charset.setCharset(Charset charset) Sets the Charset.setHttpContentType(String httpContentType) Sets the HTTP content type.setLenient(boolean lenient) Sets the lenient toggle.Methods inherited from class org.apache.commons.io.build.AbstractStreamBuildergetBufferSize, getBufferSizeDefault, getCharSequence, getCharset, getCharsetDefault, getFile, getInputStream, getOpenOptions, getOutputStream, getPath, getRandomAccessFile, getReader, getWriter, setBufferSize, setBufferSize, setBufferSizeChecker, setBufferSizeDefault, setBufferSizeMax, setCharsetDefault, setOpenOptionsMethods inherited from class org.apache.commons.io.build.AbstractOriginSuppliercheckOrigin, getOrigin, hasOrigin, newByteArrayOrigin, newCharSequenceOrigin, newFileOrigin, newFileOrigin, newInputStreamOrigin, newOutputStreamOrigin, newPathOrigin, newPathOrigin, newRandomAccessFileOrigin, newRandomAccessFileOrigin, newReaderOrigin, newURIOrigin, newWriterOrigin, setByteArray, setCharSequence, setFile, setFile, setInputStream, setOrigin, setOutputStream, setPath, setPath, setRandomAccessFile, setRandomAccessFile, setReader, setURI, setWriterMethods inherited from class org.apache.commons.io.build.AbstractSupplierasThisMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.commons.io.function.IOSupplierasSupplier, getUnchecked
- 
Constructor Details- 
Builderpublic Builder()Constructs a new builder ofXmlStreamReader.
 
- 
- 
Method Details- 
getBuilds a newXmlStreamWriter.You must set an aspect that supports AbstractStreamBuilder.getInputStream(), otherwise, this method throws an exception.This builder uses the following aspects: - AbstractStreamBuilder.getInputStream()
- AbstractStreamBuilder.getCharset()
- lenient
- httpContentType
 - Returns:
- a new instance.
- Throws:
- IllegalStateException- if the- originis- null.
- UnsupportedOperationException- if the origin cannot be converted to an- InputStream.
- IOException- if an I/O error occurs converting to an- InputStreamusing- AbstractStreamBuilder.getInputStream().
- XmlStreamReaderException- thrown if the Charset encoding could not be determined according to the specification.
- See Also:
 
- 
setCharsetDescription copied from class:AbstractStreamBuilderSets the Charset.Subclasses may ignore this setting. - Overrides:
- setCharsetin class- AbstractStreamBuilder<XmlStreamReader,- XmlStreamReader.Builder> 
- Parameters:
- charset- the Charset, null resets to the default.
- Returns:
- thisinstance.
 
- 
setCharsetDescription copied from class:AbstractStreamBuilderSets the Charset.Subclasses may ignore this setting. - Overrides:
- setCharsetin class- AbstractStreamBuilder<XmlStreamReader,- XmlStreamReader.Builder> 
- Parameters:
- charset- the Charset name, null resets to the default.
- Returns:
- thisinstance.
 
- 
setHttpContentTypeSets the HTTP content type.- Parameters:
- httpContentType- the HTTP content type.
- Returns:
- thisinstance.
 
- 
setLenientSets the lenient toggle.- Parameters:
- lenient- the lenient toggle.
- Returns:
- thisinstance.
 
 
-