Class DelegatingBlockReader

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

    public class DelegatingBlockReader
    extends BlockReader
    An delegating reader class.
    • Constructor Summary

      Constructors 
      Constructor Description
      DelegatingBlockReader​(BlockReader blockReader, java.io.Closeable closeable)
      Default constructor for the abstract reader implementations.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      java.nio.channels.ReadableByteChannel getChannel()
      Returns a readable byte channel of the block.
      BlockReader getDelegate()  
      long getLength()
      Gets the length of the block in bytes.
      java.lang.String getLocation()  
      boolean isClosed()  
      java.nio.ByteBuffer read​(long offset, long length)
      Reads data from the block.
      java.lang.String toString()  
      int transferTo​(io.netty.buffer.ByteBuf buf)
      Transfers data (up to buf.writableBytes()) from this reader to the buffer.
      • Methods inherited from class java.lang.Object

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

      • DelegatingBlockReader

        public DelegatingBlockReader​(BlockReader blockReader,
                                     java.io.Closeable closeable)
        Default constructor for the abstract reader implementations.
        Parameters:
        blockReader - block reader
        closeable - closer
    • Method Detail

      • getDelegate

        public BlockReader getDelegate()
        Returns:
        the delegate
      • read

        public java.nio.ByteBuffer read​(long offset,
                                        long length)
                                 throws java.io.IOException
        Description copied from class: BlockReader
        Reads data from the block.

        Implementation Note

        Since this method needs to allocate a buffer inside its implementation, it must not choose a ByteBuffer that needs any kind of explicit de-allocation, e.g. a pooled buffer, because the caller has no means of knowing how and when to properly deallocate the returned buffer.
        If explicit de-allocation is desired, use an externally allocated ByteBuf and call BlockReader.transferTo(ByteBuf) instead. It is then the caller's responsibility to de-allocate the buffer.
        Specified by:
        read in class BlockReader
        Parameters:
        offset - the offset from starting of the block file in bytes
        length - the length of data to read in bytes. If offset + length exceeds the block size, the part of data from offset to the end of block is returned.
        Returns:
        ByteBuffer the data that was read, empty buffer if offset is at the end of block
        Throws:
        java.io.IOException
      • getLength

        public long getLength()
        Description copied from class: BlockReader
        Gets the length of the block in bytes.
        Specified by:
        getLength in class BlockReader
        Returns:
        the length of the block in bytes
      • getChannel

        public java.nio.channels.ReadableByteChannel getChannel()
        Description copied from class: BlockReader
        Returns a readable byte channel of the block.
        Specified by:
        getChannel in class BlockReader
        Returns:
        channel
      • transferTo

        public int transferTo​(io.netty.buffer.ByteBuf buf)
                       throws java.io.IOException
        Description copied from class: BlockReader
        Transfers data (up to buf.writableBytes()) from this reader to the buffer.
        Specified by:
        transferTo in class BlockReader
        Parameters:
        buf - the byte buffer
        Returns:
        the number of bytes transferred, -1 if the end of the block is reached
        Throws:
        java.io.IOException
      • isClosed

        public boolean isClosed()
        Specified by:
        isClosed in class BlockReader
        Returns:
        true if this reader is closed
      • getLocation

        public java.lang.String getLocation()
        Specified by:
        getLocation in class BlockReader
        Returns:
        an informational string of the location the reader is reading from
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class BlockClient
        Throws:
        java.io.IOException