Class HttpResponse<T>

java.lang.Object
http.server.response.HttpResponse<T>

public class HttpResponse<T>
extends java.lang.Object
HttpResponse is used to create and send Http responses easily.
  • Field Summary

    Fields
    Modifier and Type Field Description
    T body  
    long contentLength  
    java.lang.String contentType  
    HttpStatusCode statusCode  
  • Constructor Summary

    Constructors
    Constructor Description
    HttpResponse​(HttpStatusCode statusCode, java.lang.String contentType, T body)  
    HttpResponse​(HttpStatusCode statusCode, T body)  
  • Method Summary

    Modifier and Type Method Description
    static HttpResponse badRequestResponse()
    Returns an HttpResponse having the Bad Request status code
    static HttpResponse internalServerErrorResponse()
    Returns an HttpResponse having the Internal Server Error status code
    void sendResponse​(java.io.BufferedOutputStream out)
    sendResponse sends the response through the PrintWriter Please be awater that it will flush the PrintWriter
    void writeBody​(java.io.BufferedOutputStream out)
    writeBody will write the body of the response on the BufferedOutputStream out but not flush it.
    void writeHeaders​(java.io.BufferedOutputStream out)
    writeHeader will write the header of the response on the BufferedOutputStream out but not flush it.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • statusCode

      public HttpStatusCode statusCode
    • contentType

      public java.lang.String contentType
    • body

      public T body
    • contentLength

      public long contentLength
  • Constructor Details

    • HttpResponse

      public HttpResponse​(HttpStatusCode statusCode, java.lang.String contentType, T body)
    • HttpResponse

      public HttpResponse​(HttpStatusCode statusCode, T body)
  • Method Details

    • writeHeaders

      public void writeHeaders​(java.io.BufferedOutputStream out)
      writeHeader will write the header of the response on the BufferedOutputStream out but not flush it.
      Parameters:
      out - the BufferedOutputStream attached to the open Socket
    • writeBody

      public void writeBody​(java.io.BufferedOutputStream out)
      writeBody will write the body of the response on the BufferedOutputStream out but not flush it.
      Parameters:
      out - the BufferedOutputStream attached to the open Socket
    • sendResponse

      public void sendResponse​(java.io.BufferedOutputStream out)
      sendResponse sends the response through the PrintWriter Please be awater that it will flush the PrintWriter
      Parameters:
      out - he PrintWriter used to send the response
    • badRequestResponse

      public static HttpResponse badRequestResponse()
      Returns an HttpResponse having the Bad Request status code
      Returns:
      HttpResponse having the Bad Request status code
    • internalServerErrorResponse

      public static HttpResponse internalServerErrorResponse()
      Returns an HttpResponse having the Internal Server Error status code
      Returns:
      HttpResponse having the Internal Server Error status code