org.entityfs.util
Class FileSystems

java.lang.Object
  extended by org.entityfs.util.FileSystems

public class FileSystems
extends Object

A utility class that contains static methods for working with FileSystem:s.

The methods in this class will use the locking strategy for utility classes described in EntityLock.

Since:
1.0
Author:
Karl Gustafsson
See Also:
FileSystem

Method Summary
static boolean entityExists(FileSystem fs, AbsoluteLocation el)
          Check if there exists an entity in the supplied location.
static AbsoluteLocation getCanonicalLocation(FileSystem fs, AbsoluteLocation l)
          Return the canonical location for the given location in this file system.
static Entity getEntity(FileSystem fs, AbsoluteLocation el)
          Get the entity identified by the absolute entity location.
static Directory getEntityForDirectory(File d, boolean readOnly)
          Create a file system with the root in the given directory and return a Directory entity object representing it.
static EFile getEntityForFile(File f, boolean readOnly)
          Create a file system with the root in the file's parent directory and return an EFile entity object representing the file.
static Entity getEntityOrNull(FileSystem fs, AbsoluteLocation el)
          Get the entity identified by the absolute entity location.
static EFile getTextFile(String s)
          Creates an in-memory file system containing a text file that contains the provided text and returns the file object.
static EFile getTextFile(String s, FileSystem fs)
          Create a text file containing the provided text in the provided file system's temporary files directory.
static Directory putIfAbsentDirectory(FileSystem fs, AbsoluteLocation el)
          Get the directory that exists in the supplied absolute entity location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

entityExists

public static boolean entityExists(FileSystem fs,
                                   AbsoluteLocation el)
                            throws CircularReferenceException,
                                   AccessDeniedException
Check if there exists an entity in the supplied location.

Parameters:
fs - The file system.
el - The location of the entity.
Returns:
true if the entity exists in the file system, false otherwise.
Throws:
CircularReferenceException - If there is a circular reference in a chain of entity-accepting entities that have to be dereferenced in order to find the entity.
AccessDeniedException - If the calling thread does not have execute access to a parent directory of the entity.
Permissions_required:
Execute access to all directories between the file system's root directory (inclusive) and the entity.

getEntity

public static Entity getEntity(FileSystem fs,
                               AbsoluteLocation el)
                        throws EntityNotFoundException,
                               CircularReferenceException,
                               AccessDeniedException
Get the entity identified by the absolute entity location.

Parameters:
fs - The file system.
el - The absolute location of the entity.
Returns:
The entity in the supplied absolute entity location.
Throws:
EntityNotFoundException - If there is no entity in the absolute location.
CircularReferenceException - If there is a circular reference in a chain of entity-accepting entities that have to be dereferenced in order to find the entity.
AccessDeniedException - If the calling thread does not have execute access to a parent directory of the entity.
See Also:
getEntityOrNull(FileSystem, AbsoluteLocation)
Permissions_required:
Execute access to all directories between the file system's root directory (inclusive) and the entity.

getEntityOrNull

public static Entity getEntityOrNull(FileSystem fs,
                                     AbsoluteLocation el)
                              throws CircularReferenceException,
                                     AccessDeniedException
Get the entity identified by the absolute entity location.

Parameters:
el - An AbsoluteLocation identifying the entity to return.
Returns:
The entity in the supplied absolute entity location, or null if there is no entity in that location.
Throws:
CircularReferenceException - If there is a circular reference in a chain of entity-accepting entities that have to be dereferenced in order to find the entity.
AccessDeniedException - If the calling thread does not have execute access to a parent directory of the entity.
See Also:
getEntity(FileSystem, AbsoluteLocation)
Permissions_required:
Execute access to all directories between the file system's root directory (inclusive) and the entity.

putIfAbsentDirectory

public static Directory putIfAbsentDirectory(FileSystem fs,
                                             AbsoluteLocation el)
                                      throws EntityFoundException,
                                             CircularReferenceException,
                                             AccessDeniedException
Get the directory that exists in the supplied absolute entity location. If there is no directory in the location, create it and all necessary parent directories.

Parameters:
fs - The file system.
el - The absolute location of the directory.
Returns:
The directory in the supplied location.
Throws:
EntityFoundException - If there is a non-directory entity somewhere in the directory path so that the directory cannot be created.
CircularReferenceException - If there is a circular reference in a chain of entity-accepting entities that have to be dereferenced in order to find the entity.
AccessDeniedException - If the calling thread does not have sufficient access rights.
Permissions_required:
Execute access to all directories between the file system's root directory (inclusive) and the target directory. Write access to all parent directories of directories that this method must create.

getCanonicalLocation

public static AbsoluteLocation getCanonicalLocation(FileSystem fs,
                                                    AbsoluteLocation l)
                                             throws EntityNotFoundException,
                                                    CircularReferenceException,
                                                    AccessDeniedException
Return the canonical location for the given location in this file system. For file systems that don't support any other entity-accepting entities than directories (don't support symbolic links), this always returns the supplied location.

Parameters:
fs - The file system.
l - The absolute entity location.
Returns:
The canonical absolute entity location.
Throws:
EntityNotFoundException - If an entity denoted by the absolute location does not exist.
CircularReferenceException - If there is a circular reference in a chain of entity-accepting entities that have to be dereferenced in order to find the entity.
AccessDeniedException - If the calling thread does not have execute access to the entities necessary for creating the canonical location.
See Also:
File.getCanonicalFile(), Entities.getCanonicalLocation(EntityView)
Permissions_required:
Execute access to all entities necessary for creating the canonical location.

getEntityForFile

public static EFile getEntityForFile(File f,
                                     boolean readOnly)
                              throws NotAFileException,
                                     EntityNotFoundException
Create a file system with the root in the file's parent directory and return an EFile entity object representing the file.

The file system is created with the default configuration from FSRWFileSystemBuilder (or FSROFileSystemBuilder if it is read-only).

Parameters:
f - The file to return the entity object for.
readOnly - Should the created file system be read only?
Returns:
An entity object representing the file in a new file system.
Throws:
EntityNotFoundException - If the file does not exist.
NotAFileException - If the file is not a file.

getEntityForDirectory

public static Directory getEntityForDirectory(File d,
                                              boolean readOnly)
                                       throws NotADirectoryException,
                                              EntityNotFoundException
Create a file system with the root in the given directory and return a Directory entity object representing it.

The file system is created with the default configuration from FSRWFileSystemBuilder (or FSROFileSystemBuilder if it is read-only).

Parameters:
d - The directory to return the entity object for.
readOnly - Should the created file system be read only?
Returns:
An entity object representing the directory in a new file system.
Throws:
EntityNotFoundException - If the directory does not exist.
NotAFileException - If the file object does not reference a directory.
NotADirectoryException

getTextFile

public static EFile getTextFile(String s)
Creates an in-memory file system containing a text file that contains the provided text and returns the file object.

The returned file system does not do any entity locking, does not send any entity events and does not use any access controls.

Parameters:
s - The contents of the text file.
Returns:
The text file.

getTextFile

public static EFile getTextFile(String s,
                                FileSystem fs)
                         throws IllegalArgumentException
Create a text file containing the provided text in the provided file system's temporary files directory.

Parameters:
s - The contents of the text file.
fs - The file system.
Returns:
A reference to the text file.
Throws:
IllegalArgumentException - If the provided file system does not have a temporary files directory set.
See Also:
FileSystem.setTemporaryFilesDirectory(Directory)