Class Header


  • public class Header
    extends java.lang.Object
    Event-stream header. This object can be represented in many types, so before using the getValueAs*() functions, check the value of getHeaderType() and then decide which getValueAs*() function to call based on the returned type.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Header createHeader​(java.lang.String name, boolean value)
      Create a header with name of boolean value
      static Header createHeader​(java.lang.String name, byte value)
      Create a header with name of byte or int8 value
      static Header createHeader​(java.lang.String name, byte[] value)
      Create a header with name of byte[] value
      static Header createHeader​(java.lang.String name, int value)
      Create a header with name of int or int32 value
      static Header createHeader​(java.lang.String name, long value)
      Create a header with name of long or int64 value
      static Header createHeader​(java.lang.String name, short value)
      Create a header with name of short or int16 value
      static Header createHeader​(java.lang.String name, java.lang.String value)
      Create a header with name of String value
      static Header createHeader​(java.lang.String name, java.util.Date value)
      Create a header with name of Date (assumed to be UTC) value
      static Header createHeader​(java.lang.String name, java.util.UUID value)
      Create a header with name of UUID value
      boolean equals​(java.lang.Object o)  
      static Header fromByteBuffer​(java.nio.ByteBuffer buffer)
      Marshals buffer into a Header instance
      HeaderType getHeaderType()
      Gets the header type of the value.
      java.lang.String getName()
      Gets the name of the header as a (UTF-8) string
      int getTotalByteLength()  
      boolean getValueAsBoolean()
      Gets the value as a boolean.
      byte getValueAsByte()
      Gets the value as a byte or int8.
      byte[] getValueAsBytes()
      Gets the value as a byte[].
      int getValueAsInt()
      Gets the value as an int or int32.
      long getValueAsLong()
      Gets the value as a long or int64.
      short getValueAsShort()
      Gets the value as a short or int16.
      java.lang.String getValueAsString()
      Gets the value as a utf-8 encoded string.
      java.util.Date getValueAsTimestamp()
      Gets the value as a Date.
      java.util.UUID getValueAsUUID()
      Gets the value as a UUID.
      int hashCode()  
      void writeToByteBuffer​(java.nio.ByteBuffer buffer)
      Writes the value of this header into a buffer, using the wire representation of the header.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • createHeader

        public static Header createHeader​(java.lang.String name,
                                          boolean value)
        Create a header with name of boolean value
        Parameters:
        name - name for the header.
        value - value for the header.
        Returns:
        new Header instance
      • createHeader

        public static Header createHeader​(java.lang.String name,
                                          byte value)
        Create a header with name of byte or int8 value
        Parameters:
        name - name for the header
        value - value for the header
        Returns:
        new Header instance
      • createHeader

        public static Header createHeader​(java.lang.String name,
                                          java.lang.String value)
        Create a header with name of String value
        Parameters:
        name - name for the header
        value - value for the header
        Returns:
        new Header instance
      • createHeader

        public static Header createHeader​(java.lang.String name,
                                          short value)
        Create a header with name of short or int16 value
        Parameters:
        name - name for the header
        value - value for the header
        Returns:
        new Header instance
      • createHeader

        public static Header createHeader​(java.lang.String name,
                                          int value)
        Create a header with name of int or int32 value
        Parameters:
        name - name for the header
        value - value for the header
        Returns:
        new Header instance
      • createHeader

        public static Header createHeader​(java.lang.String name,
                                          long value)
        Create a header with name of long or int64 value
        Parameters:
        name - name for the header
        value - value for the header
        Returns:
        new Header instance
      • createHeader

        public static Header createHeader​(java.lang.String name,
                                          java.util.Date value)
        Create a header with name of Date (assumed to be UTC) value
        Parameters:
        name - name for the header
        value - value for the header
        Returns:
        new Header instance
      • createHeader

        public static Header createHeader​(java.lang.String name,
                                          byte[] value)
        Create a header with name of byte[] value
        Parameters:
        name - name for the header
        value - value for the header
        Returns:
        new Header instance
      • createHeader

        public static Header createHeader​(java.lang.String name,
                                          java.util.UUID value)
        Create a header with name of UUID value
        Parameters:
        name - name for the header
        value - value for the header
        Returns:
        new Header instance
      • fromByteBuffer

        public static Header fromByteBuffer​(java.nio.ByteBuffer buffer)
        Marshals buffer into a Header instance
        Parameters:
        buffer - buffer to read the header data from
        Returns:
        New instance of Header
      • writeToByteBuffer

        public void writeToByteBuffer​(java.nio.ByteBuffer buffer)
        Writes the value of this header into a buffer, using the wire representation of the header.
        Parameters:
        buffer - buffer to write this header into
      • getName

        public java.lang.String getName()
        Gets the name of the header as a (UTF-8) string
        Returns:
        utf-8 encoded string for the header name
      • getHeaderType

        public HeaderType getHeaderType()
        Gets the header type of the value.
        Returns:
        HeaderType for this header
      • getValueAsBoolean

        public boolean getValueAsBoolean()
        Gets the value as a boolean. This assumes you've already checked getHeaderType() returns BooleanTrue or BooleanFalse
        Returns:
        the value as a boolean
      • getValueAsByte

        public byte getValueAsByte()
        Gets the value as a byte or int8. This assumes you've already checked getHeaderType() returns Byte
        Returns:
        the value as a byte
      • getValueAsShort

        public short getValueAsShort()
        Gets the value as a short or int16. This assumes you've already checked getHeaderType() returns Int16
        Returns:
        the value as a short
      • getValueAsInt

        public int getValueAsInt()
        Gets the value as an int or int32. This assumes you've already checked getHeaderType() returns Int32
        Returns:
        the value as a int
      • getValueAsLong

        public long getValueAsLong()
        Gets the value as a long or int64. This assumes you've already checked getHeaderType() returns Int64
        Returns:
        the value as a long
      • getValueAsTimestamp

        public java.util.Date getValueAsTimestamp()
        Gets the value as a Date. This assumes you've already checked getHeaderType() returns TimeStamp
        Returns:
        the value as a Date
      • getValueAsBytes

        public byte[] getValueAsBytes()
        Gets the value as a byte[]. This assumes you've already checked getHeaderType() returns ByteBuf
        Returns:
        the value as a byte[]
      • getValueAsString

        public java.lang.String getValueAsString()
        Gets the value as a utf-8 encoded string. This assumes you've already checked getHeaderType() returns String
        Returns:
        the value as a utf-8 encoded string
      • getValueAsUUID

        public java.util.UUID getValueAsUUID()
        Gets the value as a UUID. This assumes you've already checked getHeaderType() returns UUID
        Returns:
        the value as a UUID
      • getTotalByteLength

        public int getTotalByteLength()
        Returns:
        the total binary wire representation length of this header.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object