Interface MessageReader

All Superinterfaces:
io.cloudevents.rw.CloudEventReader, StructuredMessageReader
All Known Implementing Classes:
BaseBinaryMessageReader, BaseGenericBinaryMessageReaderImpl, BaseStructuredMessageReader, GenericStructuredMessageReader

@ParametersAreNonnullByDefault public interface MessageReader extends StructuredMessageReader, io.cloudevents.rw.CloudEventReader
Represents a CloudEvent message reader.

This class expands the CloudEventReader to define reading both binary and structured messages.

  • Method Summary

    Modifier and Type
    Method
    Description
     
    default <BW extends io.cloudevents.rw.CloudEventWriter<R>, R>
    R
    read(MessageWriter<BW,R> writer)
    Read the content of this object using a MessageWriter.
    <R> R
    Read the message as structured encoded message using the provided writer
    default <W extends io.cloudevents.rw.CloudEventWriter<R>, R>
    R
    read(io.cloudevents.rw.CloudEventWriterFactory<W,R> writerFactory)
    Like read(CloudEventWriterFactory, CloudEventDataMapper), but with the identity CloudEventDataMapper.
    <W extends io.cloudevents.rw.CloudEventWriter<R>, R>
    R
    read(io.cloudevents.rw.CloudEventWriterFactory<W,R> writerFactory, io.cloudevents.rw.CloudEventDataMapper<? extends io.cloudevents.CloudEventData> mapper)
    Read the message as binary encoded message using the provided writer factory.
    default io.cloudevents.CloudEvent
    Like toEvent(CloudEventDataMapper), but with the identity CloudEventDataMapper.
    default io.cloudevents.CloudEvent
    toEvent(io.cloudevents.rw.CloudEventDataMapper<? extends io.cloudevents.CloudEventData> mapper)
    Translate this message into a CloudEvent representation, mapping the data with the provided mapper.
  • Method Details

    • read

      default <W extends io.cloudevents.rw.CloudEventWriter<R>, R> R read(io.cloudevents.rw.CloudEventWriterFactory<W,R> writerFactory) throws io.cloudevents.rw.CloudEventRWException, IllegalStateException
      Like read(CloudEventWriterFactory, CloudEventDataMapper), but with the identity CloudEventDataMapper.
      Specified by:
      read in interface io.cloudevents.rw.CloudEventReader
      Throws:
      io.cloudevents.rw.CloudEventRWException
      IllegalStateException
      See Also:
    • read

      <W extends io.cloudevents.rw.CloudEventWriter<R>, R> R read(io.cloudevents.rw.CloudEventWriterFactory<W,R> writerFactory, io.cloudevents.rw.CloudEventDataMapper<? extends io.cloudevents.CloudEventData> mapper) throws io.cloudevents.rw.CloudEventRWException, IllegalStateException
      Read the message as binary encoded message using the provided writer factory.
      Specified by:
      read in interface io.cloudevents.rw.CloudEventReader
      Type Parameters:
      W - the CloudEventWriter type
      R - the return type of the CloudEventWriter
      Parameters:
      writerFactory - a factory that generates a reader starting from the SpecVersion of the event
      mapper - the mapper to use to map the data, if any.
      Throws:
      io.cloudevents.rw.CloudEventRWException - if something went wrong during the visit.
      IllegalStateException - if the message is not in binary encoding.
    • read

      <R> R read(StructuredMessageWriter<R> writer) throws io.cloudevents.rw.CloudEventRWException, IllegalStateException
      Read the message as structured encoded message using the provided writer
      Specified by:
      read in interface StructuredMessageReader
      Type Parameters:
      R - 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.
    • getEncoding

      Encoding getEncoding()
      Returns:
      The message encoding
    • read

      default <BW extends io.cloudevents.rw.CloudEventWriter<R>, R> R read(MessageWriter<BW,R> writer) throws io.cloudevents.rw.CloudEventRWException, IllegalStateException
      Read the content of this object using a MessageWriter. This method allows to transcode an event from one transport to another without converting it to CloudEvent. The resulting encoding will be the same as the original encoding.
      Type Parameters:
      BW - the CloudEventWriter type
      R - the return type of both CloudEventWriter and StructuredMessageWriter
      Parameters:
      writer - the MessageWriter accepting this Message
      Returns:
      The return value of the MessageWriter
      Throws:
      io.cloudevents.rw.CloudEventRWException - if something went wrong during the visit.
      IllegalStateException - if the message has an unknown encoding.
    • toEvent

      default io.cloudevents.CloudEvent toEvent() throws io.cloudevents.rw.CloudEventRWException, IllegalStateException
      Like toEvent(CloudEventDataMapper), but with the identity CloudEventDataMapper.
      Specified by:
      toEvent in interface StructuredMessageReader
      Throws:
      io.cloudevents.rw.CloudEventRWException
      IllegalStateException
      See Also:
    • toEvent

      default io.cloudevents.CloudEvent toEvent(io.cloudevents.rw.CloudEventDataMapper<? extends io.cloudevents.CloudEventData> mapper) throws io.cloudevents.rw.CloudEventRWException, IllegalStateException
      Translate this message into a CloudEvent representation, mapping the data with the provided mapper.
      Specified by:
      toEvent in interface StructuredMessageReader
      Parameters:
      mapper - the mapper to use to map the data, if any.
      Returns:
      A CloudEvent with the contents of this message.
      Throws:
      io.cloudevents.rw.CloudEventRWException - if something went wrong during the read.
      IllegalStateException - if the message has an unknown encoding.