public static class XmlStreamReader.Builder extends AbstractStreamBuilder<XmlStreamReader,XmlStreamReader.Builder>
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();
get()| Constructor and Description |
|---|
Builder()
Constructs a new builder of
XmlStreamReader. |
| Modifier and Type | Method and Description |
|---|---|
XmlStreamReader |
get()
Builds a new
XmlStreamWriter. |
XmlStreamReader.Builder |
setCharset(java.nio.charset.Charset charset)
Sets the Charset.
|
XmlStreamReader.Builder |
setCharset(java.lang.String charset)
Sets the Charset.
|
XmlStreamReader.Builder |
setHttpContentType(java.lang.String httpContentType)
Sets the HTTP content type.
|
XmlStreamReader.Builder |
setLenient(boolean lenient)
Sets the lenient toggle.
|
getBufferSize, getBufferSizeDefault, getCharSequence, getCharset, getCharsetDefault, getFile, getInputStream, getOpenOptions, getOutputStream, getPath, getRandomAccessFile, getReader, getWriter, setBufferSize, setBufferSize, setBufferSizeChecker, setBufferSizeMax, setOpenOptionssetByteArray, setCharSequence, setFile, setFile, setInputStream, setOutputStream, setPath, setPath, setRandomAccessFile, setRandomAccessFile, setReader, setURI, setWriterequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitasSupplier, getUncheckedpublic Builder()
XmlStreamReader.public XmlStreamReader get() throws java.io.IOException
XmlStreamWriter.
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()java.lang.IllegalStateException - if the origin is null.java.lang.UnsupportedOperationException - if the origin cannot be converted to an InputStream.java.io.IOException - if an I/O error occurs converting to an InputStream using AbstractStreamBuilder.getInputStream().XmlStreamReaderException - thrown if the Charset encoding could not be determined according to the specification.AbstractStreamBuilder.getInputStream(),
IOSupplier.getUnchecked()public XmlStreamReader.Builder setCharset(java.nio.charset.Charset charset)
AbstractStreamBuilderSubclasses may ignore this setting.
setCharset in class AbstractStreamBuilder<XmlStreamReader,XmlStreamReader.Builder>charset - the Charset, null resets to the default.this instance.public XmlStreamReader.Builder setCharset(java.lang.String charset)
AbstractStreamBuilderSubclasses may ignore this setting.
setCharset in class AbstractStreamBuilder<XmlStreamReader,XmlStreamReader.Builder>charset - the Charset name, null resets to the default.this instance.public XmlStreamReader.Builder setHttpContentType(java.lang.String httpContentType)
httpContentType - the HTTP content type.this instance.public XmlStreamReader.Builder setLenient(boolean lenient)
lenient - the lenient toggle.this instance.Copyright © 2010 - 2025 Adobe. All Rights Reserved