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.AbstractRandomAccessFileOrigin
,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
Modifier and TypeClassDescriptionstatic class
AbstractOrigin.AbstractRandomAccessFileOrigin<T extends RandomAccessFile,
B extends AbstractOrigin.AbstractRandomAccessFileOrigin<T, B>> ARandomAccessFile
origin.static class
Abyte[]
origin.static class
ACharSequence
origin.static class
AFile
origin.static class
AnInputStream
origin.static class
AIORandomAccessFile
origin.static class
AnOutputStream
origin.static class
APath
origin.static class
ARandomAccessFile
origin.static class
AReader
origin.static class
AURI
origin.static class
AWriter
origin. -
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractOrigin
(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 a portion of 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.getRandomAccessFile
(OpenOption... openOption) Gets this origin as a RandomAccessFile, 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.long
size()
Gets the size of the origin, if possible.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
-
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 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 theposition
overflows 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.
-
getRandomAccessFile
Gets this origin as a RandomAccessFile, if possible.- Parameters:
openOption
- options likeStandardOpenOption
.- Returns:
- this origin as a RandomAccessFile, if possible.
- Throws:
FileNotFoundException
- SeeRandomAccessFile(File, String)
.UnsupportedOperationException
- if this method is not implemented in a concrete subclass.- Since:
- 2.18.0
-
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
-