Class CloudEventUtils

java.lang.Object
io.cloudevents.core.CloudEventUtils

public final class CloudEventUtils extends Object
This class contains a set of utility methods to deal with conversions of io.cloudevents related interfaces
  • Method Summary

    Modifier and Type
    Method
    Description
    static <R extends io.cloudevents.CloudEventData>
    R
    mapData(io.cloudevents.CloudEvent event, io.cloudevents.rw.CloudEventDataMapper<R> mapper)
    Get the data contained in event and map it using the provided mapper.
    static io.cloudevents.rw.CloudEventContextReader
    toContextReader(io.cloudevents.CloudEventContext event)
    Convert a CloudEvent to a CloudEventContextReader.
    static io.cloudevents.CloudEvent
    toEvent(io.cloudevents.rw.CloudEventReader reader)
    Convert a CloudEventReader to a CloudEvent.
    static io.cloudevents.CloudEvent
    toEvent(io.cloudevents.rw.CloudEventReader reader, io.cloudevents.rw.CloudEventDataMapper<?> mapper)
    Convert a CloudEventReader to a CloudEvent mapping the data with the provided mapper.
    static io.cloudevents.rw.CloudEventReader
    toReader(io.cloudevents.CloudEvent event)
    Convert a CloudEvent to a CloudEventReader.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • toReader

      public static io.cloudevents.rw.CloudEventReader toReader(io.cloudevents.CloudEvent event)
      Convert a CloudEvent to a CloudEventReader. This method provides a default implementation for CloudEvent that doesn't implement CloudEventReader.

      It's safe to use the returned CloudEventReader multiple times.

      Parameters:
      event - the event to convert
      Returns:
      the reader implementation
    • toContextReader

      public static io.cloudevents.rw.CloudEventContextReader toContextReader(io.cloudevents.CloudEventContext event)
      Convert a CloudEvent to a CloudEventContextReader. This method provides a default implementation for CloudEvent that doesn't implement CloudEventContextReader.

      It's safe to use the returned CloudEventReader multiple times.

      Parameters:
      event - the event to convert
      Returns:
      the context reader implementation
    • toEvent

      public static io.cloudevents.CloudEvent toEvent(io.cloudevents.rw.CloudEventReader reader) throws io.cloudevents.rw.CloudEventRWException
      Convert a CloudEventReader to a CloudEvent.
      Parameters:
      reader - the reader where to read the message from
      Returns:
      the reader implementation
      Throws:
      io.cloudevents.rw.CloudEventRWException
    • toEvent

      public static io.cloudevents.CloudEvent toEvent(io.cloudevents.rw.CloudEventReader reader, io.cloudevents.rw.CloudEventDataMapper<?> mapper) throws io.cloudevents.rw.CloudEventRWException
      Convert a CloudEventReader to a CloudEvent mapping the data with the provided mapper.
      Parameters:
      reader - the reader where to read the message from
      mapper - the mapper to use when reading the data
      Returns:
      the reader implementation
      Throws:
      io.cloudevents.rw.CloudEventRWException
    • mapData

      @Nullable public static <R extends io.cloudevents.CloudEventData> R mapData(io.cloudevents.CloudEvent event, io.cloudevents.rw.CloudEventDataMapper<R> mapper)
      Get the data contained in event and map it using the provided mapper.
      Type Parameters:
      R - the returned CloudEventData implementation from the provided mapper
      Parameters:
      event - the event eventually containing the data
      mapper - the mapper to use to map the data
      Returns:
      the data contained in event and mapped with mapper, if any, otherwise null