Class IOUtil


  • public class IOUtil
    extends Object
    Utility for various I/O operations used within library internals
    • Constructor Detail

      • IOUtil

        public IOUtil()
    • Method Detail

      • readAllBytes

        @NotNull
        public static @org.jetbrains.annotations.NotNull byte[] readAllBytes​(@NotNull
                                                                             @NotNull InputStream stream)
                                                                      throws IOException
        Reads all bytes from an InputStream
        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 an InputStream to a JSONObject
        Parameters:
        input - The InputStream
        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