Class MemoryFileSystemBuilder
- java.lang.Object
-
- com.github.marschall.memoryfilesystem.MemoryFileSystemBuilder
-
public final class MemoryFileSystemBuilder extends Object
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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description MemoryFileSystemBuilder
addFileAttributeView(Class<? extends FileAttributeView> fileAttributeView)
Adds support for an attribute view.MemoryFileSystemBuilder
addFileAttributeView(String fileAttributeViewName)
Adds support for an attribute view.MemoryFileSystemBuilder
addForbiddenCharacter(char c)
Forbids a character to be used in a name.MemoryFileSystemBuilder
addGroup(String groupName)
Adds a group to the file systemsUserPrincipalLookupService
.MemoryFileSystemBuilder
addRoot(String root)
Add a file system root.MemoryFileSystemBuilder
addUser(String userName)
Adds a user and a group to the file systemsUserPrincipalLookupService
.FileSystem
build()
Creates the new file system instance.FileSystem
build(String name)
Creates the new file system instance.Map<String,?>
buildEnvironment()
Builds an environment to pass toFileSystems.newFileSystem(URI, Map)
.static MemoryFileSystemBuilder
newEmpty()
Creates a builder for a very basic file system.static MemoryFileSystemBuilder
newLinux()
Creates a builder for a Linux-like file system.static MemoryFileSystemBuilder
newMacOs()
Creates a builder for a macOS-like file system.static MemoryFileSystemBuilder
newMacOsOldJvm()
Creates a builder for a macOS-like file system for old JVMs.static MemoryFileSystemBuilder
newWindows()
Creates a builder for a Windows-like file system.MemoryFileSystemBuilder
setCaseSensitive(boolean caseSensitive)
Toggles case sensitivity.MemoryFileSystemBuilder
setCollator(Collator collator)
Sets the collator used for name comparisons.MemoryFileSystemBuilder
setCurrentWorkingDirectory(String currentWorkingDirectory)
Sets the current working directory used for resolving relative paths.MemoryFileSystemBuilder
setLocale(Locale locale)
Sets the locale to be used for case insensitivity.MemoryFileSystemBuilder
setLookUpTransformer(StringTransformer lookUpTransformer)
Sets the transformer that controls how a file name is looked up.MemoryFileSystemBuilder
setSeparator(String separator)
Sets the the name separator.MemoryFileSystemBuilder
setSeprator(String separator)
Deprecated.MemoryFileSystemBuilder
setStoreTransformer(StringTransformer storeTransformer)
Sets the transformer that controls how a file name is stored.MemoryFileSystemBuilder
setUmask(Set<PosixFilePermission> umask)
Sets the umask.
-
-
-
Method Detail
-
addRoot
public MemoryFileSystemBuilder addRoot(String root)
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
-
setSeprator
@Deprecated public MemoryFileSystemBuilder setSeprator(String separator)
Deprecated.Sets the the name separator.- Parameters:
separator
- the name separator, notnull
- Returns:
- the current builder object
- See Also:
FileSystem.getSeparator()
-
setSeparator
public MemoryFileSystemBuilder setSeparator(String separator)
Sets the the name separator.- Parameters:
separator
- the name separator, notnull
- Returns:
- the current builder object
- See Also:
FileSystem.getSeparator()
-
addForbiddenCharacter
public MemoryFileSystemBuilder addForbiddenCharacter(char c)
Forbids a character to be used in a name.- Parameters:
c
- the character to forbid- Returns:
- the current builder object
-
addUser
public MemoryFileSystemBuilder addUser(String userName)
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
public MemoryFileSystemBuilder addGroup(String groupName)
Adds a group to the file systemsUserPrincipalLookupService
.- Parameters:
groupName
- the name of the group to add- Returns:
- the current builder object
-
setUmask
public MemoryFileSystemBuilder setUmask(Set<PosixFilePermission> umask)
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:
- umsaks.
-
addFileAttributeView
public MemoryFileSystemBuilder addFileAttributeView(String fileAttributeViewName)
Adds support for an attribute view.- Parameters:
fileAttributeViewName
- the name of the attribute view to add- Returns:
- the current builder object
- See Also:
AttributeView.name()
-
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
public MemoryFileSystemBuilder setCurrentWorkingDirectory(String currentWorkingDirectory)
Sets the current working directory used for resolving relative paths.- Parameters:
currentWorkingDirectory
- path of the current working directory- Returns:
- the current builder object
-
setStoreTransformer
public MemoryFileSystemBuilder setStoreTransformer(StringTransformer storeTransformer)
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
public MemoryFileSystemBuilder setLocale(Locale locale)
Sets the locale to be used for case insensitivity.- Parameters:
locale
- for case insensitivity- Returns:
- the current builder object
- See Also:
setCaseSensitive(boolean)
-
setCaseSensitive
public MemoryFileSystemBuilder setCaseSensitive(boolean caseSensitive)
Toggles case sensitivity.- Parameters:
caseSensitive
- whether the file names should be case sensitive- Returns:
- the current builder object
- See Also:
setLocale(Locale)
-
setLookUpTransformer
public MemoryFileSystemBuilder setLookUpTransformer(StringTransformer lookUpTransformer)
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
public MemoryFileSystemBuilder setCollator(Collator collator)
Sets the collator used for name comparisons.- Parameters:
collator
- the collator for name comparisons- Returns:
- the current builder object
-
newEmpty
public static MemoryFileSystemBuilder 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
public static MemoryFileSystemBuilder 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 PosixFileAttributeView
is added as an attribute view- the current working directory is
"/home/${user.name}"
- the file system is case sensitive
0x00
is not allowed in file names
- Returns:
- the builder
-
newMacOs
public static MemoryFileSystemBuilder 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 PosixFileAttributeView
is 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
0x00
is not allowed in file names
- Returns:
- the builder
-
newMacOsOldJvm
public static MemoryFileSystemBuilder 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 PosixFileAttributeView
is 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
0x00
is not allowed in file names
- Returns:
- the builder
-
newWindows
public static MemoryFileSystemBuilder newWindows()
Creates a builder for a Windows-like file system.The file system has the following properties:
- the 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 DosFileAttributeView
is added as an attribute view- the current working directory is
"C:\\Users\\${user.name}"
- the file system is case insensitive and case case preserving
'\\'
,'/'
,':'
,'*'
,'?'
,'"'
,'<'
,'<'
and'|'
and not allowed in file names
- Returns:
- the builder
- the root is
-
build
public FileSystem build(String name) throws IOException
Creates the new file system instance.- Parameters:
name
- the name, must be unique otherwise aFileSystemAlreadyExistsException
will be thrown- Returns:
- the file system
- Throws:
IOException
- if the file system can't be created- See Also:
FileSystems.newFileSystem(URI, Map, ClassLoader)
-
build
public FileSystem build() throws IOException
Creates the new file system instance.- Returns:
- the file system
- Throws:
IOException
- if the file system can't be created- See Also:
FileSystems.newFileSystem(URI, Map, ClassLoader)
-
buildEnvironment
public Map<String,?> buildEnvironment()
Builds an environment to pass toFileSystems.newFileSystem(URI, Map)
.- Returns:
- the environment
-
-