Class ByteStreamReaderImpl

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.AsynchronousChannel, java.nio.channels.Channel

    public class ByteStreamReaderImpl
    extends ByteStreamReader
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()
      Returns the number of bytes that can be read without blocking.
      void close()
      Closes the reader.
      long fetchTailOffset()
      This make an RPC to the server to fetch the offset at which new bytes would be written.
      long getOffset()
      Returns the current byte offset in the segment.
      boolean isOpen()  
      java.util.concurrent.CompletableFuture<java.lang.Integer> onDataAvailable()
      Returns a future that will be completed when there is data available to be read.
      int read()
      Reads a single byte.
      int read​(byte[] b)
      This is equivalent to calling read(b, 0, b.length) Will only block if ByteStreamReader.available() is 0.
      int read​(byte[] b, int off, int len)
      If ByteStreamReader.available() is non-zero, this method will read bytes from an in-memory buffer into the provided array.
      int read​(java.nio.ByteBuffer dst)
      Similar to ByteStreamReader.read(byte[], int, int) but takes a byteBuffer.
      void seekToOffset​(long offset)
      Seeks to the provided offset (It can be anywhere in the segment).
      long skip​(long toSkip)
      This method attempts to skip forward by the provided number of bytes.
      java.lang.String toString()  
      • Methods inherited from class java.io.InputStream

        mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • isOpen

        public boolean isOpen()
      • getOffset

        public long getOffset()
        Description copied from class: ByteStreamReader
        Returns the current byte offset in the segment. This call does not block.
        Specified by:
        getOffset in class ByteStreamReader
        Returns:
        the current byte offset in the segment.
      • seekToOffset

        public void seekToOffset​(long offset)
        Description copied from class: ByteStreamReader
        Seeks to the provided offset (It can be anywhere in the segment). Future read calls will read from this offset. Future reads will proceed from this offset.
        Specified by:
        seekToOffset in class ByteStreamReader
        Parameters:
        offset - The offset to seek to.
      • close

        public void close()
        Description copied from class: ByteStreamReader
        Closes the reader. This may block on an ongoing ByteStreamReader.read() request if there is one. See InputStream.close()
        Specified by:
        close in interface java.nio.channels.AsynchronousChannel
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.nio.channels.Channel
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class ByteStreamReader
      • fetchTailOffset

        public long fetchTailOffset()
        Description copied from class: ByteStreamReader
        This make an RPC to the server to fetch the offset at which new bytes would be written. This is the same as the length of the segment (assuming no truncation). This offset can also be passed to ByteStreamReader.seekToOffset(long) to only read bytes from this point forward.
        Specified by:
        fetchTailOffset in class ByteStreamReader
        Returns:
        The tail offset.
      • read

        public int read​(java.nio.ByteBuffer dst)
                 throws java.io.IOException
        Description copied from class: ByteStreamReader
        Similar to ByteStreamReader.read(byte[], int, int) but takes a byteBuffer.
        Specified by:
        read in class ByteStreamReader
        Parameters:
        dst - the destination buffer to read into.
        Returns:
        The number of bytes copied into the provided buffer. Or -1 if the segment is sealed and there are no more bytes to read.
        Throws:
        java.io.IOException - If the stream cannot be read from for any reason including if truncation has deleted the data.
      • read

        public int read()
                 throws java.io.IOException
        Description copied from class: ByteStreamReader
        Reads a single byte. Avoid this API if possible as it is very wasteful. See InputStream.read().
        Specified by:
        read in class ByteStreamReader
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b)
                 throws java.io.IOException
        Description copied from class: ByteStreamReader
        This is equivalent to calling read(b, 0, b.length) Will only block if ByteStreamReader.available() is 0. See InputStream.read(byte[]).
        Specified by:
        read in class ByteStreamReader
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Description copied from class: ByteStreamReader
        If ByteStreamReader.available() is non-zero, this method will read bytes from an in-memory buffer into the provided array. If ByteStreamReader.available() is zero will wait for additional data to arrive and then fill the provided array. This method will only block if ByteStreamReader.available() is 0. In which case it will block until some data arrives and return that. (Which may or may not fill the provided buffer) See InputStream.read(byte[], int, int)
        Specified by:
        read in class ByteStreamReader
        Returns:
        The number of bytes copied into the provided buffer. Or -1 if the segment is sealed and there are no more bytes to read.
        Throws:
        java.io.IOException
      • skip

        public long skip​(long toSkip)
        Description copied from class: ByteStreamReader
        This method attempts to skip forward by the provided number of bytes. If it is not possible to skip forward `n` bytes (because there are less than `n` bytes remaining, it will skip as many as possible and return the number skipped. This method is not affected by truncation.
        Specified by:
        skip in class ByteStreamReader
        Parameters:
        toSkip - number of bytes to skip.
        Returns:
        number of bytes skipped.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object