Package 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.ByteArrayOrigin,AbstractOrigin.CharSequenceOrigin,AbstractOrigin.FileOrigin,AbstractOrigin.InputStreamOrigin,AbstractOrigin.OutputStreamOrigin,AbstractOrigin.PathOrigin,AbstractOrigin.ReaderOrigin,AbstractOrigin.URIOrigin,AbstractOrigin.WriterOrigin
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().
- Since:
- 2.12.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAbyte[]origin.static classACharSequenceorigin.static classAFileorigin.static classAnInputStreamorigin.static classAnOutputStreamorigin.static classAPathorigin.static classAnReaderorigin.static classAURIorigin.static classAnWriterorigin. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractOrigin(T origin) Constructs a new instance for a subclass. -
Method Summary
Modifier and TypeMethodDescriptionget()Gets the origin.byte[]Gets this origin as a byte array, if possible.byte[]getByteArray(long position, int length) Gets this origin as a byte array, if possible.getCharSequence(Charset charset) Gets this origin as a byte array, if possible.getFile()Gets this origin as a Path, if possible.getInputStream(OpenOption... options) Gets this origin as an InputStream, if possible.getOutputStream(OpenOption... options) Gets this origin as an OutputStream, if possible.getPath()Gets this origin as a Path, if possible.Gets a new Reader on the origin, buffered by default.getWriter(Charset charset, OpenOption... options) Gets a new Writer on the origin, buffered by default.longsize()Gets the size of the origin, if possible.toString()Methods inherited from class org.apache.commons.io.build.AbstractSupplier
asThisMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.commons.io.function.IOSupplier
asSupplier
-
Constructor Details
-
AbstractOrigin
Constructs a new instance for a subclass.- Parameters:
origin- The origin.
-
-
Method Details
-
get
Gets the origin.- Returns:
- the origin.
-
getByteArray
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
Gets 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 thepositionoverflows an intIOException- if an I/O error occurs.- Since:
- 2.13.0
-
getCharSequence
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
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
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
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
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.
-
getReader
Gets a new Reader on the origin, buffered by default.- Parameters:
charset- the charset to use for decoding- Returns:
- a new Reader on the origin.
- Throws:
IOException- if an I/O error occurs opening the file.
-
getWriter
Gets a new Writer on the origin, buffered by default.- Parameters:
charset- the charset to use for encodingoptions- 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
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.- Since:
- 2.13.0
-
toString
-