Class IOUtil

java.lang.Object
net.dv8tion.jda.internal.utils.IOUtil

public class IOUtil extends Object
  • Constructor Details

    • IOUtil

      public IOUtil()
  • Method Details

    • silentClose

      public static void silentClose(AutoCloseable closeable)
    • silentClose

      public static void silentClose(Closeable closeable)
    • addQuery

      public static String addQuery(String base, Object... params)
    • getHost

      public static String getHost(String uri)
    • setServerName

      public static void setServerName(WebSocketFactory factory, String url)
    • newHttpClientBuilder

      public static okhttp3.OkHttpClient.Builder newHttpClientBuilder()
    • readFully

      public static byte[] readFully(File file) throws IOException
      Used as an alternate to Java's nio Files.readAllBytes.

      This customized version for File is provide (instead of just using readFully(java.io.InputStream) with a FileInputStream) because with a File we can determine the total size of the array and do not need to have a buffer. This results in a memory footprint that is half the size of readFully(java.io.InputStream)

      Code provided from Stackoverflow

      Parameters:
      file - The file from which we should retrieve the bytes from
      Returns:
      A byte[] containing all of the file's data
      Throws:
      IOException - Thrown if there is a problem while reading the file.
    • readFully

      public static byte[] readFully(InputStream stream) throws IOException
      Provided as a simple way to fully read an InputStream into a byte[].

      This method will block until the InputStream has been fully read, so if you provide an InputStream that is non-finite, you're gonna have a bad time.

      Parameters:
      stream - The Stream to be read.
      Returns:
      A byte[] containing all of the data provided by the InputStream
      Throws:
      IOException - If the first byte cannot be read for any reason other than the end of the file, if the input stream has been closed, or if some other I/O error occurs.
    • createRequestBody

      public static BufferedRequestBody createRequestBody(okhttp3.MediaType contentType, InputStream stream)
      Creates a new request body that transmits the provided InputStream.
      Parameters:
      contentType - The MediaType of the data
      stream - The InputStream to be transmitted
      Returns:
      RequestBody capable of transmitting the provided InputStream of data
    • getShortBigEndian

      public static short getShortBigEndian(byte[] arr, int offset)
    • getShortLittleEndian

      public static short getShortLittleEndian(byte[] arr, int offset)
    • getIntBigEndian

      public static int getIntBigEndian(byte[] arr, int offset)
    • setIntBigEndian

      public static void setIntBigEndian(byte[] arr, int offset, int it)
    • reallocate

      public static ByteBuffer reallocate(ByteBuffer original, int length)
    • getBody

      public static InputStream getBody(okhttp3.Response response) throws IOException
      Retrieves an InputStream for the provided Response.
      When the header for content-encoding is set with gzip this will wrap the body in a GZIPInputStream which decodes the data.

      This is used to make usage of encoded responses more user-friendly in various parts of JDA.

      Parameters:
      response - The not-null Response object
      Returns:
      InputStream representing the body of this response
      Throws:
      IOException