@ThreadSafe
public class StreamBuffer
extends java.lang.Object
InputStream
for reading, reading blocks until data becomes available or the buffer is closed.
To avoid in-memory data growing excessively, this buffer stores a single "chunk" at the time. Only after a chunk is consumed, a new one can be appended.
Constructor and Description |
---|
StreamBuffer()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
closeForCompleted()
Close this buffer because all expected data has been written
Reading will return the end of stream marker after all data has been consumed.
|
void |
closeForError(java.lang.Throwable t)
Close this buffer before all data is written due to an error.
|
java.io.InputStream |
getInputStream()
Obtain the input stream to read this data.
|
void |
write(com.google.protobuf.ByteString data)
Append a chunk of data for consumption.
|
public void closeForError(java.lang.Throwable t)
t
- the cause for the buffer to be closed.public void closeForCompleted()
public void write(com.google.protobuf.ByteString data)
data
- the data to write into the bufferjava.lang.IllegalStateException
- if writing is attempted after the buffer has been closedpublic java.io.InputStream getInputStream()
java.lang.IllegalStateException
- if invoked multiple times