Package com.styra.opa.openapi.utils
Class EventStream<T>
- java.lang.Object
-
- com.styra.opa.openapi.utils.EventStream<T>
-
- Type Parameters:
T
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public final class EventStream<T> extends java.lang.Object implements java.lang.AutoCloseable
-
-
Constructor Summary
Constructors Constructor Description EventStream(java.io.InputStream in, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, com.fasterxml.jackson.databind.ObjectMapper mapper)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
java.util.Optional<T>
next()
Returns the next message.java.util.stream.Stream<T>
stream()
Returns aStream
of events.java.util.List<T>
toList()
Reads all events and returns them as aList
.
-
-
-
Constructor Detail
-
EventStream
public EventStream(java.io.InputStream in, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, com.fasterxml.jackson.databind.ObjectMapper mapper)
-
-
Method Detail
-
next
public java.util.Optional<T> next() throws java.io.IOException
Returns the next message. If another message does not exist returnsOptional.empty()
.- Returns:
- the next message or
Optional.empty()
if no more messages - Throws:
java.io.IOException
-
toList
public java.util.List<T> toList()
Reads all events and returns them as aList
. This method callsclose()
.- Returns:
- list of events
-
stream
public java.util.stream.Stream<T> stream()
Returns aStream
of events. Must be closed after use!- Returns:
- streamed events
-
close
public void close() throws java.lang.Exception
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.lang.Exception
-
-