Class EventStream<T>

java.lang.Object
com.styra.opa.openapi.utils.EventStream<T>
Type Parameters:
T -
All Implemented Interfaces:
AutoCloseable

public final class EventStream<T> extends Object implements AutoCloseable
  • Constructor Details

    • EventStream

      public EventStream(InputStream in, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, com.fasterxml.jackson.databind.ObjectMapper mapper, Optional<String> terminalMessage)
  • Method Details

    • next

      public Optional<T> next() throws IOException
      Returns the next message. If another message does not exist returns Optional.empty().
      Returns:
      the next message or Optional.empty() if no more messages
      Throws:
      IOException
    • toList

      public List<T> toList()
      Reads all events and returns them as a List. This method calls close().
      Returns:
      list of events
    • stream

      public Stream<T> stream()
      Returns a Stream of events. Must be closed after use!
      Returns:
      streamed events
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception