public class FileSystemBufferedReaderDomainEventStream extends Object implements DomainEventStream, Closeable
InputStream
.
Directly upcasts the events after reading using an UpcasterChain
.Constructor and Description |
---|
FileSystemBufferedReaderDomainEventStream(InputStream inputStream,
Serializer serializer,
UpcasterChain upcasterChain)
Initialize a BufferedReaderDomainEventStream using the given
inputStream and
serializer . |
Modifier and Type | Method and Description |
---|---|
void |
close() |
boolean |
hasNext()
Returns
true if the stream has more events, meaning that a call to next() will not
result in an exception. |
DomainEventMessage |
next()
Returns the next events in the stream, if available.
|
DomainEventMessage |
peek()
Returns the next events in the stream, if available, without moving the pointer forward.
|
public FileSystemBufferedReaderDomainEventStream(InputStream inputStream, Serializer serializer, UpcasterChain upcasterChain)
inputStream
and
serializer
. The inputStream
must provide a serialized DomainEvent, prefixed with a
UTF-8 encoded number indicating the number of bytes to read and a number representing the sequence number of
the event. In between each number and the serialized DomainEvent, there must be at least a single whitespace
character.
Example:1234 The serialized domain event using 1234 bytes...
The reader will be closed when the last event has been read from it, or when an exception occurs while
reading or deserializing an event.inputStream
- The inputStream providing serialized DomainEventsserializer
- The serializer to deserialize the DomainEventsupcasterChain
- used to upcast events directly after being readpublic boolean hasNext()
DomainEventStream
true
if the stream has more events, meaning that a call to next()
will not
result in an exception. If a call to this method returns false
, there is no guarantee about the
result of a consecutive call to next()
hasNext
in interface DomainEventStream
true
if the stream contains more events.public DomainEventMessage next()
DomainEventStream
hasNext()
to obtain a guarantee about the
availability of any next event. Each call to next()
will forward the pointer to the next event in
the stream.
If the pointer has reached the end of the stream, the behavior of this method is undefined. It could either
return null
, or throw an exception, depending on the actual implementation. Use DomainEventStream.hasNext()
to confirm the existence of elements after the current pointer.next
in interface DomainEventStream
public DomainEventMessage peek()
DomainEventStream
DomainEventStream.next()
will return the same event as a call to peek()
. Use hasNext()
to obtain a
guarantee about the availability of any next event.
If the pointer has reached the end of the stream, the behavior of this method is undefined. It could either
return null
, or throw an exception, depending on the actual implementation. Use DomainEventStream.hasNext()
to confirm the existence of elements after the current pointer.peek
in interface DomainEventStream
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2010-2014. All Rights Reserved.