Package http.server.response
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 codestatic HttpResponse
internalServerErrorResponse()
Returns an HttpResponse having the Internal Server Error status codevoid
sendResponse(java.io.BufferedOutputStream out)
sendResponse sends the response through the PrintWriter Please be awater that it will flush the PrintWritervoid
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
-
contentType
public java.lang.String contentType -
body
-
contentLength
public long contentLength
-
-
Constructor Details
-
HttpResponse
-
HttpResponse
-
-
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
Returns an HttpResponse having the Bad Request status code- Returns:
- HttpResponse having the Bad Request status code
-
internalServerErrorResponse
Returns an HttpResponse having the Internal Server Error status code- Returns:
- HttpResponse having the Internal Server Error status code
-