Commit ddd6a225 by aquilescanta Committed by Oliver Woodman

Fix EventSampleStream's implementation regarding FLAG_REQUIRE_FORMAT

The current FLAG_REQUIRE_FORMAT documentation states: If an end of
stream buffer would be read were the flag not set, then behavior is
unchanged.

PiperOrigin-RevId: 380781976
parent b48b618b
......@@ -100,18 +100,19 @@ import java.io.IOException;
@Override
public int readData(
FormatHolder formatHolder, DecoderInputBuffer buffer, @ReadFlags int readFlags) {
boolean noMoreEventsInStream = currentIndex == eventTimesUs.length;
if (noMoreEventsInStream && !eventStreamAppendable) {
buffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
return C.RESULT_BUFFER_READ;
}
if ((readFlags & FLAG_REQUIRE_FORMAT) != 0 || !isFormatSentDownstream) {
formatHolder.format = upstreamFormat;
isFormatSentDownstream = true;
return C.RESULT_FORMAT_READ;
}
if (currentIndex == eventTimesUs.length) {
if (!eventStreamAppendable) {
buffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
return C.RESULT_BUFFER_READ;
} else {
return C.RESULT_NOTHING_READ;
}
if (noMoreEventsInStream) {
// More events may be appended later.
return C.RESULT_NOTHING_READ;
}
int sampleIndex = currentIndex++;
byte[] serializedEvent = eventMessageEncoder.encode(eventStream.events[sampleIndex]);
......
......@@ -67,7 +67,10 @@ public final class EventSampleStreamTest {
public void readDataReturnFormatForFirstRead() {
EventStream eventStream =
new EventStream(SCHEME_ID, VALUE, TIME_SCALE, new long[0], new EventMessage[0]);
EventSampleStream sampleStream = new EventSampleStream(eventStream, FORMAT, false);
// Make the event stream appendable so that the format is read. Otherwise, the format will be
// skipped and the end of input will be read.
EventSampleStream sampleStream =
new EventSampleStream(eventStream, FORMAT, /* eventStreamAppendable= */ true);
int result = readData(sampleStream);
assertThat(result).isEqualTo(C.RESULT_FORMAT_READ);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment