org.cdlib.xtf.textIndexer
Class StructuredFileProxy

Object
  extended by StructuredFileProxy
All Implemented Interfaces:
StructuredStore

public class StructuredFileProxy
extends Object
implements StructuredStore

Used to put off actually creating a structured store until it is needed. Essentially, all methods are delegated to a StructuredFile that is created when the first time a method is called. The file is released after a close() or delete() operation. As an additional precaution, the store is created under a temporary file name, and only renamed to the final filename when the file is closed.

Author:
Martin Haye

Field Summary
private  File finalPath
           
private  StructuredFile realStore
           
private  File tmpPath
           
 
Constructor Summary
StructuredFileProxy(File path)
           
 
Method Summary
 void close()
          Closes the store.
 SubStoreWriter createSubStore(String name)
          Create a new sub-store with the specified name.
 void delete()
          Deletes the storage completely (implies close() first)
 String getSystemId()
          Gets the path, URI, or other unique identifier for this store
 String getUserVersion()
          Gets the user version (if any) set by StructuredStore.setUserVersion(String).
 SubStoreReader openSubStore(String name)
          Opens a pre-existing sub-store for read (or write).
private  StructuredFile realStore()
           
 void setUserVersion(String ver)
          Sets a user-defined version number for the file.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

finalPath

private File finalPath

tmpPath

private File tmpPath

realStore

private StructuredFile realStore
Constructor Detail

StructuredFileProxy

public StructuredFileProxy(File path)
Method Detail

createSubStore

public SubStoreWriter createSubStore(String name)
                              throws IOException
Description copied from interface: StructuredStore
Create a new sub-store with the specified name. Returns a SubStore that has most of the interface of a RandomAccessFile, except that seeks will be relative to the sub-store start. Only one substore may be created at a time (though many others may be opened, provided they were created before.) The caller must call SubStore.close() when the file is complete, to ensure that the directory gets written.

Specified by:
createSubStore in interface StructuredStore
Parameters:
name - Name of the sub-file to create. Must not exist.
Returns:
A sub-store to write to.
Throws:
IOException

openSubStore

public SubStoreReader openSubStore(String name)
                            throws IOException
Description copied from interface: StructuredStore
Opens a pre-existing sub-store for read (or write). Returns a sub-store that has most of the interface of a RandomAccessFile, except that seeks will be relative to the sub-file start, and IO operations cannot exceed the boundaries of the sub-file. Many sub-stores may be open simultaneously; each one has an independent file pointer. Each one is light weight, so it's okay to have many open at a time.

Specified by:
openSubStore in interface StructuredStore
Parameters:
name - Name of pre-existing sub-store to open.
Throws:
IOException

close

public void close()
           throws IOException
Description copied from interface: StructuredStore
Closes the store. This should always be called, to ensure that all sub-stores have been closed and that the directory has been written.

Specified by:
close in interface StructuredStore
Throws:
IOException

delete

public void delete()
            throws IOException
Description copied from interface: StructuredStore
Deletes the storage completely (implies close() first)

Specified by:
delete in interface StructuredStore
Throws:
IOException

getSystemId

public String getSystemId()
Description copied from interface: StructuredStore
Gets the path, URI, or other unique identifier for this store

Specified by:
getSystemId in interface StructuredStore

setUserVersion

public void setUserVersion(String ver)
                    throws IOException
Description copied from interface: StructuredStore
Sets a user-defined version number for the file. It can be retrieved later with StructuredStore.getUserVersion().

Specified by:
setUserVersion in interface StructuredStore
Parameters:
ver - The version number to set.
Throws:
IOException

getUserVersion

public String getUserVersion()
Description copied from interface: StructuredStore
Gets the user version (if any) set by StructuredStore.setUserVersion(String).

Specified by:
getUserVersion in interface StructuredStore

realStore

private StructuredFile realStore()