org.basex.io.random
Class DataAccess

java.lang.Object
  extended by org.basex.io.random.DataAccess

public final class DataAccess
extends java.lang.Object

This class allows positional read and write access to a database file.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen

Constructor Summary
DataAccess(IOFile f)
          Constructor, initializing the file reader.
 
Method Summary
 long appendNums(int[] v)
          Appends integers to the file in compressed form.
 void close()
          Closes the data access.
 long cursor()
          Returns the current file position.
 void cursor(long p)
          Sets the disk cursor.
 void flush()
          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 length()
          Returns the file length.
 boolean more()
          Checks if more bytes can be read.
 byte read1()
          Reads a byte value.
 byte read1(long p)
          Reads a byte value from the specified position.
 int read4()
          Reads an integer value.
 int read4(long p)
          Reads an integer value from the specified position.
 long read5()
          Reads a 5-byte value.
 long read5(long p)
          Reads a 5-byte value from the specified file offset.
 byte[] readBytes(int n)
          Reads a number of bytes.
 byte[] readBytes(long p, int l)
          Reads a number of bytes from the specified offset.
 int readNum()
          Reads the next compressed number and returns it as integer.
 int readNum(long p)
          Reads a Num value from disk.
 byte[] readToken()
          Reads the next token from disk.
 byte[] readToken(long p)
          Reads a token from disk.
 void write4(int v)
          Writes an integer value to the current position.
 void write4(long p, int v)
          Writes an integer value to the specified position.
 void write5(long p, long v)
          Writes a 5-byte value to the specified position.
 void writeNum(long p, int v)
          Write a value to the file.
 void writeNums(long p, int[] v)
          Writes integers to the file in compressed form.
 void writeToken(byte[] buf, int offset, int length)
          Write a token to the file.
 void writeToken(long p, byte[] v)
          Appends a value to the file and return it's offset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataAccess

public DataAccess(IOFile f)
           throws java.io.IOException
Constructor, initializing the file reader.

Parameters:
f - the file to be read
Throws:
java.io.IOException - I/O Exception
Method Detail

flush

public void flush()
Flushes the buffered data.


close

public void close()
Closes the data access.


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 p)
Reads a byte value from the specified position.

Parameters:
p - position
Returns:
integer value

read1

public byte read1()
Reads a byte value.

Returns:
integer value

read4

public int read4(long p)
Reads an integer value from the specified position.

Parameters:
p - position
Returns:
integer value

read4

public int read4()
Reads an integer value.

Returns:
integer value

read5

public long read5(long p)
Reads a 5-byte value from the specified file offset.

Parameters:
p - position
Returns:
long value

read5

public long read5()
Reads a 5-byte value.

Returns:
long value

readNum

public int readNum(long p)
Reads a Num value from disk.

Parameters:
p - text position
Returns:
read num

readToken

public byte[] readToken(long p)
Reads a token from disk.

Parameters:
p - 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 p,
                        int l)
Reads a number of bytes from the specified offset.

Parameters:
p - position
l - length
Returns:
byte array

readBytes

public byte[] readBytes(int n)
Reads a number of bytes.

Parameters:
n - length
Returns:
byte array

cursor

public void cursor(long p)
Sets the disk cursor.

Parameters:
p - read position

readNum

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

Returns:
next integer

write5

public void write5(long p,
                   long v)
Writes a 5-byte value to the specified position.

Parameters:
p - position in the file
v - value to be written

write4

public void write4(long p,
                   int v)
Writes an integer value to the specified position.

Parameters:
p - write position
v - byte array to be appended

write4

public void write4(int v)
Writes an integer value to the current position.

Parameters:
v - value to be written

writeNum

public void writeNum(long p,
                     int v)
Write a value to the file.

Parameters:
p - write position
v - value to be written

writeNums

public void writeNums(long p,
                      int[] v)
Writes integers to the file in compressed form.

Parameters:
p - write position
v - integer values

appendNums

public long appendNums(int[] v)
Appends integers to the file in compressed form.

Parameters:
v - integer values
Returns:
the position in the file where the values have been written

writeToken

public void writeToken(long p,
                       byte[] v)
Appends a value to the file and return it's offset.

Parameters:
p - write position
v - byte array to be appended

writeToken

public void writeToken(byte[] buf,
                       int offset,
                       int length)
Write a token to the file.

Parameters:
buf - buffer containing the token
offset - offset in the buffer where the token starts
length - token length

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