Class Frame


  • public class Frame
    extends java.lang.Object
    Represents a STOMP frame. STOMP frames are structured as follows. It starts by a command, followed by a set of headers. Then the frame may have a body and is finished by a 0 byte. This class represents this structure and provide access to the different parts. This class is NOT thread-safe.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Frame.Command
      The list of command defined by the STOMP specification.
      static class  Frame.Heartbeat
      Represents the heartbeat configuration.
    • Constructor Summary

      Constructors 
      Constructor Description
      Frame()
      Creates an un-configured frame.
      Frame​(io.vertx.core.json.JsonObject json)
      Creates a new instance of Frame from its JSON representation.
      Frame​(Frame other)
      Creates a new instance of Frame by copying the values from the other frame.
      Frame​(Frame.Command command, java.util.Map<java.lang.String,​java.lang.String> headers, io.vertx.core.buffer.Buffer body)
      Creates a new instance of Frame.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Frame addHeader​(java.lang.String key, java.lang.String value)
      Adds a header to the frame.
      java.lang.String encoding()
      Read the frame encoding.
      java.lang.String getAck()
      Gets the value of the ack header.
      io.vertx.core.buffer.Buffer getBody()  
      byte[] getBodyAsByteArray()  
      java.lang.String getBodyAsString()
      Gets the body of the frames as a String encoded in the frame encoding.
      java.lang.String getBodyAsString​(java.lang.String encoding)
      Gets the body of the frames as a String encoded in the given encoding.
      Frame.Command getCommand()  
      java.lang.String getDestination()  
      java.lang.String getHeader​(java.lang.String name)
      Gets the value of the header with the given name.
      java.util.Map<java.lang.String,​java.lang.String> getHeaders()
      Gets the frame headers.
      java.lang.String getId()  
      java.lang.String getReceipt()  
      java.lang.String getTransaction()  
      boolean hasEmptyBody()  
      Frame setBody​(io.vertx.core.buffer.Buffer body)
      Sets the body of the frame.
      Frame setCommand​(Frame.Command command)
      Sets the frame command.
      Frame setDestination​(java.lang.String destination)  
      Frame setHeaders​(java.util.Map<java.lang.String,​java.lang.String> headers)
      Sets the headers of the frames.
      Frame setId​(java.lang.String id)  
      Frame setTransaction​(java.lang.String id)  
      io.vertx.core.buffer.Buffer toBuffer()
      This method does not enforce the trailing line option.
      io.vertx.core.buffer.Buffer toBuffer​(boolean trailingLine)
      Creates a buffer for the current frame.
      io.vertx.core.json.JsonObject toJson()  
      java.lang.String toString()  
      void validate()
      Checks the validity of the frame.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Frame

        public Frame()
        Creates an un-configured frame. Should only be used by converters.
      • Frame

        public Frame​(Frame other)
        Creates a new instance of Frame by copying the values from the other frame. The body of the frame is copied.
        Parameters:
        other - the frame to copy.
      • Frame

        public Frame​(io.vertx.core.json.JsonObject json)
        Creates a new instance of Frame from its JSON representation.
        Parameters:
        json - the json form of the frame
      • Frame

        public Frame​(Frame.Command command,
                     java.util.Map<java.lang.String,​java.lang.String> headers,
                     io.vertx.core.buffer.Buffer body)
        Creates a new instance of Frame.
        Parameters:
        command - the command, must not be null
        headers - the headers, must not be null
        body - the body
    • Method Detail

      • addHeader

        public Frame addHeader​(java.lang.String key,
                               java.lang.String value)
        Adds a header to the frame.
        Parameters:
        key - the header name
        value - the header value
        Returns:
        the current Frame
      • getAck

        public java.lang.String getAck()
        Gets the value of the ack header.
        Returns:
        the ack header value, null if not set
      • getHeaders

        public java.util.Map<java.lang.String,​java.lang.String> getHeaders()
        Gets the frame headers. Modifications to the returned Map modifies the headers of the frame.
        Returns:
        the headers
      • setHeaders

        public Frame setHeaders​(java.util.Map<java.lang.String,​java.lang.String> headers)
        Sets the headers of the frames.
        Parameters:
        headers - the header, may be null. In the null case, an empty map is used to store the frame headers.
        Returns:
        the current Frame
      • setCommand

        public Frame setCommand​(Frame.Command command)
        Sets the frame command.
        Parameters:
        command - the command, must not be null
        Returns:
        the current Frame
      • setBody

        public Frame setBody​(io.vertx.core.buffer.Buffer body)
        Sets the body of the frame.
        Parameters:
        body - the body
        Returns:
        the current Frame
      • toJson

        public io.vertx.core.json.JsonObject toJson()
        Returns:
        the JSON representation of the current frame.
      • validate

        public void validate()
        Checks the validity of the frame. Frames must have a valid command, and not all frames can have a body.
      • hasEmptyBody

        public boolean hasEmptyBody()
        Returns:
        whether or not the frame has a body.
      • getHeader

        public java.lang.String getHeader​(java.lang.String name)
        Gets the value of the header with the given name.
        Parameters:
        name - the header name
        Returns:
        the value, null if not set
      • getBody

        public io.vertx.core.buffer.Buffer getBody()
      • getBodyAsString

        public java.lang.String getBodyAsString​(java.lang.String encoding)
        Gets the body of the frames as a String encoded in the given encoding.
        Parameters:
        encoding - the encoding
        Returns:
        the body, null if none
      • getBodyAsString

        public java.lang.String getBodyAsString()
        Gets the body of the frames as a String encoded in the frame encoding.
        Returns:
        the body, null if none
      • encoding

        public java.lang.String encoding()
        Read the frame encoding. If not set defaults to utf-8.
        Returns:
        the encoding
      • getBodyAsByteArray

        public byte[] getBodyAsByteArray()
        Returns:
        the body of the frame as a byte array, null if none.
      • toBuffer

        public io.vertx.core.buffer.Buffer toBuffer​(boolean trailingLine)
        Creates a buffer for the current frame. This buffer may contain an empty line if the trailingLine is set to true
        Parameters:
        trailingLine - whether or not a trailing line should be added to the buffer
        Returns:
        a Buffer containing the STOMP frame. It follows strictly the STOMP specification (including header encoding).
      • toBuffer

        public io.vertx.core.buffer.Buffer toBuffer()
        This method does not enforce the trailing line option. It should not be used directly, except for the PING frame.
        Returns:
        a Buffer containing the STOMP frame. It follows strictly the STOMP specification (including header encoding).
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • setDestination

        public Frame setDestination​(java.lang.String destination)
      • setTransaction

        public Frame setTransaction​(java.lang.String id)
      • setId

        public Frame setId​(java.lang.String id)
      • getId

        public java.lang.String getId()
      • getReceipt

        public java.lang.String getReceipt()
      • getTransaction

        public java.lang.String getTransaction()
      • getDestination

        public java.lang.String getDestination()