Class DoipClientResponse

java.lang.Object
net.dona.doip.client.transport.DoipClientResponse
All Implemented Interfaces:
AutoCloseable

public class DoipClientResponse extends Object implements AutoCloseable
A response from a server to the client.
  • Constructor Details

    • DoipClientResponse

      public DoipClientResponse(DoipResponseHeaders initialSegment, InDoipMessage in)
      Constructs the response with the given initial segment, and further segments to be read from the supplied InDoipMessage.
      Parameters:
      initialSegment - the contents of the initial segment of the response
      in - further segments fo the response
  • Method Details

    • setOnClose

      public void setOnClose(Runnable onClose)
      Sets a callback which will be run after closing the response.
      Parameters:
      onClose - the callback to be run after closing the response
    • getStatus

      public String 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

      public com.google.gson.JsonElement getAttribute(String key)
      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

      public String getAttributeAsString(String key)
      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

      public InDoipMessage getOutput()
      Returns the "output" of the response as an InDoipMessage 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 using setOnClose(Runnable).
      Specified by:
      close in interface AutoCloseable