Package net.dv8tion.jda.internal.utils
Class IOUtil
java.lang.Object
net.dv8tion.jda.internal.utils.IOUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
static BufferedRequestBody
createRequestBody
(okhttp3.MediaType contentType, InputStream stream) Creates a new request body that transmits the providedInputStream
.static InputStream
getBody
(okhttp3.Response response) Retrieves anInputStream
for the providedResponse
.static String
static int
getIntBigEndian
(byte[] arr, int offset) static short
getShortBigEndian
(byte[] arr, int offset) static short
getShortLittleEndian
(byte[] arr, int offset) static okhttp3.OkHttpClient.Builder
static byte[]
Used as an alternate to Java's nio Files.readAllBytes.static byte[]
readFully
(InputStream stream) Provided as a simple way to fully read an InputStream into a byte[].static ByteBuffer
reallocate
(ByteBuffer original, int length) static void
setIntBigEndian
(byte[] arr, int offset, int it) static void
setServerName
(WebSocketFactory factory, String url) static void
silentClose
(Closeable closeable) static void
silentClose
(AutoCloseable closeable)
-
Constructor Details
-
IOUtil
public IOUtil()
-
-
Method Details
-
silentClose
-
silentClose
-
addQuery
-
getHost
-
setServerName
-
newHttpClientBuilder
public static okhttp3.OkHttpClient.Builder newHttpClientBuilder() -
readFully
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 ofreadFully(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
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 providedInputStream
.- Parameters:
contentType
- TheMediaType
of the datastream
- TheInputStream
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
-
getBody
Retrieves anInputStream
for the providedResponse
.
When the header forcontent-encoding
is set withgzip
this will wrap the body in aGZIPInputStream
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
-