Class Response
java.lang.Object
com.pixelservices.flash.components.http.lifecycle.Response
Represents an HTTP response, supporting serialization to a ByteBuffer.
-
Constructor Summary
ConstructorsConstructorDescriptionResponse()Constructs a new Response object with default status and a default content type of "text/plain". -
Method Summary
Modifier and TypeMethodDescriptionSets the body of the response.voidMarks the response as finalized, preventing further modifications.getBody()Retrieves the body of the response.byte[]Gets the body as a byte array.Gets the content type of the response.Gets a ByteBuffer containing just the headers.byte[]Gets just the header portion of the response as a byte array.Serializes the response into a ByteBuffer.byte[]Serializes the response body based on its content type.Adds a header to the response.booleanstatus(int code) Sets the HTTP status code of the response.toString()Sets the content type of the response.
-
Constructor Details
-
Response
public Response()Constructs a new Response object with default status and a default content type of "text/plain".
-
-
Method Details
-
status
Sets the HTTP status code of the response.- Parameters:
code- the status code to set- Returns:
- the updated Response object
- Throws:
IllegalStateException- if the response is already finalized
-
type
Sets the content type of the response.- Parameters:
contentType- the content type to set- Returns:
- the updated Response object
- Throws:
IllegalStateException- if the response is already finalized
-
header
Adds a header to the response.- Parameters:
key- the header namevalue- the header value- Returns:
- the updated Response object
- Throws:
IllegalStateException- if the response is already finalized
-
body
Sets the body of the response. Warning: Overrides existing body content.- Parameters:
body- the body content- Returns:
- the updated Response object
- Throws:
IllegalStateException- if the response is already finalized
-
getBody
Retrieves the body of the response.- Returns:
- the body content
-
finalizeResponse
public void finalizeResponse()Marks the response as finalized, preventing further modifications. -
getSerialized
Serializes the response into a ByteBuffer.- Returns:
- the serialized response as a ByteBuffer
-
getSerializedBody
public byte[] getSerializedBody()Serializes the response body based on its content type.- Returns:
- the serialized body as a byte array
- Throws:
UnsupportedOperationException- if the content type is unsupported or the body type is invalid
-
isFinalized
public boolean isFinalized() -
toString
-
getBodyBytes
public byte[] getBodyBytes()Gets the body as a byte array.- Returns:
- the body as a byte array
-
getContentType
Gets the content type of the response.- Returns:
- the content type
-
getHeaderBytes
public byte[] getHeaderBytes()Gets just the header portion of the response as a byte array. This is useful for chunked sending of large responses.- Returns:
- the headers as a byte array
-
getHeaderBuffer
Gets a ByteBuffer containing just the headers.- Returns:
- ByteBuffer with headers
-