org.simantics.databoard.accessor.file
Class FileLibrary

java.lang.Object
  extended by org.simantics.databoard.accessor.file.FileLibrary

public class FileLibrary
extends java.lang.Object

File library handles sharing of file accessors and automatic closing of files.

On call of getFile or createFile the file library opens a file and returns a file accessor. In concecutive runs the same accessor instance is returned, unless the file was garbage collected. The shared accessor instances are not concurrent-use-safe.

The file handles are actually closed by two ways: a) File accessor are garbage collected and the the user calls expunge() b) The user invokes close() in the FileLibrary. Files are flushed before closed.

Author:
Toni Kalajainen

Constructor Summary
FileLibrary()
          Create new file library
FileLibrary(AccessorParams params)
          Create new file library
 
Method Summary
 void close()
          Close and free all files, this invalidates all existing FileAccessors.
 FileVariantAccessor createFile(java.io.File file)
          Create a new file and put it in the library.
 boolean deleteFile(java.io.File file)
           
 void expunge()
          Close unused file accessors.
 FileVariantAccessor getExistingFile(java.io.File file)
          Get existing open file accessor.
 FileVariantAccessor getFile(java.io.File file)
          Open file or get an existing file accessor.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileLibrary

public FileLibrary()
Create new file library


FileLibrary

public FileLibrary(AccessorParams params)
Create new file library

Method Detail

getExistingFile

public FileVariantAccessor getExistingFile(java.io.File file)
                                    throws AccessorConstructionException
Get existing open file accessor.

Parameters:
file -
Returns:
file or null
Throws:
java.io.IOException
AccessorConstructionException

getFile

public FileVariantAccessor getFile(java.io.File file)
                            throws AccessorConstructionException
Open file or get an existing file accessor. The caller must not close the file, it is closed upon garbage collection or when FileLibrary is closed.

Parameters:
file -
Returns:
an accessor to the contents of a file
Throws:
java.io.IOException
AccessorConstructionException

createFile

public FileVariantAccessor createFile(java.io.File file)
                               throws AccessorConstructionException
Create a new file and put it in the library. If the file exists it is overwritten.

Parameters:
file -
Returns:
accessor to contents of a file
Throws:
AccessorConstructionException

deleteFile

public boolean deleteFile(java.io.File file)
                   throws AccessorException
Throws:
AccessorException

expunge

public void expunge()
Close unused file accessors.


close

public void close()
Close and free all files, this invalidates all existing FileAccessors. close() doesn't invalidate FileLibrary.