Class FileBlockDeviceDriver

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getBlockSize()
      Returns the block size of the block device.
      void init()
      Initializes the block device for further use.
      void read​(long deviceOffset, java.nio.ByteBuffer buffer)
      Reads from the block device at a certain offset into the given buffer.
      void write​(long deviceOffset, java.nio.ByteBuffer buffer)
      Writes to the block device at a certain offset from the given buffer.
      • Methods inherited from class java.lang.Object

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

      • FileBlockDeviceDriver

        public FileBlockDeviceDriver​(java.io.File file,
                                     int blockSize,
                                     int byteOffset)
                              throws java.io.FileNotFoundException
        Throws:
        java.io.FileNotFoundException
      • FileBlockDeviceDriver

        public FileBlockDeviceDriver​(java.io.File file,
                                     int byteOffset)
                              throws java.io.FileNotFoundException
        Throws:
        java.io.FileNotFoundException
      • FileBlockDeviceDriver

        public FileBlockDeviceDriver​(java.io.File file)
                              throws java.io.FileNotFoundException
        Throws:
        java.io.FileNotFoundException
      • FileBlockDeviceDriver

        public FileBlockDeviceDriver​(java.net.URL url,
                                     int blockSize,
                                     int byteOffset)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • FileBlockDeviceDriver

        public FileBlockDeviceDriver​(java.net.URL url,
                                     int byteOffset)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • FileBlockDeviceDriver

        public FileBlockDeviceDriver​(java.net.URL url)
                              throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • init

        public void init()
                  throws java.io.IOException
        Description copied from interface: BlockDeviceDriver
        Initializes the block device for further use. This method should be called before doing anything else on the block device.
        Specified by:
        init in interface BlockDeviceDriver
        Throws:
        java.io.IOException - If initializing fails
      • read

        public void read​(long deviceOffset,
                         java.nio.ByteBuffer buffer)
                  throws java.io.IOException
        Description copied from interface: BlockDeviceDriver
        Reads from the block device at a certain offset into the given buffer. The amount of bytes to be read are determined by Buffer.remaining().

        The deviceOffset can either be the amount of bytes or a logical block addressing using the block size. To get the bytes in the last case you have to multiply the lba with the block size (offset * BlockDeviceDriver.getBlockSize()).

        Specified by:
        read in interface BlockDeviceDriver
        Parameters:
        deviceOffset - The offset where the reading should begin.
        buffer - The buffer where the data should be read into.
        Throws:
        java.io.IOException - If reading fails.
      • write

        public void write​(long deviceOffset,
                          java.nio.ByteBuffer buffer)
                   throws java.io.IOException
        Description copied from interface: BlockDeviceDriver
        Writes to the block device at a certain offset from the given buffer. The amount of bytes to be written are determined by Buffer.remaining().

        The deviceOffset can either be the amount of bytes or a logical block addressing using the block size. To get the bytes in the last case you have to multiply the lba with the block size (offset * BlockDeviceDriver.getBlockSize()).

        Specified by:
        write in interface BlockDeviceDriver
        Parameters:
        deviceOffset - The offset where the writing should begin.
        buffer - The buffer with the data to be transferred.
        Throws:
        java.io.IOException - If writing fails.
      • getBlockSize

        public int getBlockSize()
        Description copied from interface: BlockDeviceDriver
        Returns the block size of the block device. Every block device can only read and store bytes in a specific block with a certain size.

        That means that it is only possible to read or write hole blocks!

        Specified by:
        getBlockSize in interface BlockDeviceDriver
        Returns:
        The block size in bytes, mostly 512 bytes.