Class GenericStructuredMessageReader

java.lang.Object
io.cloudevents.core.message.impl.BaseStructuredMessageReader
io.cloudevents.core.message.impl.GenericStructuredMessageReader
All Implemented Interfaces:
MessageReader, StructuredMessageReader, io.cloudevents.rw.CloudEventReader

public class GenericStructuredMessageReader extends BaseStructuredMessageReader
Generic implementation of a structured message.
  • Constructor Details

    • GenericStructuredMessageReader

      public GenericStructuredMessageReader(EventFormat format, byte[] payload)
  • Method Details

    • read

      public <T> T read(StructuredMessageWriter<T> writer) throws io.cloudevents.rw.CloudEventRWException, IllegalStateException
      Description copied from interface: MessageReader
      Read the message as structured encoded message using the provided writer
      Type Parameters:
      T - the return type of the StructuredMessageWriter
      Parameters:
      writer - Structured Message writer
      Returns:
      the return value returned by StructuredMessageWriter.setEvent(EventFormat, byte[])
      Throws:
      io.cloudevents.rw.CloudEventRWException - if something went wrong during the visit.
      IllegalStateException - if the message is not in structured encoding.
    • fromContentType

      public static GenericStructuredMessageReader fromContentType(String contentType, byte[] payload)
      Create a generic structured message from a payload
      Parameters:
      contentType - content type to use to resolve the EventFormat
      payload - serialized event
      Returns:
      null if format was not found, otherwise returns the built message
    • from

      @Nullable public static GenericStructuredMessageReader from(io.cloudevents.CloudEvent event, String contentType)
      Create a generic structured message from a CloudEvent
      Parameters:
      event -
      contentType - content type to use to resolve the EventFormat
      Returns:
      null if format was not found, otherwise returns the built message
    • from

      public static GenericStructuredMessageReader from(io.cloudevents.CloudEvent event, EventFormat format)
      Create a generic structured message from a CloudEvent
      Parameters:
      event -
      format -
      Returns:
      returns the built message