@FunctionalInterface
public interface Readable
InputStream such as resources, files,
bytes in memory, etc. without having them always
loaded| Modifier and Type | Method and Description |
|---|---|
default @NotNull Writable |
asWritable()
|
static @NotNull Readable |
bytes(byte[] bytes)
Creates a new
Readable instance representing
the given byte array, which is read via a ByteArrayInputStream
when required |
static @NotNull Readable |
copyInputStream(@NotNull java.io.InputStream inputStream)
Creates a new
Readable instance that will copy,
save and return the given InputStream data. |
static @NotNull Readable |
file(@NotNull java.io.File file)
|
@NotNull java.io.InputStream |
open()
Opens this readable object with a
InputStream,
this method can be called anytime, it should be consistent
with its data and return it exactly every time. |
static @NotNull Readable |
path(@NotNull java.nio.file.Path path,
java.nio.file.OpenOption... options)
|
default void |
readAndWrite(@NotNull java.io.OutputStream output)
Opens, reads and writes this
Readable information
and transfers/writes it to the given OutputStream |
default byte[] |
readAsByteArray()
Opens and reads this
Readable instance to
a byte array, it is recommended to cache the returned
result if you need to re-use it, since this method
reads the data every time it is called |
default @NotNull java.lang.String |
readAsUTF8String()
Opens and reads this
Readable instance to
an UTF-8 string, it is recommended to cache the returned
result if you need to re-use it, since this method
(may) read the data every time is called |
static @NotNull Readable |
resource(@NotNull java.lang.ClassLoader loader,
@NotNull java.lang.String name)
Creates a new
Readable instance that represents
the named resource at the specified class loader |
static @NotNull Readable |
resource(@NotNull java.lang.String name)
Deprecated.
Use
resource(ClassLoader, String) instead |
static @NotNull Readable |
stringUtf8(@NotNull java.lang.String string)
Creates a new
Readable instance representing
the given string, which is read via a ByteArrayInputStream
when needed |
@NotNull
@NotNull java.io.InputStream open()
throws java.io.IOException
InputStream,
this method can be called anytime, it should be consistent
with its data and return it exactly every time.
Implementations should be state-less and not necessarily thread-safe
java.io.IOException - If opening failsdefault void readAndWrite(@NotNull
@NotNull java.io.OutputStream output)
Readable information
and transfers/writes it to the given OutputStream
Note that this operation won't close the
given OutputStream
output - The output stream to transferdefault byte[] readAsByteArray()
Readable instance to
a byte array, it is recommended to cache the returned
result if you need to re-use it, since this method
reads the data every time it is called@NotNull
default @NotNull java.lang.String readAsUTF8String()
throws java.io.IOException
Readable instance to
an UTF-8 string, it is recommended to cache the returned
result if you need to re-use it, since this method
(may) read the data every time is calledjava.io.IOException - If conversion fails@NotNull default @NotNull Writable asWritable()
Writable instance that represents
this Readable data.
The returned writable instance will open the readable everytime it needs to write the data, and will then write it to the output stream.
@NotNull static @NotNull Readable resource(@NotNull @NotNull java.lang.ClassLoader loader, @NotNull @NotNull java.lang.String name)
Readable instance that represents
the named resource at the specified class loaderloader - The class loader that holds the resourcename - The full resource nameReadable representation@Deprecated @ApiStatus.ScheduledForRemoval(inVersion="2.0.0") @NotNull static @NotNull Readable resource(@NotNull @NotNull java.lang.String name)
resource(ClassLoader, String) insteadReadable instance that represents
the named resource at the caller class loader.name - The full resource nameReadable representation@NotNull static @NotNull Readable file(@NotNull @NotNull java.io.File file)
Readable instance that represents
the given File, which will be opened every time
open() is calledfile - The wrapped file, must existReadable representation for this file@NotNull static @NotNull Readable path(@NotNull @NotNull java.nio.file.Path path, @NotNull java.nio.file.OpenOption... options)
Readable instance that represents
the given Path, which will be opened every time
open() is calledpath - The file pathoptions - The options Files.newInputStream(java.nio.file.Path, java.nio.file.OpenOption...)Readable representation for this path@NotNull static @NotNull Readable copyInputStream(@NotNull @NotNull java.io.InputStream inputStream)
Readable instance that will copy,
save and return the given InputStream data. In
order to preserve the data, it reads the input stream as
a byte array when this method is called.inputStream - The input stream to copyReadable representation@NotNull static @NotNull Readable bytes(byte[] bytes)
Readable instance representing
the given byte array, which is read via a ByteArrayInputStream
when requiredbytes - The wrapped bytesReadable representation@NotNull static @NotNull Readable stringUtf8(@NotNull @NotNull java.lang.String string)
Readable instance representing
the given string, which is read via a ByteArrayInputStream
when neededstring - The wrapped stringrepresentation