Package com.aliucord
Class Http.Response
-
- All Implemented Interfaces:
-
java.io.Closeable
,java.lang.AutoCloseable
public class Http.Response implements Closeable
Response obtained by calling Request.execute()
-
-
Field Summary
Fields Modifier and Type Field Description public final int
statusCode
public final String
statusMessage
-
Constructor Summary
Constructors Constructor Description Http.Response(Http.Request req)
Construct a Response
-
Method Summary
Modifier and Type Method Description boolean
ok()
Whether the request was successful (status code 2xx) void
assertOk()
Throws an HttpException if this request was unsuccessful String
text()
Get the response body as String Array<byte>
getBytes()
Get the response body as byte[]
<T> T
json(Type type)
Deserializes json response <T> T
json(Gson gson, Type type)
Deserializes json response <T> T
json(Class<T> type)
Deserializes json response <T> T
json(Gson gson, Class<T> type)
Deserializes json response InputStream
stream()
Get the raw response stream of this connection void
pipe(OutputStream os)
Pipe response into OutputStream. void
saveToFile(@NonNull() File file)
Saves the received data to the specified File void
saveToFile(@NonNull() File file, @Nullable() String sha1sum)
Saves the received data to the specified File and verifies its integrity using the specified sha1sum void
close()
Closes the Request associated with this Response -
-
Constructor Detail
-
Http.Response
Http.Response(Http.Request req)
Construct a Response- Parameters:
req
- The http request to execute
-
-
Method Detail
-
ok
boolean ok()
Whether the request was successful (status code 2xx)
-
assertOk
void assertOk()
Throws an HttpException if this request was unsuccessful
-
json
<T> T json(Gson gson, Type type)
Deserializes json response
- Parameters:
gson
- Gson instancetype
- Type to deserialize into
-
json
<T> T json(Class<T> type)
Deserializes json response
- Parameters:
type
- Class to deserialize into
-
json
<T> T json(Gson gson, Class<T> type)
Deserializes json response
- Parameters:
gson
- Gson instancetype
- Class to deserialize into
-
stream
InputStream stream()
Get the raw response stream of this connection
-
pipe
void pipe(OutputStream os)
Pipe response into OutputStream. Remember to close the OutputStream
- Parameters:
os
- The OutputStream to pipe into
-
saveToFile
void saveToFile(@NonNull() File file)
Saves the received data to the specified File
- Parameters:
file
- The file to save the data to
-
saveToFile
void saveToFile(@NonNull() File file, @Nullable() String sha1sum)
Saves the received data to the specified File and verifies its integrity using the specified sha1sum
- Parameters:
file
- The file to save the data tosha1sum
- checksum to check the file's integrity.
-
close
void close()
-
-
-
-