Package club.minnced.discord.webhook
Class IOUtil
- java.lang.Object
-
- club.minnced.discord.webhook.IOUtil
-
public class IOUtil extends Object
Utility for various I/O operations used within library internals
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IOUtil.Lazy
Lazy evaluation for logging complex objectsstatic class
IOUtil.OctetBody
Wrapper for anOCTET
request bodystatic interface
IOUtil.SilentSupplier<T>
Supplier that can throw checked-exceptions
-
Field Summary
Fields Modifier and Type Field Description static byte[]
EMPTY_BYTES
Empty byte-array, used forreadAllBytes(java.io.InputStream)
static MediaType
JSON
application/jsonstatic MediaType
OCTET
application/octet-stream
-
Constructor Summary
Constructors Constructor Description IOUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> @NotNull CompletableFuture<List<T>>
flipFuture(@NotNull List<CompletableFuture<T>> list)
Converts a list of futures in a future of a list.static @Nullable InputStream
getBody(Response req)
Helper method which handles gzip encoded response bodiesstatic @org.jetbrains.annotations.NotNull byte[]
readAllBytes(@NotNull InputStream stream)
Reads all bytes from anInputStream
static @NotNull org.json.JSONObject
toJSON(@NotNull InputStream input)
Converts anInputStream
to aJSONObject
-
-
-
Field Detail
-
JSON
public static final MediaType JSON
application/json
-
OCTET
public static final MediaType OCTET
application/octet-stream
-
EMPTY_BYTES
public static final byte[] EMPTY_BYTES
Empty byte-array, used forreadAllBytes(java.io.InputStream)
-
-
Method Detail
-
readAllBytes
@NotNull public static @org.jetbrains.annotations.NotNull byte[] readAllBytes(@NotNull @NotNull InputStream stream) throws IOException
Reads all bytes from anInputStream
- Parameters:
stream
- The InputStream- Returns:
byte[]
containing all bytes of the stream- Throws:
IOException
- If some I/O error occurs
-
getBody
@Nullable public static @Nullable InputStream getBody(@NotNull Response req) throws IOException
Helper method which handles gzip encoded response bodies- Parameters:
req
-Response
instance- Returns:
InputStream
representing the response body- Throws:
IOException
- If some I/O error occurs
-
toJSON
@NotNull public static @NotNull org.json.JSONObject toJSON(@NotNull @NotNull InputStream input)
Converts anInputStream
to aJSONObject
- Parameters:
input
- TheInputStream
- Returns:
JSONObject
for the provided input- Throws:
org.json.JSONException
- If parsing fails
-
flipFuture
@NotNull public static <T> @NotNull CompletableFuture<List<T>> flipFuture(@NotNull @NotNull List<CompletableFuture<T>> list)
Converts a list of futures in a future of a list.- Type Parameters:
T
- Component type of the list- Parameters:
list
- The list of futures to flatten- Returns:
- A future that will be completed with the resulting list
-
-