Class MessageUtils

java.lang.Object
io.cloudevents.core.message.impl.MessageUtils

public class MessageUtils extends Object
Collection of utilities useful to implement MessageReader and MessageWriter related code.
  • Constructor Details

    • MessageUtils

      public MessageUtils()
  • Method Details

    • parseStructuredOrBinaryMessage

      public static MessageReader parseStructuredOrBinaryMessage(Supplier<String> contentTypeHeaderReader, Function<EventFormat,MessageReader> structuredMessageFactory, Supplier<String> specVersionHeaderReader, Function<io.cloudevents.SpecVersion,MessageReader> binaryMessageFactory) throws io.cloudevents.rw.CloudEventRWException
      Common flow to parse an incoming message that could be structured or binary.
      Parameters:
      contentTypeHeaderReader - supplier that returns the content type header, if any
      structuredMessageFactory - factory to create the structured MessageReader from the provided EventFormat
      specVersionHeaderReader - supplier that returns the spec version header, if any
      binaryMessageFactory - factory to create the binary MessageReader from the provided SpecVersion
      Returns:
      the instantiated MessageReader
      Throws:
      io.cloudevents.rw.CloudEventRWException - if something goes wrong while resolving the SpecVersion or if the message has unknown encoding
    • generateAttributesToHeadersMapping

      public static <V> Map<String,V> generateAttributesToHeadersMapping(Function<String,V> headerNameMapping)
      Generate a map with cloudevents attributes as keys and header keys as values
      Type Parameters:
      V - Header key type
      Parameters:
      headerNameMapping - mapper to generate the header name
      Returns:
      the generated mapping
    • generateWrongEncoding

      public static IllegalStateException generateWrongEncoding(Encoding expected, Encoding actual)
      Parameters:
      expected - the expected encoding
      actual - the actual encoding
      Returns:
      a new instance of IllegalStateException.