Class FileSystemConnection
- java.lang.Object
-
- com.aquima.interactions.foundation.connectivity.impl.FileSystemConnection
-
- All Implemented Interfaces:
IConnection
,IFileSystemConnection
public class FileSystemConnection extends Object implements IFileSystemConnection
This FileSystemConnection is used to write, update and delete files and folders to the file system.- Since:
- 9.3
- Author:
- J. Hermus, G. der Kinderen
-
-
Constructor Summary
Constructors Constructor Description FileSystemConnection(String name, String basePath)
Constructs a new instance, without having any interaction with the actual file system.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
createFile(String path, InputStream stream)
This method creates a file and writes it to the file system.void
createFolder(String path)
This method creates a new folder relative to the base path.void
createOrUpdateFile(String path, InputStream stream)
This method updates an existing file or otherwise creates it, if it doesn't exist.void
deleteFile(String path)
This method deleted a file relative to the base path.void
deleteFolder(String path)
This method deletes a folder relative to the base path.protected void
ensureDirectoryExists(File directory)
Creates all directories and subdirectories in the specified path unless they already exist.long
getFileSize(String path)
This method returns the size of a file in bytes.String
getName()
This method returns the name of the connection object.ConnectionType
getType()
This method returns the type of the connection object.byte[]
readBytes(String path)
Returns the entire content of the file into a byte array.int
readBytes(String path, long position, byte[] buffer, int offset, int length)
Reads up tolength
bytes of data from a file in this connection into an array of bytes.void
updateFile(String path, InputStream stream)
This method updates a file, that is relative to the base path.
-
-
-
Constructor Detail
-
FileSystemConnection
public FileSystemConnection(String name, String basePath)
Constructs a new instance, without having any interaction with the actual file system.- Parameters:
name
- An identifier for this connection (cannot benull
or an empty String).basePath
- The absolute base path that is used as the context of all (relative) operations performed on this connection (cannot benull
or an empty String).
-
-
Method Detail
-
getName
public String getName()
Description copied from interface:IConnection
This method returns the name of the connection object. The name is used to uniquely identify the connection object.- Specified by:
getName
in interfaceIConnection
- Returns:
- the name of the connection object.
-
getType
public ConnectionType getType()
Description copied from interface:IConnection
This method returns the type of the connection object.- Specified by:
getType
in interfaceIConnection
- Returns:
- the type of the connection object.
-
ensureDirectoryExists
protected void ensureDirectoryExists(File directory)
Creates all directories and subdirectories in the specified path unless they already exist. Note that this path is an absolute path, not relative to basePath.- Parameters:
directory
- The directory to create (cannot benull
).
-
createFile
public void createFile(String path, InputStream stream) throws FileException
Description copied from interface:IFileSystemConnection
This method creates a file and writes it to the file system.- Specified by:
createFile
in interfaceIFileSystemConnection
- Parameters:
path
- The location where the file needs to be stored, relative to the basePath (cannot be null or an empty String).stream
- The file as an input stream of bytes that needs to be stored (cannot be null).- Throws:
FileException
-
readBytes
public byte[] readBytes(String path) throws FileException
Description copied from interface:IFileSystemConnection
Returns the entire content of the file into a byte array.- Specified by:
readBytes
in interfaceIFileSystemConnection
- Parameters:
path
- The path reference of the file that should be read (cannot be null or an empty String).- Returns:
- a byte array (never null).
- Throws:
FileException
-
readBytes
public int readBytes(String path, long position, byte[] buffer, int offset, int length) throws FileException
Description copied from interface:IFileSystemConnection
Reads up tolength
bytes of data from a file in this connection into an array of bytes. The method blocks until some input is available.- Specified by:
readBytes
in interfaceIFileSystemConnection
- Parameters:
path
- The path reference of the file that should be read (cannot be null or an empty String).position
- the start offset in the source content.buffer
- the buffer into which the data is read (may not be null).offset
- the start offset in the destination arraybuffer
- Returns:
- the total number of bytes read into the buffer, or
-1
if there is no more data because the end of the file has been reached. - Throws:
FileException
-
getFileSize
public long getFileSize(String path) throws FileException
Description copied from interface:IFileSystemConnection
This method returns the size of a file in bytes.- Specified by:
getFileSize
in interfaceIFileSystemConnection
- Parameters:
path
- The path to the file (cannot be null or an empty String).- Returns:
- The length of the file.
- Throws:
FileException
-
deleteFile
public void deleteFile(String path) throws FileException
Description copied from interface:IFileSystemConnection
This method deleted a file relative to the base path.- Specified by:
deleteFile
in interfaceIFileSystemConnection
- Parameters:
path
- The path to the file that needs to be deleted (cannot be null or an empty String).- Throws:
FileException
-
updateFile
public void updateFile(String path, InputStream stream) throws FileException
Description copied from interface:IFileSystemConnection
This method updates a file, that is relative to the base path.- Specified by:
updateFile
in interfaceIFileSystemConnection
- Parameters:
path
- The path to the file that needs to be updated or created (cannot be null or an empty String).stream
- The inputStream that contains the new content (cannot be null).- Throws:
FileException
-
createOrUpdateFile
public void createOrUpdateFile(String path, InputStream stream) throws FileException
Description copied from interface:IFileSystemConnection
This method updates an existing file or otherwise creates it, if it doesn't exist.- Specified by:
createOrUpdateFile
in interfaceIFileSystemConnection
- Parameters:
path
- The path to the file that needs to be updated (cannot be null or an empty String).stream
- The inputStream that contains the new content (cannot be null).- Throws:
FileException
-
createFolder
public void createFolder(String path) throws FileException
Description copied from interface:IFileSystemConnection
This method creates a new folder relative to the base path.- Specified by:
createFolder
in interfaceIFileSystemConnection
- Parameters:
path
- The relative path of the new folder to be created (cannot be null or an empty String).- Throws:
FileException
-
deleteFolder
public void deleteFolder(String path) throws FileException
Description copied from interface:IFileSystemConnection
This method deletes a folder relative to the base path.- Specified by:
deleteFolder
in interfaceIFileSystemConnection
- Parameters:
path
- The path to the directory that needs to be removed (cannot be null or an empty String).- Throws:
FileException
-
-