iitb.con.util
Class ArrayFreeSpaceList

java.lang.Object
  extended by iitb.con.util.ArrayFreeSpaceList
All Implemented Interfaces:
FreeSpaceList

public class ArrayFreeSpaceList
extends java.lang.Object
implements FreeSpaceList

ArrayFreeSpaceList is the list which maintains the information about the free blocks in a file.

The format of the list is : {[Start Location], [End Location]}
where the start location and end location indicates the block start and end in the file.


Constructor Summary
ArrayFreeSpaceList(java.lang.String fileName, java.lang.String mode)
          Reads and initializes the information about the free blocks space
 
Method Summary
 void close()
          Closes the free space list file
 void commit()
          Commits the changes to the free space list file
 void dumpFreeSpaceList()
          Dumps the free space list contents
 boolean freeTheBlock(long location, long size)
          Frees the specified block in the file
 long getFreeBlock(long size)
          Returns the free block location
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayFreeSpaceList

public ArrayFreeSpaceList(java.lang.String fileName,
                          java.lang.String mode)
                   throws java.io.FileNotFoundException,
                          java.io.IOException
Reads and initializes the information about the free blocks space

Parameters:
fileName - free space list file name
mode - opening mode (r, rw)
Throws:
java.io.FileNotFoundException - if file not found
java.io.IOException - if file operation fails
Method Detail

close

public void close()
           throws java.io.IOException
Closes the free space list file

Specified by:
close in interface FreeSpaceList
Throws:
java.io.IOException - if file operation fails

commit

public void commit()
            throws java.io.IOException
Commits the changes to the free space list file

Specified by:
commit in interface FreeSpaceList
Throws:
java.io.IOException - if file operation fails

dumpFreeSpaceList

public void dumpFreeSpaceList()
Dumps the free space list contents


freeTheBlock

public boolean freeTheBlock(long location,
                            long size)
Frees the specified block in the file

Specified by:
freeTheBlock in interface FreeSpaceList
Parameters:
location - block location
size - block size
Returns:
true on success

getFreeBlock

public long getFreeBlock(long size)
Returns the free block location

Specified by:
getFreeBlock in interface FreeSpaceList
Parameters:
size - request block size
Returns:
free block location