Class ByteStreamWriterImpl

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    public class ByteStreamWriterImpl
    extends ByteStreamWriter
    • 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 to ByteStreamWriter.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 to ByteStreamWriter.write(byte[], int, int) Writes the provided data to the segment.
      • Methods inherited from class java.io.OutputStream

        nullOutputStream, write
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • write

        public void write​(int b)
                   throws java.io.IOException
        Specified by:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(java.nio.ByteBuffer src)
                   throws java.io.IOException
        Description copied from class: ByteStreamWriter
        Similar to ByteStreamWriter.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 class ByteStreamWriter
        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 class ByteStreamWriter
        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 interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class ByteStreamWriter
        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 interface java.io.Flushable
        Specified by:
        flush in class ByteStreamWriter
        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 to ByteStreamWriter.close() but also seals it so that no future writes can ever be made.
        Specified by:
        closeAndSeal in class ByteStreamWriter
        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 to 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.
        Specified by:
        fetchTailOffset in class ByteStreamWriter
        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 class ByteStreamWriter
        Parameters:
        offset - The truncation offset.