Class ByteStreamWriterImpl
- java.lang.Object
-
- java.io.OutputStream
-
- io.pravega.client.byteStream.ByteStreamWriter
-
- io.pravega.client.byteStream.impl.ByteStreamWriterImpl
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class ByteStreamWriterImpl extends ByteStreamWriter
-
-
Constructor Summary
Constructors Constructor Description ByteStreamWriterImpl(@NonNull SegmentOutputStream out, @NonNull SegmentMetadataClient meta)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Flushes the buffer and closes the writer.void
closeAndSeal()
Closes the writer similar toByteStreamWriter.close()
but also seals it so that no future writes can ever be made.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.void
flush()
Blocks until all data written has been durably persisted.void
truncateDataBefore(long offset)
This makes a synchronous RPC call to the server to truncate the segment at the provided offset.void
write(byte[] b, int off, int len)
Writes the provided data to the segment.void
write(int b)
void
write(java.nio.ByteBuffer src)
Similar toByteStreamWriter.write(byte[], int, int)
Writes the provided data to the segment.
-
-
-
Constructor Detail
-
ByteStreamWriterImpl
@ConstructorProperties({"out","meta"}) public ByteStreamWriterImpl(@NonNull @NonNull SegmentOutputStream out, @NonNull @NonNull SegmentMetadataClient meta)
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOException
- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(java.nio.ByteBuffer src) throws java.io.IOException
Description copied from class:ByteStreamWriter
Similar toByteStreamWriter.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.- Specified by:
write
in classByteStreamWriter
- Parameters:
src
- The bytes to write.- Throws:
java.io.IOException
- If for any reason an error occurs writing the data, including if the stream is sealed.
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
Description copied from class:ByteStreamWriter
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.- Specified by:
write
in classByteStreamWriter
- Throws:
java.io.IOException
- See Also:
OutputStream.write(byte[], int, int)
-
close
public void close() throws java.io.IOException
Description copied from class:ByteStreamWriter
Flushes the buffer and closes the writer. If there is data to flush, this is a blocking method.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in classByteStreamWriter
- Throws:
java.io.IOException
- See Also:
OutputStream.close()
-
flush
public void flush() throws java.io.IOException
Description copied from class:ByteStreamWriter
Blocks until all data written has been durably persisted.- Specified by:
flush
in interfacejava.io.Flushable
- Specified by:
flush
in classByteStreamWriter
- Throws:
java.io.IOException
- If for any reason the flush fails including if the stream is sealed.- See Also:
OutputStream.flush()
-
closeAndSeal
public void closeAndSeal() throws java.io.IOException
Description copied from class:ByteStreamWriter
Closes the writer similar toByteStreamWriter.close()
but also seals it so that no future writes can ever be made.- Specified by:
closeAndSeal
in classByteStreamWriter
- Throws:
java.io.IOException
- If for any reason the flush fails including if the stream is sealed.
-
fetchTailOffset
public long fetchTailOffset()
Description copied from class:ByteStreamWriter
This makes a synchronous RPC call to the server to obtain the total number of bytes written to the segment in its history. This is the sum total of the bytes written in all calls toOutputStream.write(byte[])
that have been flushed. It does not include data that was passed toOutputStream.write(byte[])
but which has not yet been persisted.- Specified by:
fetchTailOffset
in classByteStreamWriter
- Returns:
- The tail offset
-
truncateDataBefore
public void truncateDataBefore(long offset)
Description copied from class:ByteStreamWriter
This makes a synchronous RPC call to the server to truncate the segment at the provided offset.- Specified by:
truncateDataBefore
in classByteStreamWriter
- Parameters:
offset
- The truncation offset.
-
-