Package org.apache.commons.io.build
Class AbstractOrigin.ByteArrayOrigin
- java.lang.Object
-
- org.apache.commons.io.build.AbstractSupplier<T,B>
-
- org.apache.commons.io.build.AbstractOrigin<byte[],AbstractOrigin.ByteArrayOrigin>
-
- org.apache.commons.io.build.AbstractOrigin.ByteArrayOrigin
-
- All Implemented Interfaces:
IOSupplier<byte[]>
- Enclosing class:
- AbstractOrigin<T,B extends AbstractOrigin<T,B>>
public static class AbstractOrigin.ByteArrayOrigin extends AbstractOrigin<byte[],AbstractOrigin.ByteArrayOrigin>
Abyte[]origin.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.commons.io.build.AbstractOrigin
AbstractOrigin.AbstractRandomAccessFileOrigin<T extends java.io.RandomAccessFile,B extends AbstractOrigin.AbstractRandomAccessFileOrigin<T,B>>, AbstractOrigin.ByteArrayOrigin, AbstractOrigin.ChannelOrigin, AbstractOrigin.CharSequenceOrigin, AbstractOrigin.FileOrigin, AbstractOrigin.InputStreamOrigin, AbstractOrigin.IORandomAccessFileOrigin, AbstractOrigin.OutputStreamOrigin, AbstractOrigin.PathOrigin, AbstractOrigin.RandomAccessFileOrigin, AbstractOrigin.ReaderOrigin, AbstractOrigin.URIOrigin, AbstractOrigin.WriterOrigin
-
-
Constructor Summary
Constructors Constructor Description ByteArrayOrigin(byte[] origin)Constructs a new instance for the given origin.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]getByteArray()Gets this origin as a byte array, if possible.protected java.nio.channels.ChannelgetChannel(java.nio.file.OpenOption... options)Gets this origin as a Channel, if possible.java.io.InputStreamgetInputStream(java.nio.file.OpenOption... options)Gets this origin as an InputStream, if possible.java.io.ReadergetReader(java.nio.charset.Charset charset)Gets a new Reader on the origin, buffered by default.longsize()Gets the size of the origin, if possible.-
Methods inherited from class org.apache.commons.io.build.AbstractOrigin
get, getByteArray, getChannel, getCharSequence, getFile, getOutputStream, getPath, getRandomAccessFile, getWriter, 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 Detail
-
ByteArrayOrigin
public ByteArrayOrigin(byte[] origin)
Constructs a new instance for the given origin.- Parameters:
origin- The origin, not null.- Throws:
java.lang.NullPointerException- iforiginisnull.
-
-
Method Detail
-
getByteArray
public byte[] getByteArray()
Gets this origin as a byte array, if possible.No conversion should occur when calling this method.
- Overrides:
getByteArrayin classAbstractOrigin<byte[],AbstractOrigin.ByteArrayOrigin>- Returns:
- this origin as a byte array, if possible.
-
getChannel
protected java.nio.channels.Channel getChannel(java.nio.file.OpenOption... options) throws java.io.IOException
Description copied from class:AbstractOriginGets this origin as a Channel, if possible.- Overrides:
getChannelin classAbstractOrigin<byte[],AbstractOrigin.ByteArrayOrigin>- Parameters:
options- Options specifying how a file-based origin is opened, ignored otherwise.- Returns:
- A new Channel on the origin.
- Throws:
java.io.IOException- If an I/O error occurs.- See Also:
AbstractOrigin.getChannel(Class, OpenOption...)
-
getInputStream
public java.io.InputStream getInputStream(java.nio.file.OpenOption... options) throws java.io.IOException
Gets this origin as an InputStream, if possible.The
optionsparameter is ignored since abyte[]does not need anOpenOptionto be read.- Overrides:
getInputStreamin classAbstractOrigin<byte[],AbstractOrigin.ByteArrayOrigin>- Parameters:
options- options specifying how the file is opened- Returns:
- this origin as an InputStream, if possible.
- Throws:
java.io.IOException- if an I/O error occurs.
-
getReader
public java.io.Reader getReader(java.nio.charset.Charset charset) throws java.io.IOException
Description copied from class:AbstractOriginGets a new Reader on the origin, buffered by default.- Overrides:
getReaderin classAbstractOrigin<byte[],AbstractOrigin.ByteArrayOrigin>- Parameters:
charset- the charset to use for decoding, null maps to the default Charset.- Returns:
- a new Reader on the origin.
- Throws:
java.io.IOException- if an I/O error occurs opening the file.
-
size
public long size() throws java.io.IOException
Description copied from class:AbstractOriginGets the size of the origin, if possible.- Overrides:
sizein classAbstractOrigin<byte[],AbstractOrigin.ByteArrayOrigin>- Returns:
- the size of the origin in bytes or characters.
- Throws:
java.io.IOException- if an I/O error occurs.
-
-