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 intstatusCodepublic final StringstatusMessage
-
Constructor Summary
Constructors Constructor Description Http.Response(Http.Request req)Construct a Response
-
Method Summary
Modifier and Type Method Description booleanok()Whether the request was successful (status code 2xx) voidassertOk()Throws an HttpException if this request was unsuccessful Stringtext()Get the response body as String Array<byte>getBytes()Get the response body as byte[]<T> Tjson(Type type)Deserializes json response <T> Tjson(Gson gson, Type type)Deserializes json response <T> Tjson(Class<T> type)Deserializes json response <T> Tjson(Gson gson, Class<T> type)Deserializes json response InputStreamstream()Get the raw response stream of this connection voidpipe(OutputStream os)Pipe response into OutputStream. voidsaveToFile(@NonNull() File file)Saves the received data to the specified File voidsaveToFile(@NonNull() File file, @Nullable() String sha1sum)Saves the received data to the specified File and verifies its integrity using the specified sha1sum voidclose()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(Type type)
Deserializes json response
- Parameters:
type- Type to deserialize into- Returns:
Response Object
-
json
<T> T json(Gson gson, Type type)
Deserializes json response
- Parameters:
gson- Gson instancetype- Type to deserialize into- Returns:
Response Object
-
json
<T> T json(Class<T> type)
Deserializes json response
- Parameters:
type- Class to deserialize into- Returns:
Response Object
-
json
<T> T json(Gson gson, Class<T> type)
Deserializes json response
- Parameters:
gson- Gson instancetype- Class to deserialize into- Returns:
Response Object
-
stream
InputStream stream()
Get the raw response stream of this connection
- Returns:
InputStream
-
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()
-
-
-
-