Class IOStoreDataAccessor

  • All Implemented Interfaces:
    StoreDataAccessor

    class IOStoreDataAccessor
    extends java.lang.Object
    implements StoreDataAccessor
    An implementation of StoreDataAccessor that uses the standard Java IO API to access data in some underlying file in the filesystem.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.RandomAccessFile data
      The underlying RandomAccessFile containing the data.
      private java.io.File file
      The File object representing the file in the file system.
      private boolean is_open
      True if the file is open.
      private java.lang.Object lock
      A lock because access to the data is stateful.
      private long size
      The size of the data area.
    • Constructor Summary

      Constructors 
      Constructor Description
      IOStoreDataAccessor​(java.io.File file)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the underlying data area representation.
      boolean delete()
      Deletes the data area resource.
      boolean exists()
      Returns true if the resource exists.
      long getSize()
      Returns the current size of the underlying data area.
      void open​(boolean is_read_only)
      Opens the underlying data area representation.
      void read​(long position, byte[] buf, int off, int len)
      Reads a block of data from the underlying data area at the given position into the byte array at the given offset.
      void setSize​(long new_size)
      Sets the size of the underlying data area to the given size.
      void synch()
      Synchronizes the data area by forcing any data out of the OS buffers onto the disk.
      void write​(long position, byte[] buf, int off, int len)
      Writes a block of data to the underlying data area from the byte array at the given offset.
      • Methods inherited from class java.lang.Object

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

      • lock

        private java.lang.Object lock
        A lock because access to the data is stateful.
      • file

        private java.io.File file
        The File object representing the file in the file system.
      • data

        private java.io.RandomAccessFile data
        The underlying RandomAccessFile containing the data.
      • size

        private long size
        The size of the data area.
      • is_open

        private boolean is_open
        True if the file is open.
    • Constructor Detail

      • IOStoreDataAccessor

        IOStoreDataAccessor​(java.io.File file)
        Constructor.
    • Method Detail

      • open

        public void open​(boolean is_read_only)
                  throws java.io.IOException
        Description copied from interface: StoreDataAccessor
        Opens the underlying data area representation. If the resource doesn't exist then it is created and the size is set to 0.
        Specified by:
        open in interface StoreDataAccessor
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Description copied from interface: StoreDataAccessor
        Closes the underlying data area representation.
        Specified by:
        close in interface StoreDataAccessor
        Throws:
        java.io.IOException
      • delete

        public boolean delete()
        Description copied from interface: StoreDataAccessor
        Deletes the data area resource. Returns true if the delete was successful.
        Specified by:
        delete in interface StoreDataAccessor
      • read

        public void read​(long position,
                         byte[] buf,
                         int off,
                         int len)
                  throws java.io.IOException
        Description copied from interface: StoreDataAccessor
        Reads a block of data from the underlying data area at the given position into the byte array at the given offset.
        Specified by:
        read in interface StoreDataAccessor
        Throws:
        java.io.IOException
      • write

        public void write​(long position,
                          byte[] buf,
                          int off,
                          int len)
                   throws java.io.IOException
        Description copied from interface: StoreDataAccessor
        Writes a block of data to the underlying data area from the byte array at the given offset.
        Specified by:
        write in interface StoreDataAccessor
        Throws:
        java.io.IOException
      • setSize

        public void setSize​(long new_size)
                     throws java.io.IOException
        Description copied from interface: StoreDataAccessor
        Sets the size of the underlying data area to the given size. If the size of the data area is increased, the content between the old size and the new size is implementation defined.
        Specified by:
        setSize in interface StoreDataAccessor
        Throws:
        java.io.IOException
      • getSize

        public long getSize()
                     throws java.io.IOException
        Description copied from interface: StoreDataAccessor
        Returns the current size of the underlying data area.
        Specified by:
        getSize in interface StoreDataAccessor
        Throws:
        java.io.IOException
      • synch

        public void synch()
                   throws java.io.IOException
        Description copied from interface: StoreDataAccessor
        Synchronizes the data area by forcing any data out of the OS buffers onto the disk.
        Specified by:
        synch in interface StoreDataAccessor
        Throws:
        java.io.IOException