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()

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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

      • text

         String text()

        Get the response body as String

      • getBytes

         Array<byte> getBytes()

        Get the response body as byte[]

      • json

         <T> T json(Type type)

        Deserializes json response

        Parameters:
        type - Type to deserialize into
      • json

         <T> T json(Gson gson, Type type)

        Deserializes json response

        Parameters:
        gson - Gson instance
        type - 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 instance
        type - Class to deserialize into
      • 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 to
        sha1sum - checksum to check the file's integrity.