Interface Submitter.Response

Enclosing interface:
Submitter

public static interface Submitter.Response
Represents the response received from executing a request.
  • Method Details

    • create

      static Submitter.Response create(int statusCode, Submitter.Response.InputStreamSupplier supplier, Exception exception)
      Creates a new Submitter.Response instance.

      The body of the created response is cached on the first read, so both readString() and getInputStream() may be called multiple times without losing data.

      Parameters:
      statusCode - the status code
      supplier - the input stream supplier (can be null)
      exception - the exception (can be null)
      Returns:
      the response instance
    • readAll

      static byte[] readAll(InputStream stream) throws IOException
      Reads the given stream completely.
      Parameters:
      stream - the stream to read
      Returns:
      the read bytes
      Throws:
      IOException - if an I/O error occurs
    • getStatusCode

      int getStatusCode()
      Gets the HTTP response status code, or 0 / -1 if a client-side exception occurred.
      Returns:
      the status code
    • getInputStream

      InputStream getInputStream() throws IOException
      Gets the response body input stream.
      Returns:
      the input stream
      Throws:
      IOException - if an I/O error occurs
    • getException

      Optional<Exception> getException()
      Gets the exception that occurred during execution, if any.
      Returns:
      the exception, or empty if successful
    • isSuccessful

      default boolean isSuccessful()
      Checks if the request was accepted by the server.
      Returns:
      true if the status code is in the 2xx range, false otherwise
    • readString

      default String readString() throws Exception
      Reads the entire response body stream as a UTF-8 String.
      Returns:
      the response body as a String
      Throws:
      Exception - if an I/O or conversion error occurs