Class DataAccess

java.lang.Object
org.basex.io.random.DataAccess
All Implemented Interfaces:
Closeable, AutoCloseable

public final class DataAccess extends Object implements Closeable
This class allows positional read and write access to a database file.
Author:
BaseX Team 2005-21, BSD License, Christian Gruen
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor, initializing the file reader.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    long
    Returns the current file position.
    void
    cursor(long pos)
    Sets the disk cursor.
    void
    Flushes the buffered data.
    long
    free(long pos, int size)
    Returns the offset to a free slot for writing an entry with the specified length.
    long
    Returns the file length.
    boolean
    Checks if more bytes can be read.
    byte
    Reads a byte value.
    byte
    read1(long pos)
    Reads a byte value from the specified position.
    int
    Reads an integer value.
    int
    read4(long pos)
    Reads an integer value from the specified position.
    long
    Reads a 5-byte value.
    long
    read5(long pos)
    Reads a 5-byte value from the specified file offset.
    byte[]
    readBytes(int len)
    Reads a number of bytes.
    byte[]
    readBytes(long pos, int len)
    Reads a number of bytes from the specified offset.
    int
    Reads the next compressed number and returns it as integer.
    int
    readNum(long pos)
    Reads a Num value from disk.
    byte[]
    Reads the next token from disk.
    byte[]
    readToken(long pos)
    Reads a token from disk.
    void
    write4(int value)
    Writes an integer value to the file.
    void
    write4(long pos, int value)
    Writes an integer value to the specified position.
    void
    write5(long pos, long value)
    Writes a 5-byte value to the specified position.
    void
    writeBytes(byte[] data, int offset, int len)
    Writes a byte array to the file.
    void
    writeNum(int value)
    Writes a number to the file.
    void
    writeToken(long pos, byte[] value)
    Writes a token to the file.

    Methods inherited from class java.lang.Object

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

    • DataAccess

      public DataAccess(IOFile file) throws IOException
      Constructor, initializing the file reader.
      Parameters:
      file - the file to be read
      Throws:
      IOException - I/O Exception
  • Method Details

    • flush

      public void flush()
      Flushes the buffered data.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • cursor

      public long cursor()
      Returns the current file position.
      Returns:
      position in the file
    • length

      public long length()
      Returns the file length.
      Returns:
      file length
    • more

      public boolean more()
      Checks if more bytes can be read.
      Returns:
      result of check
    • read1

      public byte read1(long pos)
      Reads a byte value from the specified position.
      Parameters:
      pos - position
      Returns:
      integer value
    • read1

      public byte read1()
      Reads a byte value.
      Returns:
      integer value
    • read4

      public int read4(long pos)
      Reads an integer value from the specified position.
      Parameters:
      pos - position
      Returns:
      integer value
    • read4

      public int read4()
      Reads an integer value.
      Returns:
      integer value
    • read5

      public long read5(long pos)
      Reads a 5-byte value from the specified file offset.
      Parameters:
      pos - position
      Returns:
      long value
    • read5

      public long read5()
      Reads a 5-byte value.
      Returns:
      long value
    • readNum

      public int readNum(long pos)
      Reads a Num value from disk.
      Parameters:
      pos - text position
      Returns:
      read num
    • readToken

      public byte[] readToken(long pos)
      Reads a token from disk.
      Parameters:
      pos - text position
      Returns:
      text as byte array
    • readToken

      public byte[] readToken()
      Reads the next token from disk.
      Returns:
      text as byte array
    • readBytes

      public byte[] readBytes(long pos, int len)
      Reads a number of bytes from the specified offset.
      Parameters:
      pos - position
      len - length
      Returns:
      byte array
    • readBytes

      public byte[] readBytes(int len)
      Reads a number of bytes.
      Parameters:
      len - length
      Returns:
      byte array
    • cursor

      public void cursor(long pos)
      Sets the disk cursor.
      Parameters:
      pos - read position
    • readNum

      public int readNum()
      Reads the next compressed number and returns it as integer.
      Returns:
      next integer
    • write5

      public void write5(long pos, long value)
      Writes a 5-byte value to the specified position.
      Parameters:
      pos - position in the file
      value - value to be written
    • write4

      public void write4(long pos, int value)
      Writes an integer value to the specified position.
      Parameters:
      pos - write position
      value - byte array to be appended
    • write4

      public void write4(int value)
      Writes an integer value to the file.
      Parameters:
      value - value to be written
    • writeNum

      public void writeNum(int value)
      Writes a number to the file.
      Parameters:
      value - value to be written
    • writeBytes

      public void writeBytes(byte[] data, int offset, int len)
      Writes a byte array to the file.
      Parameters:
      data - data containing the bytes to be written
      offset - offset of first byte
      len - number of bytes to be written
    • writeToken

      public void writeToken(long pos, byte[] value)
      Writes a token to the file.
      Parameters:
      pos - write position
      value - value to be written
    • free

      public long free(long pos, int size)
      Returns the offset to a free slot for writing an entry with the specified length. Fills the original space with 0xFF to facilitate future write operations.
      Parameters:
      pos - original offset
      size - size of new text entry
      Returns:
      new offset to store text