@FunctionalInterface
public interface Writable
OutputStream, this
class is util for representing assets that
can be exported anytime, without necessarily
loading them| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_BUFFER_LENGTH
Determines the default buffer size used when
copying data from an input stream to an output
stream
|
static Writable |
EMPTY |
| Modifier and Type | Method and Description |
|---|---|
static @NotNull Writable |
bytes(byte[] bytes)
Creates a new
Writable instance representing
the given byte array, which is written using the
OutputStream.write(byte[])} method |
static @NotNull Writable |
copyInputStream(@NotNull java.io.InputStream inputStream)
Creates a new
Writable instance that represents
the given InputStream data, in order to preserve
the data, it reads the input stream to a byte array when
this method is called |
static @NotNull Writable |
file(@NotNull java.io.File file)
Creates a new
Writable instance that represents
the given File, which will be copied to the
given OutputStream when calling write(java.io.OutputStream) |
static @NotNull Writable |
inputStream(@NotNull java.util.concurrent.Callable<java.io.InputStream> inputStreamSupplier)
Creates a new
Writable instance that represents
the given InputStream supplier, the supplied
input stream will be opened, read and copied every
time it is required |
static @NotNull Writable |
path(@NotNull java.nio.file.Path path,
java.nio.file.OpenOption... options)
Creates a new
Writable instance that represents
the given Path, which will be copied to the given
OutputStream when calling write(java.io.OutputStream) |
static @NotNull Writable |
resource(@NotNull java.lang.ClassLoader loader,
@NotNull java.lang.String name)
Creates a new
Writable instance that represents
the named resource at the specified class loader |
static @NotNull Writable |
resource(@NotNull java.lang.String name)
Deprecated.
Use
resource(ClassLoader, String) instead |
static @NotNull Writable |
stringUtf8(@NotNull java.lang.String string)
Creates a new
Writable instance representing
the given string, which is written using the UTF-8
StandardCharsets.UTF_8 encoding |
default byte[] |
toByteArray()
Converts this
Writable instance to a byte
array, it is not recommended invoking this method
so often |
default @NotNull java.lang.String |
toUTF8String()
Converts this
Writable instance to an UTF-8
string, it is not recommended invoking this method so
often, it exists only for easing debugging |
void |
write(@NotNull java.io.OutputStream output)
Writes this object information to a
OutputStream, this method can be
called anytime, it should be consistent
with its data and generate the exact same
output for the same input (attributes) of
the implementation |
static final Writable EMPTY
static final int DEFAULT_BUFFER_LENGTH
void write(@NotNull
@NotNull java.io.OutputStream output)
throws java.io.IOException
OutputStream, this method can be
called anytime, it should be consistent
with its data and generate the exact same
output for the same input (attributes) of
the implementationoutput - The target output streamjava.io.IOException - If write failsdefault byte[] toByteArray()
throws java.io.IOException
Writable instance to a byte
array, it is not recommended invoking this method
so oftenjava.io.IOException - If conversion fails@NotNull
default @NotNull java.lang.String toUTF8String()
throws java.io.IOException
Writable instance to an UTF-8
string, it is not recommended invoking this method so
often, it exists only for easing debuggingjava.io.IOException - If conversion fails@NotNull static @NotNull Writable resource(@NotNull @NotNull java.lang.ClassLoader loader, @NotNull @NotNull java.lang.String name)
Writable instance that represents
the named resource at the specified class loaderloader - The class loader that holds the resourcename - The full resource nameWritable representation@Deprecated @ApiStatus.ScheduledForRemoval(inVersion="2.0.0") @NotNull static @NotNull Writable resource(@NotNull @NotNull java.lang.String name)
resource(ClassLoader, String) insteadWritable instance that represents
the named resource at the caller class loader.name - The full resource nameWritable representation@NotNull static @NotNull Writable file(@NotNull @NotNull java.io.File file)
Writable instance that represents
the given File, which will be copied to the
given OutputStream when calling write(java.io.OutputStream)file - The wrapped file, must existWritable representation for this file@NotNull static @NotNull Writable path(@NotNull @NotNull java.nio.file.Path path, @NotNull java.nio.file.OpenOption... options)
Writable instance that represents
the given Path, which will be copied to the given
OutputStream when calling write(java.io.OutputStream)path - The file pathoptions - The options (Files.newInputStream(java.nio.file.Path, java.nio.file.OpenOption...))Writable representation for this path@NotNull static @NotNull Writable inputStream(@NotNull @NotNull java.util.concurrent.Callable<java.io.InputStream> inputStreamSupplier)
Writable instance that represents
the given InputStream supplier, the supplied
input stream will be opened, read and copied every
time it is requiredinputStreamSupplier - The input stream supplierWritable representation@NotNull static @NotNull Writable copyInputStream(@NotNull @NotNull java.io.InputStream inputStream) throws java.io.IOException
Writable instance that represents
the given InputStream data, in order to preserve
the data, it reads the input stream to a byte array when
this method is calledinputStream - The input stream to copyWritable representationjava.io.IOException - If reading the input stream fails@NotNull static @NotNull Writable bytes(byte[] bytes)
Writable instance representing
the given byte array, which is written using the
OutputStream.write(byte[])} methodbytes - The wrapped bytesWritable representation@NotNull static @NotNull Writable stringUtf8(@NotNull @NotNull java.lang.String string)
Writable instance representing
the given string, which is written using the UTF-8
StandardCharsets.UTF_8 encodingstring - The wrapped stringWritable representation