Package net.dona.doip.client.transport
Class DoipClientResponse
java.lang.Object
net.dona.doip.client.transport.DoipClientResponse
- All Implemented Interfaces:
AutoCloseable
A response from a server to the client.
-
Constructor Summary
ConstructorsConstructorDescriptionDoipClientResponse
(DoipResponseHeaders initialSegment, InDoipMessage in) Constructs the response with the given initial segment, and further segments to be read from the suppliedInDoipMessage
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the response "output" and runs a callback if one was specified usingsetOnClose(Runnable)
.com.google.gson.JsonElement
getAttribute
(String key) Returns a specified attribute from the initial segment of the response.Returns a specified attribute from the initial segment of the response, as a String.com.google.gson.JsonObject
Returns the attributes from the initial segment of the response.Returns the "output" of the response as anInDoipMessage
for the client to read from.Returns the status code from the initial segment of the response.void
setOnClose
(Runnable onClose) Sets a callback which will be run after closing the response.
-
Constructor Details
-
DoipClientResponse
Constructs the response with the given initial segment, and further segments to be read from the suppliedInDoipMessage
.- Parameters:
initialSegment
- the contents of the initial segment of the responsein
- further segments fo the response
-
-
Method Details
-
setOnClose
Sets a callback which will be run after closing the response.- Parameters:
onClose
- the callback to be run after closing the response
-
getStatus
Returns the status code from the initial segment of the response.- Returns:
- the status code from the initial segment of the response
-
getAttributes
public com.google.gson.JsonObject getAttributes()Returns the attributes from the initial segment of the response.- Returns:
- the attributes from the initial segment of the response
-
getAttribute
Returns a specified attribute from the initial segment of the response.- Parameters:
key
- the property name of the attribute to retrieve- Returns:
- the value of the specified attribute
-
getAttributeAsString
Returns a specified attribute from the initial segment of the response, as a String.- Parameters:
key
- the property name of the attribute to retrieve- Returns:
- the value as a String of the specified attribute
-
getOutput
Returns the "output" of the response as anInDoipMessage
for the client to read from. This can either be a single JSON segment, in the case of a "compact" response fully contained in the initial segment, or in general it can be all segments following the initial segment.- Returns:
- the output of a DOIP client response
-
close
public void close()Closes the response "output" and runs a callback if one was specified usingsetOnClose(Runnable)
.- Specified by:
close
in interfaceAutoCloseable
-