Package org.apache.commons.io.input

# Class XmlStreamReader.Builder

java.lang.Object
org.apache.commons.io.build.AbstractSupplier<XmlStreamReader,XmlStreamReader.Builder>
org.apache.commons.io.build.AbstractOriginSupplier<XmlStreamReader,XmlStreamReader.Builder>
org.apache.commons.io.build.AbstractStreamBuilder<XmlStreamReader,XmlStreamReader.Builder>
org.apache.commons.io.input.XmlStreamReader.Builder

All Implemented Interfaces:
  `IOSupplier<XmlStreamReader>`

Enclosing class:
  `XmlStreamReader`

public static class XmlStreamReader.Builder extends AbstractStreamBuilder<XmlStreamReader,XmlStreamReader.Builder>
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:
  - `get()`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Builder()`
  Constructs a new builder of `XmlStreamReader`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `XmlStreamReader`
  `get()`
  Builds a new `XmlStreamWriter`.
  `XmlStreamReader.Builder`
  `setCharset(String charset)`
  Sets the Charset.
  `XmlStreamReader.Builder`
  `setCharset(Charset charset)`
  Sets the Charset.
  `XmlStreamReader.Builder`
  `setHttpContentType(String httpContentType)`
  Sets the HTTP content type.
  `XmlStreamReader.Builder`
  `setLenient(boolean lenient)`
  Sets the lenient toggle.

  ### Methods inherited from class org.apache.commons.io.build.AbstractStreamBuilder

  `getBufferSize, getBufferSizeDefault, getCharSequence, getCharset, getCharsetDefault, getFile, getInputStream, getOpenOptions, getOutputStream, getPath, getRandomAccessFile, getReader, 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, newRandomAccessFileOrigin, newRandomAccessFileOrigin, newReaderOrigin, newURIOrigin, newWriterOrigin, setByteArray, setCharSequence, setFile, setFile, setInputStream, setOrigin, setOutputStream, setPath, setPath, setRandomAccessFile, setRandomAccessFile, 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, getUnchecked`

- ## Constructor Details

  - ### Builder

    public Builder()
    Constructs a new builder of `XmlStreamReader`.

- ## Method Details

  - ### get

    public XmlStreamReader get() throws IOException
    Builds a new `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()`
    - lenient
    - httpContentType
    Returns:
      a new instance.
    Throws:
      `IllegalStateException` - if the `origin` is `null`.
      `UnsupportedOperationException` - if the origin cannot be converted to an `InputStream`.
      `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.
    See Also:
      - `AbstractStreamBuilder.getInputStream()`
      - `IOSupplier.getUnchecked()`

  - ### setCharset

    public XmlStreamReader.Builder setCharset(Charset charset)
    Description copied from class: `AbstractStreamBuilder`
    Sets the Charset.

    Subclasses may ignore this setting.

    Overrides:
      `setCharset` in class `AbstractStreamBuilder<XmlStreamReader,XmlStreamReader.Builder>`
    Parameters:
      `charset` - the Charset, null resets to the default.
    Returns:
      `this` instance.

  - ### setCharset

    public XmlStreamReader.Builder setCharset(String charset)
    Description copied from class: `AbstractStreamBuilder`
    Sets the Charset.

    Subclasses may ignore this setting.

    Overrides:
      `setCharset` in class `AbstractStreamBuilder<XmlStreamReader,XmlStreamReader.Builder>`
    Parameters:
      `charset` - the Charset name, null resets to the default.
    Returns:
      `this` instance.

  - ### setHttpContentType

    public XmlStreamReader.Builder setHttpContentType(String httpContentType)
    Sets the HTTP content type.
    Parameters:
      `httpContentType` - the HTTP content type.
    Returns:
      `this` instance.

  - ### setLenient

    public XmlStreamReader.Builder setLenient(boolean lenient)
    Sets the lenient toggle.
    Parameters:
      `lenient` - the lenient toggle.
    Returns:
      `this` instance.