Class LocalFileBlockReader

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

    @NotThreadSafe
    public class LocalFileBlockReader
    extends BlockReader
    This class provides read access to a block data file locally stored in managed storage.
    • Constructor Summary

      Constructors 
      Constructor Description
      LocalFileBlockReader​(java.lang.String path)
      Constructs a Block reader given the file path of the block.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void decreaseUsageCount()
      decrease the file reader usage count.
      java.nio.channels.ReadableByteChannel getChannel()
      Returns a readable byte channel of the block.
      java.lang.String getFilePath()  
      long getLength()
      Gets the length of the block in bytes.
      java.lang.String getLocation()  
      int getUsageCount()  
      void increaseUsageCount()
      increase the file reader usage count.
      boolean isClosed()  
      java.nio.ByteBuffer read​(long offset, long length)
      Reads data from the block.
      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

      • LocalFileBlockReader

        public LocalFileBlockReader​(java.lang.String path)
                             throws java.io.IOException
        Constructs a Block reader given the file path of the block.
        Parameters:
        path - file path of the block
        Throws:
        java.io.IOException
    • Method Detail

      • 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
      • 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
      • increaseUsageCount

        public void increaseUsageCount()
        increase the file reader usage count.
      • decreaseUsageCount

        public void decreaseUsageCount()
        decrease the file reader usage count.
      • getUsageCount

        public int getUsageCount()
        Returns:
        the file reader usage count
      • getFilePath

        public java.lang.String getFilePath()
        Returns:
        the file path
      • 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
      • 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
      • 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
      • 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