Package de.xima.fc.common.filesystem
Class CommonFileSystems
- java.lang.Object
-
- de.xima.fc.common.filesystem.CommonFileSystems
-
public final class CommonFileSystems extends Object
Helper methods forICommonFileSystem
.- Since:
- 8.3.0
- Author:
- XIMA MEDIA GmbH
-
-
Field Summary
Fields Modifier and Type Field Description static String
PROTOCOL_VOLUME_GROUP
The special protocol for volume groups, i.e.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <FD> byte[]
getFileData(ICommonFileSystem<FD> fileSystem, FD file)
Gets the data for the file with the given key.static <FD> String
getFileText(ICommonFileSystem<FD> fileSystem, FD file, Charset charset)
Gets the text content of the file with the given key.static <FD extends IFileSystemEntry<?>>
ICommonFileSystem<FD>rootOnlyFileSystem()
Gets a read-only file system that does not contain any files, other than the root file descriptor.static <FD> void
setFileData(ICommonFileSystem<FD> fileSystem, FD file, byte[] data)
Sets the data for the file with the given key.static <FD> void
setFileData(ICommonFileSystem<FD> fileSystem, FD file, InputStream data)
Sets the data for the file with the given key.static <FD> void
setFileText(ICommonFileSystem<FD> fileSystem, FD file, String text, Charset charset)
Sets the text content of the file with the given key.static <FD> ICommonFileSystem<FD>
simpleDiskCachedFileSystem(ICommonFileSystem<FD> delegate, ISerializableThrowingSupplier<Path> tempFileCreator)
Wraps an existing file system in a cached file system stores the file content on the disk temporarily, so it does have to be read from the original file system each time.static <FD> ICommonFileSystem<FD>
synchronizedFileSystem(ICommonFileSystem<FD> delegate, int concurrencyLevel)
Wraps an existing file system in a synchronized file system that locks the files for each operation.static <FD> CommonFileSystemVolumeBuilder<FD>
volumeBuilder(String protocol, String volumeId, ISerializableBiFunction<String,String,FD> entryFactory)
Creates a new builder for a file system volume.static <FD> ICommonFileSystemVolume<FD>
volumeGroup(String volumeId, FD root)
Creates a new file system volume group.static <FD> CommonFileSystemVolumeBuilder<FD>
volumeGroupBuilder(String volumeId, FD root)
Creates a new builder for a file system volume group.
-
-
-
Field Detail
-
PROTOCOL_VOLUME_GROUP
public static final String PROTOCOL_VOLUME_GROUP
The special protocol for volume groups, i.e. volumes that do not contain any files, but can be used as the parent of other volumes to group them together.- See Also:
- Constant Field Values
-
-
Method Detail
-
rootOnlyFileSystem
public static <FD extends IFileSystemEntry<?>> ICommonFileSystem<FD> rootOnlyFileSystem()
Gets a read-only file system that does not contain any files, other than the root file descriptor.- Type Parameters:
FD
- The type of the file descriptors.- Returns:
- The file system representing the volume group.
-
getFileData
public static <FD> byte[] getFileData(ICommonFileSystem<FD> fileSystem, FD file) throws IOException
Gets the data for the file with the given key. If the file does not exist, or if the file data is not available, an empty byte array is returned.- Type Parameters:
FD
- Type of the file descriptors.- Parameters:
fileSystem
- The file system from which to read the data.file
- The file descriptor.- Returns:
- The data for the file, or an empty byte array if the file does not exist or the data is not available.
- Throws:
IOException
- If an error occurs while reading the file data from the temporary file.
-
getFileText
public static <FD> String getFileText(ICommonFileSystem<FD> fileSystem, FD file, Charset charset) throws IOException
Gets the text content of the file with the given key. If the file does not exist, or if the file data is not available, an empty string is returned.- Type Parameters:
FD
- Type of the file descriptors.- Parameters:
fileSystem
- The file system from which to read the data.file
- The file descriptor.charset
- The charset to use for decoding the file data.- Returns:
- The text content of the file, or an empty string if the file does not exist or the data is not available.
- Throws:
IOException
- If an error occurs while reading the file data from the temporary file.
-
setFileData
public static <FD> void setFileData(ICommonFileSystem<FD> fileSystem, FD file, byte[] data) throws IOException
Sets the data for the file with the given key. If no file exists yet, it is created.- Type Parameters:
FD
- Type of the file descriptors.- Parameters:
fileSystem
- The file system to which to write the data.file
- The file descriptor.data
- The data to set. null is treated as an empty byte array.- Throws:
IOException
- If an error occurs while writing the file data to the temporary file.
-
setFileData
public static <FD> void setFileData(ICommonFileSystem<FD> fileSystem, FD file, InputStream data) throws IOException
Sets the data for the file with the given key. If no file exists yet, it is created.- Type Parameters:
FD
- Type of the file descriptors.- Parameters:
fileSystem
- The file system to which to write the data.file
- The file descriptor.data
- The data to set. null is treated as an empty byte array.- Throws:
IOException
- If an error occurs while writing the file data to the temporary file.
-
setFileText
public static <FD> void setFileText(ICommonFileSystem<FD> fileSystem, FD file, String text, Charset charset) throws IOException
Sets the text content of the file with the given key. If no file exists yet, it is created.- Type Parameters:
FD
- Type of the file descriptors.- Parameters:
fileSystem
- The file system to which to write the data.file
- The file descriptor.text
- The text to set. null is treated as an empty string.charset
- The charset to use for encoding the text.- Throws:
IOException
- If an error occurs while writing the file data to the temporary file.
-
simpleDiskCachedFileSystem
public static <FD> ICommonFileSystem<FD> simpleDiskCachedFileSystem(ICommonFileSystem<FD> delegate, ISerializableThrowingSupplier<Path> tempFileCreator)
Wraps an existing file system in a cached file system stores the file content on the disk temporarily, so it does have to be read from the original file system each time.- Type Parameters:
FD
- The type of the file descriptors.- Parameters:
delegate
- The file system to wrap.tempFileCreator
- The creator for creating temporary files that will hold the file content.- Returns:
- A cached file system.
-
synchronizedFileSystem
public static <FD> ICommonFileSystem<FD> synchronizedFileSystem(ICommonFileSystem<FD> delegate, int concurrencyLevel)
Wraps an existing file system in a synchronized file system that locks the files for each operation. You can specify the concurrency level to limit the number of concurrent file operations.- Type Parameters:
FD
- The type of the file descriptors.- Parameters:
delegate
- The file system to wrap.concurrencyLevel
- The concurrency level to limit the number of concurrent file operations.- Returns:
- The synchronized file system.
-
volumeBuilder
public static <FD> CommonFileSystemVolumeBuilder<FD> volumeBuilder(String protocol, String volumeId, ISerializableBiFunction<String,String,FD> entryFactory)
Creates a new builder for a file system volume.- Type Parameters:
FD
- The type of the file descriptors.- Parameters:
protocol
- The protocol of the file system, such as "file" for a local file system, "ftp" for FTP, or "smb" for Samba. The protocol is arbitrary and can be any string that is recognized by theICommonFileSystem
implementation.volumeId
- The ID of the volume, must be unique among all volumes.entryFactory
- Factory for creating file descriptors. The first arguments is the volume ID, the second argument is the file path.- Returns:
- A new builder for a file system volume.
-
volumeGroup
public static <FD> ICommonFileSystemVolume<FD> volumeGroup(String volumeId, FD root)
Creates a new file system volume group. A volume group is a virtual volume that contains multiple volumes, but does not contain any files.- Type Parameters:
FD
- The type of the file descriptors.- Parameters:
volumeId
- The ID of the volume, must be unique among all volumes.root
- The root file descriptor for the volume group.- Returns:
- A new builder for a file system volume.
-
volumeGroupBuilder
public static <FD> CommonFileSystemVolumeBuilder<FD> volumeGroupBuilder(String volumeId, FD root)
Creates a new builder for a file system volume group. A volume group is a virtual volume that contains multiple volumes, but does not contain any files.- Type Parameters:
FD
- The type of the file descriptors.- Parameters:
volumeId
- The ID of the volume, must be unique among all volumes.root
- The root file descriptor for the volume group.- Returns:
- A new builder for a file system volume.
-
-