public abstract class ByteStreamWriter
extends java.io.OutputStream
EventStreamWriter
or RevisionedStreamClient
the data written
cannot be split apart when read. As such, any bytes written by this API can ONLY be read using
ByteStreamReader
. Similarly, unless some sort of framing is added it is probably an error
to have multiple ByteStreamWriters write to the same segment as this will result in interleaved
data.
The methods on this class are non-blocking unless otherwise specified. As such data passed to a
OutputStream.write(byte[])
call cannot be assumed to be persisted until a flush has been called.
It is safe to invoke methods on this class from multiple threads but doing so will not result in
an increase in performance.Constructor and Description |
---|
ByteStreamWriter() |
Modifier and Type | Method and Description |
---|---|
abstract void |
close()
Flushes the buffer and closes the writer.
|
abstract void |
closeAndSeal()
Closes the writer similar to
close() but also seals it so that no future writes can
ever be made. |
abstract long |
fetchTailOffset()
This makes a synchronous RPC call to the server to obtain the total number of bytes written
to the segment in its history.
|
abstract void |
flush()
Blocks until all data written has been durably persisted.
|
abstract void |
write(byte[] b,
int off,
int len)
Writes the provided data to the segment.
|
abstract void |
write(java.nio.ByteBuffer src)
Similar to
write(byte[], int, int)
Writes the provided data to the segment. |
public abstract void write(java.nio.ByteBuffer src) throws java.io.IOException
write(byte[], int, int)
Writes the provided data to the segment. The data is buffered internally to avoid blocking.
As such it cannot be assumed to be durably stored until a flush completes.
It is intended that this method not block, but it may in the event that the server becomes
disconnected for sufficiently long or is sufficiently slow that that backlog of data to be
written becomes a memory issue.src
- The bytes to write.java.io.IOException
- If for any reason an error occurs writing the data, including if the
stream is sealed.public abstract void write(byte[] b, int off, int len) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
OutputStream.write(byte[], int, int)
public abstract void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStream
java.io.IOException
OutputStream.close()
public abstract void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class java.io.OutputStream
java.io.IOException
- If for any reason the flush fails including if the stream is sealed.OutputStream.flush()
public abstract void closeAndSeal() throws java.io.IOException
close()
but also seals it so that no future writes can
ever be made.java.io.IOException
- If for any reason the flush fails including if the stream is sealed.public abstract long fetchTailOffset()
OutputStream.write(byte[])
that have been flushed. It does not include data that was passed to
OutputStream.write(byte[])
but which has not yet been persisted.