org.schmant.support.entityfs
Class SchmantFileSystems

java.lang.Object
  extended by org.schmant.support.entityfs.SchmantFileSystems

public final class SchmantFileSystems
extends Object

This is Schmant's wrapper for the EntityFS FileSystems utility class. The methods in this class calls their FileSystems counterparts and sets the SchmantReportLogAdapter LogAdapter on the returned (entities') file systems.

Since:
0.6
Author:
Karl Gustafsson

Method Summary
static Directory createRamFileSystem()
          Create a memory-backed locking file system and return its root directory.
static Directory getEntityForDirectory(File d, boolean readOnly)
          Creates a locking file system with the root in the supplied directory and returns the root directory.
static Directory getEntityForDirectory(File d, boolean readOnly, boolean locking)
          Creates a file system with the root in the supplied directory and returns the root directory.
static Directory getEntityForDirectory(File d, String tmpDirName)
          Creates a read/write locking file system with the root in the supplied directory and returns the root directory.
static EFile getEntityForFile(File f, boolean readOnly)
          Create a locking file system with the root directory in the file's parent directory and return a reference to the file entity.
static File makeFileBacked(EFile f)
          Make the supplied file entity File-backed.
static EFile makeRandomlyAccessible(EFile f)
          Make sure that the file is randomly accessible (supports the FCRandomAccess capability).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getEntityForDirectory

public static Directory getEntityForDirectory(File d,
                                              boolean readOnly)
Creates a locking file system with the root in the supplied directory and returns the root directory. Events, entity validation and access controls are disabled on the file system.

File system locking is a way of ensuring that parallel threads cannot modify the same entities simultaneously. If you're running a single-threaded build, you can create a non-locking file system using the getEntityForDirectory(File, boolean, boolean) method instead.

The returned file system logs to a SchmantReportLogAdapter.

This is equivalent to calling:
new FS(RO/RW)FileSystemBuilder().
  setRoot(d).
(  enableLocking(). if read/write)
  disableEntityValidityControls().
  disableAccessControls().
  setLogAdapter(SchmantReportLogAdapter.INSTANCE).
  create().
  getRootDirectory();

Parameters:
d - The directory.
readOnly - Should the returned directory be read only?
Returns:
The file system's root directory.
See Also:
getEntityForDirectory(File, String), getEntityForDirectory(File, boolean, boolean)

getEntityForDirectory

public static Directory getEntityForDirectory(File d,
                                              boolean readOnly,
                                              boolean locking)
Creates a file system with the root in the supplied directory and returns the root directory. Events, entity validation and access controls are disabled on the file system. Locking may be enabled by setting locking to true.

File system locking is a way of ensuring that parallel threads cannot modify the same entities simultaneously.

The returned file system logs to a SchmantReportLogAdapter.

This is equivalent to calling:
new FS(RO/RW)FileSystemBuilder().
  setRoot(d).
(  enableLocking(). if read/write and locking is enabled)
  disableEntityValidityControls().
  disableAccessControls().
  setLogAdapter(SchmantReportLogAdapter.INSTANCE).
  create().
  getRootDirectory();

Parameters:
d - The directory.
readOnly - Should the returned directory be read only?
locking - Should the returned file system be locking (if it is read/write)?
Returns:
The file system's root directory.
See Also:
getEntityForDirectory(File, String), getEntityForDirectory(File, boolean)

getEntityForDirectory

public static Directory getEntityForDirectory(File d,
                                              String tmpDirName)
Creates a read/write locking file system with the root in the supplied directory and returns the root directory. Events, entity validation and access controls are disabled on the file system.

The file system is assigned a temporary directory with the name tmpDirName in its root directory. If the directory does not already exist, it is created.

Parameters:
d - The directory
tmpDirName - The name of the file system's temporary files directory, in the file system's root directory. If the directory does not already exist, it is created by this method.
Returns:
The new file system's root directory.
See Also:
getEntityForDirectory(File, boolean)

getEntityForFile

public static EFile getEntityForFile(File f,
                                     boolean readOnly)
Create a locking file system with the root directory in the file's parent directory and return a reference to the file entity.

The file system is created with the same settings as a file system created by getEntityForDirectory(File, boolean).

Parameters:
f - The file.
readOnly - Should the returned file be read only?
Returns:
The file.

createRamFileSystem

public static Directory createRamFileSystem()
Create a memory-backed locking file system and return its root directory. Events and access controls are disabled on the file system.

The returned file system logs to a SchmantReportLogAdapter.

This is equivalent to calling:
new RamFileSystemBuilder().
  enableLocking().
  disableEntityValidityControls().
  setLogAdapter(SchmantReportLogAdapter.INSTANCE).
  create().
  getRootDirectory();

Returns:
The file system's root directory.

makeFileBacked

public static File makeFileBacked(EFile f)
                           throws WrappedIOException
Make the supplied file entity File-backed. If the entity is in a non-file backed file system, it is copied to a temporary directory.

Parameters:
f - The entity to make file-backed.
Returns:
A file reference to the entity
Throws:
WrappedIOException
Since:
0.9.1

makeRandomlyAccessible

public static EFile makeRandomlyAccessible(EFile f)
Make sure that the file is randomly accessible (supports the FCRandomAccess capability). If it is not, its contents is copied to a temporary file and the temporary file is returned.

Parameters:
f - The file.
Returns:
A randomly accessible version of the file.