org.basex.io
Class DataAccess

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

public final class DataAccess
extends java.lang.Object

This class allows positional read access.

Author:
Workgroup DBIS, University of Konstanz 2005-07, ISC License, Christian Gruen

Constructor Summary
DataAccess(java.io.File f)
          Constructor, initializing the file reader.
DataAccess(java.lang.String db, java.lang.String fn)
          Constructor, initializing the file reader.
 
Method Summary
 void close()
          Closes the data access.
 void cursor(long p)
          Sets the disk cursor.
 int firstID(int p)
          Returns the first id of an index.
 void flush()
          Flushes the buffered data.
 long length()
          Returns file length.
 boolean more()
          Checks if more bytes can be read.
 void next(int b)
          Writes the next byte.
 long pos()
          Returns the input position.
 int read()
          Reads the next byte.
 int read4(long p)
          Reads an integer value from the specified position.
 long read5(long p)
          Reads a five-byte value from the specified position.
 byte[] readBytes(long p)
          Reads a text from disk.
 byte[] readBytes(long from, long to)
          Reads a number of bytes in range from -> to and returns them as array.
 int readInt(long p)
          Reads an integer value from the specified position.
 int[] readInts(long from, long to)
          Reads a number of int values in range from -> to and returns them as array.
 int readNum(long p)
          Reads a Num value from disk.
 void writeBytes(byte[] v)
          Append a value to the file and return it's offset.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataAccess

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

Parameters:
f - the file to be read
Throws:
java.io.IOException - IO Exception

DataAccess

public DataAccess(java.lang.String db,
                  java.lang.String fn)
           throws java.io.IOException
Constructor, initializing the file reader.

Parameters:
db - name of the database
fn - the file to be read
Throws:
java.io.IOException - IO Exception
Method Detail

close

public void close()
           throws java.io.IOException
Closes the data access.

Throws:
java.io.IOException - in case of write errors

cursor

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

Parameters:
p - read position

firstID

public int firstID(int p)
Returns the first id of an index.

Parameters:
p - position
Returns:
id

flush

public void flush()
Flushes the buffered data.


length

public long length()
Returns file length.

Returns:
file length

more

public boolean more()
Checks if more bytes can be read.

Returns:
result of check

next

public void next(int b)
Writes the next byte.

Parameters:
b - byte to be written

pos

public long pos()
Returns the input position.

Returns:
position

read

public int read()
Reads the next byte.

Returns:
next byte

read4

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

Parameters:
p - position
Returns:
integer value

read5

public long read5(long p)
Reads a five-byte value from the specified position.

Parameters:
p - position
Returns:
integer value

readBytes

public byte[] readBytes(long p)
Reads a text from disk.

Parameters:
p - text position
Returns:
text as byte array

readBytes

public byte[] readBytes(long from,
                        long to)
Reads a number of bytes in range from -> to and returns them as array.

Parameters:
from - starting position for reading
to - ending position for reading
Returns:
byte array

readInt

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

Parameters:
p - position
Returns:
integer value

readInts

public int[] readInts(long from,
                      long to)
Reads a number of int values in range from -> to and returns them as array.

Parameters:
from - starting position for reading
to - ending position for reading
Returns:
int array

readNum

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

Parameters:
p - text position
Returns:
read num

writeBytes

public void writeBytes(byte[] v)
Append a value to the file and return it's offset. MAY but currently doesn't return an existing index, given the value is the same.

Parameters:
v - byte array to be appended