T
- the type of instances to build.B
- the type of builder subclass.public abstract class AbstractOrigin<T,B extends AbstractOrigin<T,B>> extends AbstractSupplier<T,B>
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()
.
Modifier and Type | Class and Description |
---|---|
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.OutputStreamOrigin
An
OutputStream origin. |
static class |
AbstractOrigin.PathOrigin
A
Path origin. |
static class |
AbstractOrigin.ReaderOrigin
An
Reader origin. |
static class |
AbstractOrigin.URIOrigin
A
URI origin. |
static class |
AbstractOrigin.WriterOrigin
An
Writer origin. |
Modifier and Type | Field and Description |
---|---|
(package private) T |
origin
The non-null origin.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractOrigin(T origin)
Constructs a new instance for a subclass.
|
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 this origin as a byte array, if possible.
|
java.lang.CharSequence |
getCharSequence(java.nio.charset.Charset charset)
Gets this origin as a byte array, if possible.
|
java.io.File |
getFile()
Gets this origin as a Path, if possible.
|
java.io.InputStream |
getInputStream(java.nio.file.OpenOption... options)
Gets this origin as an InputStream, if possible.
|
java.io.OutputStream |
getOutputStream(java.nio.file.OpenOption... options)
Gets this origin as an OutputStream, if possible.
|
java.nio.file.Path |
getPath()
Gets this origin as a Path, if possible.
|
java.io.Reader |
getReader(java.nio.charset.Charset charset)
Gets a new Reader on the origin, buffered by default.
|
java.io.Writer |
getWriter(java.nio.charset.Charset charset,
java.nio.file.OpenOption... options)
Gets a new Writer on the origin, buffered by default.
|
long |
size()
Gets the size of the origin, if possible.
|
java.lang.String |
toString() |
asThis
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
asSupplier
final T origin
protected AbstractOrigin(T origin)
origin
- The origin.public T get()
public byte[] getByteArray() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.java.lang.UnsupportedOperationException
- if the origin cannot be converted to a Path.public byte[] getByteArray(long position, int length) throws java.io.IOException
position
- the initial index of the range to be copied, inclusive.length
- How many bytes to copy.java.lang.UnsupportedOperationException
- if the origin cannot be converted to a Path.java.lang.ArithmeticException
- if the position
overflows an intjava.io.IOException
- if an I/O error occurs.public java.lang.CharSequence getCharSequence(java.nio.charset.Charset charset) throws java.io.IOException
charset
- The charset to use if conversion from bytes is needed.java.io.IOException
- if an I/O error occurs.java.lang.UnsupportedOperationException
- if the origin cannot be converted to a Path.public java.io.File getFile()
java.lang.UnsupportedOperationException
- if this method is not implemented in a concrete subclass.public java.io.InputStream getInputStream(java.nio.file.OpenOption... options) throws java.io.IOException
options
- options specifying how the file is openedjava.io.IOException
- if an I/O error occurs.java.lang.UnsupportedOperationException
- if the origin cannot be converted to a Path.public java.io.OutputStream getOutputStream(java.nio.file.OpenOption... options) throws java.io.IOException
options
- options specifying how the file is openedjava.io.IOException
- if an I/O error occurs.java.lang.UnsupportedOperationException
- if the origin cannot be converted to a Path.public java.nio.file.Path getPath()
java.lang.UnsupportedOperationException
- if this method is not implemented in a concrete subclass.public java.io.Reader getReader(java.nio.charset.Charset charset) throws java.io.IOException
charset
- the charset to use for decodingjava.io.IOException
- if an I/O error occurs opening the file.public java.io.Writer getWriter(java.nio.charset.Charset charset, java.nio.file.OpenOption... options) throws java.io.IOException
charset
- the charset to use for encodingoptions
- options specifying how the file is openedjava.io.IOException
- if an I/O error occurs opening or creating the file.java.lang.UnsupportedOperationException
- if the origin cannot be converted to a Path.public long size() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.public java.lang.String toString()
toString
in class java.lang.Object