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 classIOUtil.LazyLazy evaluation for logging complex objectsstatic classIOUtil.OctetBodyWrapper for anOCTETrequest bodystatic interfaceIOUtil.SilentSupplier<T>Supplier that can throw checked-exceptions
-
Field Summary
Fields Modifier and Type Field Description static byte[]EMPTY_BYTESEmpty byte-array, used forreadAllBytes(java.io.InputStream)static MediaTypeJSONapplication/jsonstatic MediaTypeOCTETapplication/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 InputStreamgetBody(Response req)Helper method which handles gzip encoded response bodiesstatic @org.jetbrains.annotations.NotNull byte[]readAllBytes(@NotNull InputStream stream)Reads all bytes from anInputStreamstatic @NotNull org.json.JSONObjecttoJSON(@NotNull InputStream input)Converts anInputStreamto 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 IOExceptionReads 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-Responseinstance- Returns:
InputStreamrepresenting 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 anInputStreamto aJSONObject- Parameters:
input- TheInputStream- Returns:
JSONObjectfor 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
-
-