Package org.basex.io.random
Class DataAccess
java.lang.Object
org.basex.io.random.DataAccess
- All Implemented Interfaces:
Closeable,AutoCloseable
This class allows positional read and write access to a database file.
- Author:
- BaseX Team 2005-21, BSD License, Christian Gruen
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()longcursor()Returns the current file position.voidcursor(long pos) Sets the disk cursor.voidflush()Flushes the buffered data.longfree(long pos, int size) Returns the offset to a free slot for writing an entry with the specified length.longlength()Returns the file length.booleanmore()Checks if more bytes can be read.byteread1()Reads a byte value.byteread1(long pos) Reads a byte value from the specified position.intread4()Reads an integer value.intread4(long pos) Reads an integer value from the specified position.longread5()Reads a 5-byte value.longread5(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.intreadNum()Reads the next compressed number and returns it as integer.intreadNum(long pos) Reads aNumvalue from disk.byte[]Reads the next token from disk.byte[]readToken(long pos) Reads a token from disk.voidwrite4(int value) Writes an integer value to the file.voidwrite4(long pos, int value) Writes an integer value to the specified position.voidwrite5(long pos, long value) Writes a 5-byte value to the specified position.voidwriteBytes(byte[] data, int offset, int len) Writes a byte array to the file.voidwriteNum(int value) Writes a number to the file.voidwriteToken(long pos, byte[] value) Writes a token to the file.
-
Constructor Details
-
DataAccess
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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
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 aNumvalue 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- positionlen- 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 filevalue- value to be written
-
write4
public void write4(long pos, int value) Writes an integer value to the specified position.- Parameters:
pos- write positionvalue- 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 writtenoffset- offset of first bytelen- number of bytes to be written
-
writeToken
public void writeToken(long pos, byte[] value) Writes a token to the file.- Parameters:
pos- write positionvalue- 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 offsetsize- size of new text entry- Returns:
- new offset to store text
-