Package db.buffers

Interface BufferFile

All Known Subinterfaces:
ManagedBufferFile
All Known Implementing Classes:
BufferFileAdapter, LocalBufferFile, LocalManagedBufferFile, ManagedBufferFileAdapter

public interface BufferFile
BufferFile facilitates read/write access to buffer oriented file. Access to related resources, such as parameters and change data, is also facilitated.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deletes all parameters
    void
    Close the buffer file.
    boolean
    Delete this buffer file if writable.
    void
    Dispose of this buffer file object.
    get(DataBuffer buf, int index)
    Get the specified buffer.
    int
    Return the actual size of a user data buffer.
    int[]
    Returns the list of free indexes sorted by value.
    int
    Returns the number of allocated buffer indexes.
    int
    Get a the stored value for a named parameter.
    Returns a list of all parameter names.
    boolean
    Returns true if this file may not be modified via the buffer put method.
    void
    put(DataBuffer buf, int index)
    Store a data buffer at the specified block index.
    void
    setFreeIndexes(int[] indexes)
    Sets the list of free buffer indexes.
    void
    setParameter(String name, int value)
    Set the integer value for a named parameter.
    boolean
    If file is open read-write, the modified contents are flushed and the file re-opened as read-only.
  • Method Details

    • isReadOnly

      boolean isReadOnly() throws IOException
      Returns true if this file may not be modified via the buffer put method. A read-only file may be considered "updateable" if the canSave method returns true. The term "updateable" means that a Save file can be obtained via the getSaveFile method.
      Throws:
      IOException - if an I/O error occurs
    • setReadOnly

      boolean setReadOnly() throws IOException
      If file is open read-write, the modified contents are flushed and the file re-opened as read-only. This is also used to commit a new version if the file had been modified for update.
      Returns:
      true if successfully transitioned from read-write to read-only
      Throws:
      IOException - if an I/O error occurs
    • getParameter

      int getParameter(String name) throws NoSuchElementException, IOException
      Get a the stored value for a named parameter.
      Parameters:
      name - parameter name
      Returns:
      integer value
      Throws:
      NoSuchElementException - thrown if parameter not found
      IOException
    • setParameter

      void setParameter(String name, int value) throws IOException
      Set the integer value for a named parameter.
      Parameters:
      name - parameter name
      value - parameter value
      Throws:
      IOException
    • clearParameters

      void clearParameters() throws IOException
      Deletes all parameters
      Throws:
      IOException
    • getParameterNames

      String[] getParameterNames() throws IOException
      Returns a list of all parameter names.
      Throws:
      IOException
    • getBufferSize

      int getBufferSize() throws IOException
      Return the actual size of a user data buffer. This value should be used when constructing DataBuffer objects.
      Returns:
      DataBuffer data size as a number of bytes
      Throws:
      IOException - if an I/O error occurs
    • getIndexCount

      int getIndexCount() throws IOException
      Returns the number of allocated buffer indexes. When a new buffer is allocated, and the file size grows, the buffer will remain allocated although it may be added to the list of free-indexes. A file will never shrink in size due to this permanent allocation.
      Throws:
      IOException
    • getFreeIndexes

      int[] getFreeIndexes() throws IOException
      Returns the list of free indexes sorted by value. The management of the free-index-list is implementation specific.
      Throws:
      IOException
    • setFreeIndexes

      void setFreeIndexes(int[] indexes) throws IOException
      Sets the list of free buffer indexes. The management of the free-index-list is implementation specific.
      Parameters:
      indexes -
      Throws:
      IOException
    • close

      void close() throws IOException
      Close the buffer file. If the file was open for write access, all buffers are flushed and the file header updated. Once closed, this object is immediately disposed and may no longer be used.
      Throws:
      IOException - if an I/O error occurs
    • delete

      boolean delete() throws IOException
      Delete this buffer file if writable. Once deleted, this object is immediately disposed and may no longer be used.
      Returns:
      true if deleted, false if the file is read-only
      Throws:
      IOException - if an I/O error occurs.
    • dispose

      void dispose()
      Dispose of this buffer file object. If file is not readOnly and has not been closed, an attempt will be made to delete the associated file(s). Once disposed, it may no longer be used.
    • get

      DataBuffer get(DataBuffer buf, int index) throws IOException
      Get the specified buffer. DataBuffer data and flags are read from the file at index and stored within the supplied DataBuffer object. If the read buffer is empty, the DataBuffer's data field will remain unchanged (which could be null).
      Parameters:
      buf - a buffer whose data array will be filled-in or replaced.
      index - index of buffer to be read. First user buffer is at index 0.
      Throws:
      EOFException - if the requested buffer index is greater than the number of available buffers of the end-of-file was encountered while reading the buffer.
      IOException - if an I/O error occurs
    • put

      void put(DataBuffer buf, int index) throws IOException
      Store a data buffer at the specified block index.
      Parameters:
      buf - data buffer
      index - block index
      Throws:
      IOException - thrown if an IO error occurs