org.garret.perst
Class MappedFile

java.lang.Object
  extended by org.garret.perst.MappedFile
All Implemented Interfaces:
IFile

public class MappedFile
extends java.lang.Object
implements IFile

Class using NIO mapping file on virtual mapping. Useing this class instead standard OSFile can significantly increase speed of application in some cases.


Constructor Summary
MappedFile(java.lang.String filePath, long initialSize, boolean readOnly)
           
 
Method Summary
 void close()
          Close file
 long length()
          Length of the file
 void lock(boolean shared)
          Lock file
 int read(long pos, byte[] buf)
          Read data from the file
 void sync()
          Flush all fiels changes to the disk
 boolean tryLock(boolean shared)
          Try lock file
 void unlock()
          Unlock file
 void write(long pos, byte[] buf)
          Write data to the file
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MappedFile

public MappedFile(java.lang.String filePath,
                  long initialSize,
                  boolean readOnly)
Method Detail

close

public void close()
Description copied from interface: IFile
Close file

Specified by:
close in interface IFile

length

public long length()
Description copied from interface: IFile
Length of the file

Specified by:
length in interface IFile

lock

public void lock(boolean shared)
Description copied from interface: IFile
Lock file

Specified by:
lock in interface IFile
Parameters:
shared - if lock is shared

read

public int read(long pos,
                byte[] buf)
Description copied from interface: IFile
Read data from the file

Specified by:
read in interface IFile
Parameters:
pos - offset in the file
buf - array to receive readen data (size is always equal to database page size)
Returns:
number of bytes actually readen

sync

public void sync()
Description copied from interface: IFile
Flush all fiels changes to the disk

Specified by:
sync in interface IFile

tryLock

public boolean tryLock(boolean shared)
Description copied from interface: IFile
Try lock file

Specified by:
tryLock in interface IFile
Parameters:
shared - if lock is shared
Returns:
true if file was successfully locked or locking in not implemented, false if file is locked by some other applciation

unlock

public void unlock()
Description copied from interface: IFile
Unlock file

Specified by:
unlock in interface IFile

write

public void write(long pos,
                  byte[] buf)
Description copied from interface: IFile
Write data to the file

Specified by:
write in interface IFile
Parameters:
pos - offset in the file
buf - array with data to be writter (size is always equal to database page size)