org.apache.commons.io.build

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

- java.lang.Object
- - org.apache.commons.io.build.AbstractSupplier<T,B>
  - - org.apache.commons.io.build.AbstractOrigin<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:
    AbstractOrigin.AbstractRandomAccessFileOrigin, AbstractOrigin.ByteArrayOrigin, AbstractOrigin.CharSequenceOrigin, AbstractOrigin.FileOrigin, AbstractOrigin.InputStreamOrigin, AbstractOrigin.OutputStreamOrigin, AbstractOrigin.PathOrigin, AbstractOrigin.ReaderOrigin, AbstractOrigin.URIOrigin, AbstractOrigin.WriterOrigin

      public abstract class AbstractOrigin<T,B extends AbstractOrigin<T,B>>
      extends AbstractSupplier<T,B>

  Abstracts the origin of data for builders like a `File`, `Path`, `Reader`, `Writer`, `InputStream`, `OutputStream`, and `URI`.

  Some methods may throw `UnsupportedOperationException` if that method is not implemented in a concrete subclass, see `getFile()` and `getPath()`.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `AbstractOrigin.AbstractRandomAccessFileOrigin<T extends RandomAccessFile,B extends AbstractOrigin.AbstractRandomAccessFileOrigin<T,B>>` A `RandomAccessFile` origin.
    `static class` | `AbstractOrigin.ByteArrayOrigin` A `byte[]` origin.
    `static class` | `AbstractOrigin.CharSequenceOrigin` A `CharSequence` origin.
    `static class` | `AbstractOrigin.FileOrigin` A `File` origin.
    `static class` | `AbstractOrigin.InputStreamOrigin` An `InputStream` origin.
    `static class` | `AbstractOrigin.IORandomAccessFileOrigin` A `IORandomAccessFile` origin.
    `static class` | `AbstractOrigin.OutputStreamOrigin` An `OutputStream` origin.
    `static class` | `AbstractOrigin.PathOrigin` A `Path` origin.
    `static class` | `AbstractOrigin.RandomAccessFileOrigin` A `RandomAccessFile` origin.
    `static class` | `AbstractOrigin.ReaderOrigin` A `Reader` origin.
    `static class` | `AbstractOrigin.URIOrigin` A `URI` origin.
    `static class` | `AbstractOrigin.WriterOrigin` A `Writer` origin.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `(package private) T` | `origin` The non-null origin.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractOrigin(T origin)` Constructs a new instance for subclasses.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `T` | `get()` Gets the origin.
    `byte[]` | `getByteArray()` Gets this origin as a byte array, if possible.
    `byte[]` | `getByteArray(long position, int length)` Gets a portion of this origin as a byte array, if possible.
    `CharSequence` | `getCharSequence(Charset charset)` Gets this origin as a byte array, if possible.
    `File` | `getFile()` Gets this origin as a Path, if possible.
    `InputStream` | `getInputStream(OpenOption... options)` Gets this origin as an InputStream, if possible.
    `OutputStream` | `getOutputStream(OpenOption... options)` Gets this origin as an OutputStream, if possible.
    `Path` | `getPath()` Gets this origin as a Path, if possible.
    `RandomAccessFile` | `getRandomAccessFile(OpenOption... openOption)` Gets this origin as a RandomAccessFile, if possible.
    `Reader` | `getReader(Charset charset)` Gets a new Reader on the origin, buffered by default.
    `Writer` | `getWriter(Charset charset, OpenOption... options)` Gets a new Writer on the origin, buffered by default.
    `long` | `size()` Gets the size of the origin, if possible.
    `String` | `toString()`

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

    - ### Methods inherited from interface org.apache.commons.io.function.IOSupplier

      `asSupplier, getUnchecked`

- - ### Field Detail

    - #### origin

          final T origin

      The non-null origin.

  - ### Constructor Detail

    - #### AbstractOrigin

          protected AbstractOrigin(T origin)

      Constructs a new instance for subclasses.
      Parameters:
        `origin` - The origin, not null.

  - ### Method Detail

    - #### get

          public T get()

      Gets the origin.
      Returns:
        the origin.
      See Also:
        `IOSupplier.getUnchecked()`

    - #### getByteArray

          public byte[] getByteArray()
                              throws IOException

      Gets this origin as a byte array, if possible.
      Returns:
        this origin as a byte array, if possible.
      Throws:
        `IOException` - if an I/O error occurs.
        `UnsupportedOperationException` - if the origin cannot be converted to a Path.

    - #### getByteArray

          public byte[] getByteArray(long position,
                                     int length)
                              throws IOException

      Gets a portion of this origin as a byte array, if possible.
      Parameters:
        `position` - the initial index of the range to be copied, inclusive.
        `length` - How many bytes to copy.
      Returns:
        this origin as a byte array, if possible.
      Throws:
        `UnsupportedOperationException` - if the origin cannot be converted to a Path.
        `ArithmeticException` - if the `position` overflows an int
        `IOException` - if an I/O error occurs.

    - #### getCharSequence

          public CharSequence getCharSequence(Charset charset)
                                       throws IOException

      Gets this origin as a byte array, if possible.
      Parameters:
        `charset` - The charset to use if conversion from bytes is needed.
      Returns:
        this origin as a byte array, if possible.
      Throws:
        `IOException` - if an I/O error occurs.
        `UnsupportedOperationException` - if the origin cannot be converted to a Path.

    - #### getFile

          public File getFile()

      Gets this origin as a Path, if possible.
      Returns:
        this origin as a Path, if possible.
      Throws:
        `UnsupportedOperationException` - if this method is not implemented in a concrete subclass.

    - #### getInputStream

          public InputStream getInputStream(OpenOption... options)
                                     throws IOException

      Gets this origin as an InputStream, if possible.
      Parameters:
        `options` - options specifying how the file is opened
      Returns:
        this origin as an InputStream, if possible.
      Throws:
        `IOException` - if an I/O error occurs.
        `UnsupportedOperationException` - if the origin cannot be converted to a Path.

    - #### getOutputStream

          public OutputStream getOutputStream(OpenOption... options)
                                       throws IOException

      Gets this origin as an OutputStream, if possible.
      Parameters:
        `options` - options specifying how the file is opened
      Returns:
        this origin as an OutputStream, if possible.
      Throws:
        `IOException` - if an I/O error occurs.
        `UnsupportedOperationException` - if the origin cannot be converted to a Path.

    - #### getPath

          public Path getPath()

      Gets this origin as a Path, if possible.
      Returns:
        this origin as a Path, if possible.
      Throws:
        `UnsupportedOperationException` - if this method is not implemented in a concrete subclass.

    - #### getRandomAccessFile

          public RandomAccessFile getRandomAccessFile(OpenOption... openOption)
                                               throws FileNotFoundException

      Gets this origin as a RandomAccessFile, if possible.
      Parameters:
        `openOption` - options like `StandardOpenOption`.
      Returns:
        this origin as a RandomAccessFile, if possible.
      Throws:
        `FileNotFoundException` - See `RandomAccessFile(File, String)`.
        `UnsupportedOperationException` - if this method is not implemented in a concrete subclass.

    - #### getReader

          public Reader getReader(Charset charset)
                           throws IOException

      Gets a new Reader on the origin, buffered by default.
      Parameters:
        `charset` - the charset to use for decoding, null maps to the default Charset.
      Returns:
        a new Reader on the origin.
      Throws:
        `IOException` - if an I/O error occurs opening the file.

    - #### getWriter

          public Writer getWriter(Charset charset,
                                  OpenOption... options)
                           throws IOException

      Gets a new Writer on the origin, buffered by default.
      Parameters:
        `charset` - the charset to use for encoding
        `options` - options specifying how the file is opened
      Returns:
        a new Writer on the origin.
      Throws:
        `IOException` - if an I/O error occurs opening or creating the file.
        `UnsupportedOperationException` - if the origin cannot be converted to a Path.

    - #### size

          public long size()
                    throws IOException

      Gets the size of the origin, if possible.
      Returns:
        the size of the origin in bytes or characters.
      Throws:
        `IOException` - if an I/O error occurs.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`