Class MemoryFileSystemBuilder
java.lang.Object
com.github.marschall.memoryfilesystem.MemoryFileSystemBuilder
Builder
for conveniently creating create memory file system instances.
The builder takes care of creating the environment and selecting
the correct class loader to pass to FileSystems.newFileSystem(URI, Map, ClassLoader).
-
Method Summary
Modifier and TypeMethodDescriptionaddFileAttributeView(Class<? extends FileAttributeView> fileAttributeView) Adds support for an attribute view.addFileAttributeView(String fileAttributeViewName) Adds support for an attribute view.addForbiddenCharacter(char c) Forbids a character to be used in a name.Adds a group to the file systemsUserPrincipalLookupService.Add a file system root.Adds a user and a group to the file systemsUserPrincipalLookupService.build()Creates the new file system instance.Creates the new file system instance.Builds an environment to pass toFileSystems.newFileSystem(URI, Map).static MemoryFileSystemBuildernewEmpty()Creates a builder for a very basic file system.static MemoryFileSystemBuildernewLinux()Creates a builder for a Linux-like file system.static MemoryFileSystemBuildernewMacOs()Creates a builder for a macOS-like file system.static MemoryFileSystemBuilderCreates a builder for a macOS-like file system for old JVMs.static MemoryFileSystemBuilderCreates a builder for a Windows-like file system.setCaseSensitive(boolean caseSensitive) Toggles case sensitivity.setCollator(Collator collator) Sets the collator used for name comparisons.setCurrentWorkingDirectory(String currentWorkingDirectory) Sets the current working directory used for resolving relative paths.setFileTimeResolution(TemporalUnit resolution) Sets the resolution of the file time used for modification, access and creation time.Sets the locale to be used for case insensitivity.setLookUpTransformer(StringTransformer lookUpTransformer) Sets the transformer that controls how a file name is looked up.setSeparator(String separator) Sets the the name separator.setStoreTransformer(StringTransformer storeTransformer) Sets the transformer that controls how a file name is stored.setSupportFileChannelOnDirectory(boolean supportFileChannelOnDirectory) Sets the support for opening a file channel for reading on a directory.setUmask(Set<PosixFilePermission> umask) Sets the umask.
-
Method Details
-
addRoot
Add a file system root.This method is intended to be used in Windows mode to add a drive letter eg.:
builder.addRoot("D:\\")- Parameters:
root- the file system root- Returns:
- the current builder object
-
setSeparator
Sets the the name separator.- Parameters:
separator- the name separator, notnull- Returns:
- the current builder object
- See Also:
-
addForbiddenCharacter
Forbids a character to be used in a name.- Parameters:
c- the character to forbid- Returns:
- the current builder object
-
addUser
Adds a user and a group to the file systemsUserPrincipalLookupService.- Parameters:
userName- the name of the user to add- Returns:
- the current builder object
-
addGroup
Adds a group to the file systemsUserPrincipalLookupService.- Parameters:
groupName- the name of the group to add- Returns:
- the current builder object
-
setUmask
Sets the umask. The umask is a set of permissions that will be removed from newly created files.- Parameters:
umask- the permissions that will be removed from newly created files- Returns:
- the current builder object
- See Also:
-
addFileAttributeView
Adds support for an attribute view.- Parameters:
fileAttributeViewName- the name of the attribute view to add- Returns:
- the current builder object
- See Also:
-
addFileAttributeView
public MemoryFileSystemBuilder addFileAttributeView(Class<? extends FileAttributeView> fileAttributeView) Adds support for an attribute view.- Parameters:
fileAttributeView- the attribute view class- Returns:
- the current builder object
-
setCurrentWorkingDirectory
Sets the current working directory used for resolving relative paths.- Parameters:
currentWorkingDirectory- path of the current working directory- Returns:
- the current builder object
-
setStoreTransformer
Sets the transformer that controls how a file name is stored.- Parameters:
storeTransformer- to apply to the file names before storing- Returns:
- the current builder object
-
setLocale
Sets the locale to be used for case insensitivity.- Parameters:
locale- for case insensitivity- Returns:
- the current builder object
- See Also:
-
setCaseSensitive
Toggles case sensitivity.- Parameters:
caseSensitive- whether the file names should be case sensitive- Returns:
- the current builder object
- See Also:
-
setLookUpTransformer
Sets the transformer that controls how a file name is looked up.- Parameters:
lookUpTransformer- to apply to the file names for lookup- Returns:
- the current builder object
-
setCollator
Sets the collator used for name comparisons.- Parameters:
collator- the collator for name comparisons- Returns:
- the current builder object
-
setFileTimeResolution
Sets the resolution of the file time used for modification, access and creation time.- Parameters:
resolution- used to truncate file times- Returns:
- the current builder object
-
setSupportFileChannelOnDirectory
public MemoryFileSystemBuilder setSupportFileChannelOnDirectory(boolean supportFileChannelOnDirectory) Sets the support for opening a file channel for reading on a directory.- Parameters:
supportFileChannelOnDirectory- whether a file channel for reading on a directory should be supported- Returns:
- the current builder object
- See Also:
-
newEmpty
Creates a builder for a very basic file system.The file system does not support permissions and only supports
BasicFileAttributeView. It is UNIX-like in the sense that is uses "/" as a separator, has a single root and is case sensitive and case preserving.- Returns:
- the builder
-
newLinux
Creates a builder for a Linux-like file system.The file system has the following properties:
- the root is "/"
- the separator is "/"
- the current user (value of the
"user.name"system property) is added as a user - the current user (value of the
"user.name"system property) is added as a group PosixFileAttributeViewis added as an attribute view- the current working directory is
"/home/${user.name}" - the file system is case sensitive
- the file file time resolution is 1ns
0x00is not allowed in file names
- Returns:
- the builder
-
newMacOs
Creates a builder for a macOS-like file system.The file system has the following properties:
- the root is "/"
- the separator is "/"
- the current user (value of the
"user.name"system property) is added as a user - the current user (value of the
"user.name"system property) is added as a group PosixFileAttributeViewis added as an attribute view- the current working directory is
"/Users/${user.name}" - the file system is case insensitive and case case preserving
- file names are normalized to NFC
- the file file time resolution is 1ns
0x00is not allowed in file names
- Returns:
- the builder
-
newMacOsOldJvm
Creates a builder for a macOS-like file system for old JVMs.The file system has the following properties:
- the root is "/"
- the separator is "/"
- the current user (value of the
"user.name"system property) is added as a user - the current user (value of the
"user.name"system property) is added as a group PosixFileAttributeViewis added as an attribute view- the current working directory is
"/Users/${user.name}" - the file system is case insensitive and case case preserving
- file names are normalized to NFD
- the file file time resolution is 1s
0x00is not allowed in file names
- Returns:
- the builder
-
newWindows
Creates a builder for a Windows-like file system.The file system has the following properties:
- the only root is
"C:\\" - the separator is "\\"
- the current user (value of the
"user.name"system property) is added as a user - the current user (value of the
"user.name"system property) is added as a group DosFileAttributeViewis added as an attribute view- the current working directory is
"C:\\Users\\${user.name}" - the file system is case insensitive and case case preserving
- the file file time resolution is 100ns
'\\','/',':','*','?','"','<','<'and'|'and not allowed in file names
Use
addRoot(String)to add additional roots.- Returns:
- the builder
- the only root is
-
build
Creates the new file system instance.- Parameters:
name- the name, must be unique otherwise aFileSystemAlreadyExistsExceptionwill be thrown- Returns:
- the file system
- Throws:
IOException- if the file system can't be created- See Also:
-
build
Creates the new file system instance.- Returns:
- the file system
- Throws:
IOException- if the file system can't be created- See Also:
-
buildEnvironment
Builds an environment to pass toFileSystems.newFileSystem(URI, Map).- Returns:
- the environment
-