Package org.apache.commons.io.build

# Class AbstractStreamBuilder<T,B extends AbstractStreamBuilder<T,B>>

java.lang.Object
org.apache.commons.io.build.AbstractSupplier<T,B>
org.apache.commons.io.build.AbstractOriginSupplier<T,B>
org.apache.commons.io.build.AbstractStreamBuilder<T,B>

Type Parameters:
  `T` - the type of instances to build.
  `B` - the type of builder subclass.

All Implemented Interfaces:
  `IOSupplier<T>`

Direct Known Subclasses:
  `AutoCloseInputStream.Builder`, `BOMInputStream.Builder`, `BoundedInputStream.Builder`, `BufferedFileChannelInputStream.Builder`, `CharSequenceInputStream.Builder`, `ChecksumInputStream.Builder`, `ChunkedOutputStream.Builder`, `DeferredFileOutputStream.Builder`, `FileWriterWithEncoding.Builder`, `LockableFileWriter.Builder`, `MemoryMappedFileInputStream.Builder`, `MessageDigestCalculatingInputStream.Builder`, `MessageDigestInputStream.Builder`, `QueueInputStream.Builder`, `RandomAccessFileInputStream.Builder`, `ReadAheadInputStream.Builder`, `ReaderInputStream.Builder`, `ReversedLinesFileReader.Builder`, `Tailer.Builder`, `ThrottledInputStream.Builder`, `UncheckedBufferedReader.Builder`, `UncheckedFilterInputStream.Builder`, `UncheckedFilterOutputStream.Builder`, `UncheckedFilterReader.Builder`, `UncheckedFilterWriter.Builder`, `UnsynchronizedBufferedInputStream.Builder`, `UnsynchronizedByteArrayInputStream.Builder`, `UnsynchronizedByteArrayOutputStream.Builder`, `UnsynchronizedFilterInputStream.Builder`, `WriterOutputStream.Builder`, `XmlStreamReader.Builder`, `XmlStreamWriter.Builder`

public abstract class AbstractStreamBuilder<T,B extends AbstractStreamBuilder<T,B>> extends AbstractOriginSupplier<T,B>
Abstracts building a typed instance of `T`.

Since:
  2.12.0

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AbstractStreamBuilder()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected int`
  `getBufferSize()`
  Gets the buffer size, defaults to `IOUtils.DEFAULT_BUFFER_SIZE` (8192).
  `protected int`
  `getBufferSizeDefault()`
  Gets the buffer size default, defaults to `IOUtils.DEFAULT_BUFFER_SIZE` (8192).
  `protected CharSequence`
  `getCharSequence()`
  Gets a CharSequence from the origin with a Charset.
  `Charset`
  `getCharset()`
  Gets the Charset, defaults to `Charset.defaultCharset()`.
  `protected Charset`
  `getCharsetDefault()`
  Gets the Charset default, defaults to `Charset.defaultCharset()`.
  `protected InputStream`
  `getInputStream()`
  Gets an InputStream from the origin with OpenOption[].
  `protected OpenOption[]`
  `getOpenOptions()`
  Gets the OpenOption array.
  `protected OutputStream`
  `getOutputStream()`
  Gets an OutputStream from the origin with OpenOption[].
  `protected Path`
  `getPath()`
  Gets a Path from the origin.
  `protected Reader`
  `getReader()`
  Gets a Reader from the origin with a Charset.
  `protected Writer`
  `getWriter()`
  Gets a Writer from the origin with an OpenOption[].
  `B`
  `setBufferSize(int bufferSize)`
  Sets the buffer size.
  `B`
  `setBufferSize(Integer bufferSize)`
  Sets the buffer size.
  `B`
  `setBufferSizeChecker(IntUnaryOperator bufferSizeChecker)`
  Sets the buffer size checker function.
  `protected B`
  `setBufferSizeDefault(int bufferSizeDefault)`
  Sets the buffer size for subclasses to initialize.
  `B`
  `setBufferSizeMax(int bufferSizeMax)`
  The maximum buffer size checked by the buffer size checker.
  `B`
  `setCharset(String charset)`
  Sets the Charset.
  `B`
  `setCharset(Charset charset)`
  Sets the Charset.
  `protected B`
  `setCharsetDefault(Charset defaultCharset)`
  Sets the Charset default for subclasses to initialize.
  `B`
  `setOpenOptions(OpenOption... openOptions)`
  Sets the OpenOption[].

  ### 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, get`

- ## Constructor Details

  - ### AbstractStreamBuilder

    public AbstractStreamBuilder()

- ## Method Details

  - ### getBufferSize

    protected int getBufferSize()
    Gets the buffer size, defaults to `IOUtils.DEFAULT_BUFFER_SIZE` (8192).
    Returns:
      the buffer size, defaults to `IOUtils.DEFAULT_BUFFER_SIZE` (8192).

  - ### getBufferSizeDefault

    protected int getBufferSizeDefault()
    Gets the buffer size default, defaults to `IOUtils.DEFAULT_BUFFER_SIZE` (8192).
    Returns:
      the buffer size default, defaults to `IOUtils.DEFAULT_BUFFER_SIZE` (8192).

  - ### getCharSequence

    protected CharSequence getCharSequence() throws IOException
    Gets a CharSequence from the origin with a Charset.
    Returns:
      An input stream
    Throws:
      `IllegalStateException` - if the `origin` is `null`.
      `UnsupportedOperationException` - if the origin cannot be converted to a CharSequence.
      `IOException` - if an I/O error occurs.
    Since:
      2.13.0
    See Also:
      - `AbstractOrigin.getCharSequence(Charset)`

  - ### getCharset

    public Charset getCharset()
    Gets the Charset, defaults to `Charset.defaultCharset()`.
    Returns:
      the Charset, defaults to `Charset.defaultCharset()`.

  - ### getCharsetDefault

    protected Charset getCharsetDefault()
    Gets the Charset default, defaults to `Charset.defaultCharset()`.
    Returns:
      the Charset default, defaults to `Charset.defaultCharset()`.

  - ### getInputStream

    protected InputStream getInputStream() throws IOException
    Gets an InputStream from the origin with OpenOption[].
    Returns:
      An input stream
    Throws:
      `IllegalStateException` - if the `origin` is `null`.
      `UnsupportedOperationException` - if the origin cannot be converted to an `InputStream`.
      `IOException` - if an I/O error occurs.
    Since:
      2.13.0
    See Also:
      - `AbstractOrigin.getInputStream(OpenOption...)`
      - `getOpenOptions()`

  - ### getOpenOptions

    protected OpenOption[] getOpenOptions()
    Gets the OpenOption array.
    Returns:
      the OpenOption array.

  - ### getOutputStream

    protected OutputStream getOutputStream() throws IOException
    Gets an OutputStream from the origin with OpenOption[].
    Returns:
      An OutputStream
    Throws:
      `IllegalStateException` - if the `origin` is `null`.
      `UnsupportedOperationException` - if the origin cannot be converted to an `OutputStream`.
      `IOException` - if an I/O error occurs.
    Since:
      2.13.0
    See Also:
      - `AbstractOrigin.getOutputStream(OpenOption...)`
      - `getOpenOptions()`

  - ### getPath

    protected Path getPath()
    Gets a Path from the origin.
    Returns:
      A Path
    Throws:
      `IllegalStateException` - if the `origin` is `null`.
      `UnsupportedOperationException` - if the origin cannot be converted to a `Path`.
    Since:
      2.13.0
    See Also:
      - `AbstractOrigin.getPath()`

  - ### getReader

    protected Reader getReader() throws IOException
    Gets a Reader from the origin with a Charset.
    Returns:
      A Reader
    Throws:
      `IllegalStateException` - if the `origin` is `null`.
      `UnsupportedOperationException` - if the origin cannot be converted to a `Reader`.
      `IOException` - if an I/O error occurs.
    Since:
      2.16.0
    See Also:
      - `AbstractOrigin.getReader(Charset)`
      - `getCharset()`

  - ### getWriter

    protected Writer getWriter() throws IOException
    Gets a Writer from the origin with an OpenOption[].
    Returns:
      An writer.
    Throws:
      `IllegalStateException` - if the `origin` is `null`.
      `UnsupportedOperationException` - if the origin cannot be converted to a `Writer`.
      `IOException` - if an I/O error occurs.
    Since:
      2.13.0
    See Also:
      - `AbstractOrigin.getOutputStream(OpenOption...)`
      - `getOpenOptions()`

  - ### setBufferSize

    public B setBufferSize(int bufferSize)
    Sets the buffer size. Invalid input (bufferSize <= 0) resets the value to its default.

    Subclasses may ignore this setting.

    Parameters:
      `bufferSize` - the buffer size.
    Returns:
      this.

  - ### setBufferSize

    public B setBufferSize(Integer bufferSize)
    Sets the buffer size.

    Subclasses may ignore this setting.

    Parameters:
      `bufferSize` - the buffer size, null resets to the default.
    Returns:
      this.

  - ### setBufferSizeChecker

    public B setBufferSizeChecker(IntUnaryOperator bufferSizeChecker)
    Sets the buffer size checker function. Throws a `IllegalArgumentException` by default.
    Parameters:
      `bufferSizeChecker` - the buffer size checker function. null resets to the default behavior.
    Returns:
      this
    Since:
      2.14.0

  - ### setBufferSizeDefault

    protected B setBufferSizeDefault(int bufferSizeDefault)
    Sets the buffer size for subclasses to initialize.

    Subclasses may ignore this setting.

    Parameters:
      `bufferSizeDefault` - the buffer size, null resets to the default.
    Returns:
      this.

  - ### setBufferSizeMax

    public B setBufferSizeMax(int bufferSizeMax)
    The maximum buffer size checked by the buffer size checker. Values less or equal to 0, resets to the int max value. By default, if this value is exceeded, this methods throws an `IllegalArgumentException`.
    Parameters:
      `bufferSizeMax` - maximum buffer size checked by the buffer size checker.
    Returns:
      this.
    Since:
      2.14.0

  - ### setCharset

    public B setCharset(Charset charset)
    Sets the Charset.

    Subclasses may ignore this setting.

    Parameters:
      `charset` - the Charset, null resets to the default.
    Returns:
      this.

  - ### setCharset

    public B setCharset(String charset)
    Sets the Charset.

    Subclasses may ignore this setting.

    Parameters:
      `charset` - the Charset name, null resets to the default.
    Returns:
      this.

  - ### setCharsetDefault

    protected B setCharsetDefault(Charset defaultCharset)
    Sets the Charset default for subclasses to initialize.

    Subclasses may ignore this setting.

    Parameters:
      `defaultCharset` - the Charset name, null resets to the default.
    Returns:
      this.

  - ### setOpenOptions

    public B setOpenOptions(OpenOption... openOptions)
    Sets the OpenOption[].

    Normally used with InputStream, OutputStream, and Writer.

    Subclasses may ignore this setting.

    Parameters:
      `openOptions` - the OpenOption[] name, null resets to the default.
    Returns:
      this.
    Since:
      2.13.0
    See Also:
      - `AbstractOriginSupplier.setInputStream(InputStream)`
      - `AbstractOriginSupplier.setOutputStream(OutputStream)`
      - `AbstractOriginSupplier.setWriter(Writer)`