Module org.refcodes.filesystem
Package org.refcodes.filesystem
Class ChangeRootFileSystemWrapperImpl
java.lang.Object
org.refcodes.filesystem.ChangeRootFileSystemWrapperImpl
- All Implemented Interfaces:
org.refcodes.component.Component
,org.refcodes.component.Destroyable
,FileSystem
The change root space wrapper for a given
FileSystem
relocates the
paths accessed by an application to the given namespace. This is helpful in
case an application is to use a FileSystem
sand box. Only the files
below that name space are visible by the file system.
ATTENTION: Make sure that the FileSystem
cannot jail break its sand
box by using relative paths with ".." !!!
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.refcodes.component.Destroyable
org.refcodes.component.Destroyable.DestroyAutomaton
-
Field Summary
Fields inherited from interface org.refcodes.filesystem.FileSystem
PATH_DELIMITER
-
Constructor Summary
ConstructorDescriptionChangeRootFileSystemWrapperImpl
(String aNamespace, FileSystem aFileSystem) Instantiates a new change root file system wrapper impl. -
Method Summary
Modifier and TypeMethodDescriptioncreateFile
(String aKey) Creates a file (handle) with the given key.createFile
(String aPath, String aName) Creates a file (handle) with the given path and name.void
deleteFile
(FileHandle aFileHandle) Deletes a file (handle) from the file system.void
destroy()
fromFile
(FileHandle aFromFileHandle) An input stream is being provided from which the data of the file (handle) may be read.void
fromFile
(FileHandle aFromFileHandle, File aToFile) The data contained in the given file (handle) is written to the provided file.void
fromFile
(FileHandle aFromFileHandle, OutputStream aOutputStream) The data contained in the given file (handle) is written to the provided output stream.getFileHandle
(String aKey) Gets a file (handle) with the given key from the file system.getFileHandle
(String aPath, String aName) Gets a file (handle) with the given path and name from the file system.getFileHandles
(String aPath, boolean isRecursively) With the behavior of theFileSystem.hasFiles(String, boolean)
method, all file (handle)s found for the path are returned.boolean
Tests whether the file system knows a file (handle) with the given key.boolean
Tests whether the file system knows a file (handle) with the given path and name.boolean
hasFile
(FileHandle aFileHandle) Returns true in case the given file (handle) exists.boolean
Determines whether there is any file (handle)s found for the given path.moveFile
(FileHandle aFileHandle, String aNewKey) Renames the file (handle), it will be accessible via the provided key.renameFile
(FileHandle aFileHandle, String aNewName) Renames the file (handle), the name part of the key will be renamed to the new name.toFile
(FileHandle aToFileHandle) Returns an output stream which may be used to write (or append, in case data did already exist for the file system) data to a file (handle).void
toFile
(FileHandle aToFileHandle, byte[] aBuffer) Data provided by the given buffer is written to the file (handle) (or appended to the file (handle)'s data in case the file (handle) did already contain data).void
toFile
(FileHandle aToFileHandle, File aFromFile) Data provided by the given input stream is written to the file (handle) (or appended to the file (handle)'s data in case the file (handle) did already contain data).void
toFile
(FileHandle aToFileHandle, InputStream aInputStream) Data provided by the given input stream is written to the file (handle) (or appended to the file (handle)'s data in case the file (handle) did already contain data).
-
Constructor Details
-
ChangeRootFileSystemWrapperImpl
Instantiates a new change root file system wrapper impl.- Parameters:
aNamespace
- the namespaceaFileSystem
- the file system
-
-
Method Details
-
hasFile
public boolean hasFile(String aKey) throws IllegalKeyException, NoListAccessException, UnknownFileSystemException, IOException Tests whether the file system knows a file (handle) with the given key.- Specified by:
hasFile
in interfaceFileSystem
- Parameters:
aKey
- The key which to test if there is a file (handle).- Returns:
- True in case there is a file (handle) with the given key exists.
- Throws:
IllegalKeyException
- in case the path was not a valid path.NoListAccessException
- in case listing the content in the file system was denied.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle).
-
hasFile
public boolean hasFile(String aPath, String aName) throws IllegalPathException, IllegalNameException, NoListAccessException, UnknownFileSystemException, IOException Tests whether the file system knows a file (handle) with the given path and name. Caution, path and name are not just concatenated with a path separator in between to get the key: The name must not contain any path separator! In case of a file system implementation of the file system ("file system nature") the name must actually represent the filename of the file representing the file (handle).- Specified by:
hasFile
in interfaceFileSystem
- Parameters:
aPath
- The path part of the key for which to test if there is a file (handle).aName
- The name part of the key for which to test if there is a file (handle).- Returns:
- True in case there is a file (handle) with the given path and name exists.
- Throws:
IllegalPathException
- in case the path was not a valid path.IllegalNameException
- in case the name was not a valid path.NoListAccessException
- in case listing the content in the file syste was denied.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)
-
hasFile
public boolean hasFile(FileHandle aFileHandle) throws NoListAccessException, UnknownFileSystemException, IOException, IllegalFileHandleException Returns true in case the given file (handle) exists.- Specified by:
hasFile
in interfaceFileSystem
- Parameters:
aFileHandle
- The file (handle) which's existence is to be tested.- Returns:
- True in case the file (handle) exists, else false is returned.
- Throws:
NoListAccessException
- in case listing the content in the file system was denied.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)IllegalFileHandleException
- in case the file handle with name and path is not valid, i.e. the name contains a path separator.
-
createFile
public FileHandle createFile(String aKey) throws FileAlreadyExistsException, NoCreateAccessException, IllegalKeyException, UnknownFileSystemException, IOException, NoListAccessException Creates a file (handle) with the given key.- Specified by:
createFile
in interfaceFileSystem
- Parameters:
aKey
- The key for which to create the file (handle).- Returns:
- The newly created file (handle).
- Throws:
FileAlreadyExistsException
- in case a file (handle) with the given key (path and name) already exists.NoCreateAccessException
- in case create access to the file system was denied.IllegalKeyException
- in case the key with name and path is not valid, i.e. the name contains a path separator.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)NoListAccessException
- in case listing the content in the file system was denied.
-
createFile
public FileHandle createFile(String aPath, String aName) throws FileAlreadyExistsException, NoCreateAccessException, IllegalNameException, IllegalPathException, UnknownFileSystemException, IOException, NoListAccessException Creates a file (handle) with the given path and name. Caution, path and name are not just concatenated with a path separator in between to get the key: The name must not contain any path separator! In case of a file system implementation of the file system ("file system alternative") the name will actually represent the filename of the file representing the file handle.- Specified by:
createFile
in interfaceFileSystem
- Parameters:
aPath
- The path part of the key for which to create the file (handle).aName
- The name part of the key for which to create the file (handle).- Returns:
- The newly created file (handle).
- Throws:
FileAlreadyExistsException
- in case a file (handle) with the given key (path and name) already exists.NoCreateAccessException
- in case create access to the file system was denied.IllegalNameException
- in case the name was not a valid path.IllegalPathException
- in case the path was not a valid path.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)NoListAccessException
- in case listing the content in the file system was denied.
-
getFileHandle
public FileHandle getFileHandle(String aKey) throws NoListAccessException, IllegalKeyException, UnknownFileSystemException, IOException, UnknownKeyException Gets a file (handle) with the given key from the file system.- Specified by:
getFileHandle
in interfaceFileSystem
- Parameters:
aKey
- The key for which to retrieve the file (handle).- Returns:
- The retrieved file (handle).
- Throws:
NoListAccessException
- in case listing the content in the file system was denied.IllegalKeyException
- in case the key with name and path is not valid, i.e. the name contains a path separator.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)UnknownKeyException
- in case the given key (path and name) does not exist in the file system.
-
getFileHandle
public FileHandle getFileHandle(String aPath, String aName) throws NoListAccessException, IllegalNameException, IllegalPathException, UnknownFileSystemException, IOException, UnknownKeyException Gets a file (handle) with the given path and name from the file system. Caution, path and name are not just concatenated with a path separator in between to get the key: The name must not contain any path separator! In case of a file system implementation of the file system ("file system nature") the name will actually represent the filename of the file representing the file (handle).- Specified by:
getFileHandle
in interfaceFileSystem
- Parameters:
aPath
- The path part of the key for which to retrieve the file (handle).aName
- The name part of the key for which to retrieve the file (handle).- Returns:
- The retrieved file (handle).
- Throws:
NoListAccessException
- in case listing the content in the file system was denied.IllegalNameException
- in case the name was not a valid path.IllegalPathException
- in case the path was not a valid path.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)UnknownKeyException
- in case the given key (path and name) does not exist in the file system.
-
fromFile
public void fromFile(FileHandle aFromFileHandle, OutputStream aOutputStream) throws ConcurrentAccessException, UnknownFileException, NoReadAccessException, UnknownFileSystemException, IOException, NoListAccessException, IllegalFileHandleException The data contained in the given file (handle) is written to the provided output stream. This may be used to write the file (handle) to a file.- Specified by:
fromFile
in interfaceFileSystem
- Parameters:
aFromFileHandle
- The file (handle) which is to be written to the output stream.aOutputStream
- The stream to which to write.- Throws:
ConcurrentAccessException
- in case the file (handle) is concurrently read, modified or deleted.UnknownFileException
- in case none such file (handle) was found in the file system.NoReadAccessException
- in case read access to the file system was denied.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)NoListAccessException
- in case listing the content in the file system was denied.IllegalFileHandleException
- in case the file handle with name and path is not valid, i.e. the name contains a path separator.
-
toFile
public void toFile(FileHandle aToFileHandle, InputStream aInputStream) throws ConcurrentAccessException, UnknownFileException, NoWriteAccessException, UnknownFileSystemException, IOException, NoListAccessException, IllegalFileHandleException Data provided by the given input stream is written to the file (handle) (or appended to the file (handle)'s data in case the file (handle) did already contain data). This may be used to store data from a file in a file (handle).- Specified by:
toFile
in interfaceFileSystem
- Parameters:
aToFileHandle
- The file (handle) to which data is to be written.aInputStream
- The input stream from which to read the data which is to be written to the file (handle).- Throws:
ConcurrentAccessException
- in case the file (handle) is concurrently read, modified or deleted.UnknownFileException
- in case none such file (handle) was found in the file system.NoWriteAccessException
- in case write access to the file system was denied.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)NoListAccessException
- in case listing the content in the file system was denied.IllegalFileHandleException
- in case the file handle with name and path is not valid, i.e. the name contains a path separator.
-
fromFile
public InputStream fromFile(FileHandle aFromFileHandle) throws ConcurrentAccessException, UnknownFileException, UnknownFileException, NoReadAccessException, UnknownFileSystemException, IOException, NoListAccessException, IllegalFileHandleException An input stream is being provided from which the data of the file (handle) may be read.- Specified by:
fromFile
in interfaceFileSystem
- Parameters:
aFromFileHandle
- The file (handle) for which to get the input stream.- Returns:
- The input stream providing the data of the file (handle).
- Throws:
ConcurrentAccessException
- in case the file (handle) is concurrently read, modified or deleted.UnknownFileException
- in case none such file (handle) was found in the file system.NoReadAccessException
- in case read access to the file system was denied.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)NoListAccessException
- in case listing the content in the file system was denied.IllegalFileHandleException
- in case the file handle with name and path is not valid, i.e. the name contains a path separator.
-
toFile
public OutputStream toFile(FileHandle aToFileHandle) throws ConcurrentAccessException, UnknownFileException, NoWriteAccessException, UnknownFileSystemException, IOException, IllegalFileHandleException Returns an output stream which may be used to write (or append, in case data did already exist for the file system) data to a file (handle).- Specified by:
toFile
in interfaceFileSystem
- Parameters:
aToFileHandle
- The file (handle) to which to write data.- Returns:
- The output stream to be used to write data to.
- Throws:
ConcurrentAccessException
- in case the file (handle) is concurrently read, modified or deleted.UnknownFileException
- in case none such file (handle) was found in the file system.NoWriteAccessException
- in case write access to the file system was denied.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)IllegalFileHandleException
- in case the file handle with name and path is not valid, i.e. the name contains a path separator.
-
fromFile
public void fromFile(FileHandle aFromFileHandle, File aToFile) throws ConcurrentAccessException, UnknownFileException, NoReadAccessException, UnknownFileSystemException, IOException, NoListAccessException, IllegalFileHandleException The data contained in the given file (handle) is written to the provided file.- Specified by:
fromFile
in interfaceFileSystem
- Parameters:
aFromFileHandle
- The file (handle) which is to be written to the output stream.aToFile
- The file to which the data is to be written.- Throws:
ConcurrentAccessException
- in case the file (handle) is concurrently read, modified or deleted.UnknownFileException
- in case none such file (handle) was found in the file system.NoReadAccessException
- in case read access to the file system was denied.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)NoListAccessException
- in case listing the content in the file system was denied.IllegalFileHandleException
- in case the file handle with name and path is not valid, i.e. the name contains a path separator.
-
toFile
public void toFile(FileHandle aToFileHandle, File aFromFile) throws ConcurrentAccessException, UnknownFileException, NoWriteAccessException, UnknownFileSystemException, IOException, NoListAccessException, IllegalFileHandleException Data provided by the given input stream is written to the file (handle) (or appended to the file (handle)'s data in case the file (handle) did already contain data). This may be used to store data from a file in a file (handle).- Specified by:
toFile
in interfaceFileSystem
- Parameters:
aToFileHandle
- The file (handle) to which data is to be written.aFromFile
- The file from which to read the data which is to be written to the file (handle).- Throws:
ConcurrentAccessException
- in case the file (handle) is concurrently read, modified or deleted.UnknownFileException
- in case none such file (handle) was found in the file system.NoWriteAccessException
- in case write access to the file system was denied.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)NoListAccessException
- in case listing the content in the file system was denied.IllegalFileHandleException
- in case the file handle with name and path is not valid, i.e. the name contains a path separator.
-
toFile
public void toFile(FileHandle aToFileHandle, byte[] aBuffer) throws ConcurrentAccessException, UnknownFileException, NoWriteAccessException, UnknownFileSystemException, IOException, NoListAccessException, IllegalFileHandleException Data provided by the given buffer is written to the file (handle) (or appended to the file (handle)'s data in case the file (handle) did already contain data). This may be used to store data from a string or other data structure.- Specified by:
toFile
in interfaceFileSystem
- Parameters:
aToFileHandle
- The file (handle) to which data is to be written.aBuffer
- The buffer from which to read the data which is to be written to the file (handle).- Throws:
ConcurrentAccessException
- in case the file (handle) is concurrently read, modified or deleted.UnknownFileException
- in case none such file (handle) was found in the file system.NoWriteAccessException
- in case write access to the file system was denied.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)NoListAccessException
- in case listing the content in the file system was denied.IllegalFileHandleException
- in case the file handle with name and path is not valid, i.e. the name contains a path separator.
-
renameFile
public FileHandle renameFile(FileHandle aFileHandle, String aNewName) throws UnknownFileException, ConcurrentAccessException, FileAlreadyExistsException, NoCreateAccessException, NoDeleteAccessException, IllegalNameException, UnknownFileSystemException, IOException, NoListAccessException, IllegalFileHandleException Renames the file (handle), the name part of the key will be renamed to the new name. The name must not contain any path separator.- Specified by:
renameFile
in interfaceFileSystem
- Parameters:
aFileHandle
- The file (handle) to be renamed.aNewName
- The new name of the file (handle).- Returns:
- The resulting file (handle) in case the operation was successful.
- Throws:
UnknownFileException
- in case none such file (handle) was found in the file system.ConcurrentAccessException
- in case the file (handle) is concurrently read, modified or deleted.FileAlreadyExistsException
- in case a file (handle) with the given key (path and name) already exists.NoCreateAccessException
- in case create access to the file system was denied.NoDeleteAccessException
- in case create access to the file system was denied.IllegalNameException
- in case the name was not a valid path.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)NoListAccessException
- in case listing the content in the file system was denied.IllegalFileHandleException
- in case the file handle with name and path is not valid, i.e. the name contains a path separator.
-
moveFile
public FileHandle moveFile(FileHandle aFileHandle, String aNewKey) throws UnknownFileException, ConcurrentAccessException, FileAlreadyExistsException, NoCreateAccessException, NoDeleteAccessException, IllegalKeyException, UnknownFileSystemException, IOException, NoListAccessException, IllegalFileHandleException Renames the file (handle), it will be accessible via the provided key.- Specified by:
moveFile
in interfaceFileSystem
- Parameters:
aFileHandle
- The file (handle) to be renamed.aNewKey
- The new key (path and name) of the file (handle).- Returns:
- the file handle
- Throws:
UnknownFileException
- in case none such file (handle) was found in the file system.ConcurrentAccessException
- in case the file (handle) is concurrently read, modified or deleted.FileAlreadyExistsException
- in case a file (handle) with the given key (path and name) already exists.NoCreateAccessException
- in case create access to the file system was denied.NoDeleteAccessException
- in case create access to the file system was denied.IllegalKeyException
- in case the key with name and path is not valid, i.e. the name contains a path separator.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)NoListAccessException
- in case listing the content in the file system was denied.IllegalFileHandleException
- in case the file handle with name and path is not valid, i.e. the name contains a path separator.
-
deleteFile
public void deleteFile(FileHandle aFileHandle) throws ConcurrentAccessException, UnknownFileException, NoDeleteAccessException, UnknownFileSystemException, IOException, NoListAccessException, IllegalFileHandleException Deletes a file (handle) from the file system. In case a path is "empty" after deletion then the path will stop existing as well.- Specified by:
deleteFile
in interfaceFileSystem
- Parameters:
aFileHandle
- The file (handle) to be deleted.- Throws:
ConcurrentAccessException
- in case the file (handle) is concurrently read, modified or deleted.UnknownFileException
- in case none such file (handle) was found in the file system.NoDeleteAccessException
- in case create access to the file system was denied.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)NoListAccessException
- in case listing the content in the file system was denied.IllegalFileHandleException
- in case the file handle with name and path is not valid, i.e. the name contains a path separator.
-
hasFiles
public boolean hasFiles(String aPath, boolean isRecursively) throws NoListAccessException, IllegalPathException, UnknownFileSystemException, IOException Determines whether there is any file (handle)s found for the given path. In case the recursive flag is set, then the specified path and all children of that path (separated by the path separator) are examined, else exactly the specified path is examined. Speaking of a set recursive flag, it is merely checked whether the given path is part of any key of the file (handle)s stored in the file system by taking the path separators into account. I.e. the given path must match a key from the beginning till the end of the path and the key must either continue from then on with a path separator as next character or must end there (be equal to the path). I.e. matches in between a key where the next position of the key does not contain a path separator are ignored. Example: A given path is "/a/bc/def", a given key is "a/bc/defg", the path does not match the key, although the path is contained in the key! A given path is "/a/bc/def", a given key is "a/bc/def/g", the path does match the key as the key continues the path with a path separator "/".- Specified by:
hasFiles
in interfaceFileSystem
- Parameters:
aPath
- The path where to look whether there are file (handle)s or not.isRecursively
- When true all children of that path are examined as well.- Returns:
- True in case file (handle)s were found.
- Throws:
NoListAccessException
- in case listing the content in the file system was denied.IllegalPathException
- in case the path was not a valid path.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)
-
getFileHandles
public List<FileHandle> getFileHandles(String aPath, boolean isRecursively) throws NoListAccessException, UnknownPathException, IllegalPathException, UnknownFileSystemException, IOException With the behavior of theFileSystem.hasFiles(String, boolean)
method, all file (handle)s found for the path are returned. Ehttps://www.metacodes.proly the recursive flag is described in the methodFileSystem.hasFiles(String, boolean)
.- Specified by:
getFileHandles
in interfaceFileSystem
- Parameters:
aPath
- The path where to search for the file (handle)s.isRecursively
- the is recursively- Returns:
- A list with the file (handle)s found or an empty list.
- Throws:
NoListAccessException
- in case listing the content in the file system was denied.UnknownPathException
- in case the given path did not exist in the file system.IllegalPathException
- in case the path was not a valid path.UnknownFileSystemException
- in case the "underlying" (physical) file system is not known (may not exist any more), i.e. it may have been removed after the file system instance has been created.IOException
- in case an I/O related problem occurred while accessing the file (handle)
-
destroy
public void destroy()- Specified by:
destroy
in interfaceorg.refcodes.component.Destroyable
-