Class Configuration.Builder

java.lang.Object
be.imgn.gaia.memfs.Configuration.Builder
Enclosing class:
Configuration

public static final class Configuration.Builder extends Object
A builder of Configurations.
Since:
0.1.1
  • Method Details

    • roots

      public Configuration.Builder roots(String first, String... more)
      Sets the root directories. A Unix-style file system has the one root /; a Windows-style one has drives, such as C:\, and UNC shares, such as \\server\share\.
      Parameters:
      first - the first root
      more - the other roots
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if a root is not the root of an absolute path of the style, is given twice, or a Unix-style file system is given another root than /
    • workingDirectory

      public Configuration.Builder workingDirectory(String path)
      Sets the working directory, which relative paths are resolved against. It is created with the file system, with the directories it is in.
      Parameters:
      path - the absolute path of the directory, on one of the roots
      Returns:
      this builder
    • blockSize

      public Configuration.Builder blockSize(int bytes)
      Sets the size of the blocks the content of files is stored in.
      Parameters:
      bytes - the block size, in bytes
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the size is not positive
    • maxSize

      public Configuration.Builder maxSize(long bytes)
      Sets the capacity of the file system. Writing past it throws a FileSystemException.
      Parameters:
      bytes - the capacity, in bytes
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the capacity is not positive
    • nameMatching

      public Configuration.Builder nameMatching(NameMatching matching)
      Sets how names are matched when files are looked up.
      Parameters:
      matching - the name matching
      Returns:
      this builder
    • unicodeNormalization

      public Configuration.Builder unicodeNormalization(@Nullable Normalizer.Form form)
      Sets the Unicode normalization names are matched under: with any form, a name written with composed or decomposed characters names the same file. Names are still shown as they were created.
      Parameters:
      form - the normalization form, or null to match names as they are
      Returns:
      this builder
    • attributeViews

      public Configuration.Builder attributeViews(String... views)
      Sets the supported attribute views: any of basic, owner, posix, unix, dos, acl and user. The file system also supports basic and the views these extend, as posix extends owner.
      Parameters:
      views - the names of the views
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if a view is unknown
    • defaultAttribute

      public Configuration.Builder defaultAttribute(String attribute, Object value)
      Sets an attribute new files get unless they are given it: owner:owner (a user name), posix:group (a group name), posix:permissions (a Set<PosixFilePermission> or a string such as rw-r--r--), dos:readonly, dos:hidden, dos:system or dos:archive (a Boolean), or acl:acl (a List<AclEntry>). Its view must be supported when the configuration is built.
      Parameters:
      attribute - the attribute, as view:name
      value - the value
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the attribute is not one of these, or the value has the wrong type
    • clock

      public Configuration.Builder clock(InstantSource source)
      Sets the clock that dates the creation, modification and access of files.
      Parameters:
      source - the clock
      Returns:
      this builder
    • watchServicePollingInterval

      public Configuration.Builder watchServicePollingInterval(Duration interval)
      Sets how often a watch service looks for changes in the directories it watches.
      Parameters:
      interval - the interval
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the interval is not positive
    • features

      public Configuration.Builder features(Feature... supported)
      Sets the optional features the file system has; it lacks the others.
      Parameters:
      supported - the features
      Returns:
      this builder
    • maxNameLength

      public Configuration.Builder maxNameLength(int characters)
      Sets how long a name may be. Creating a file with a longer name throws a FileSystemException.
      Parameters:
      characters - the maximum length, in characters
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the length is not positive
    • currentUser

      public Configuration.Builder currentUser(String user, String... groups)
      Enforces permissions, checking them against a user and their groups. The files the user creates belong to them and to their first group, unless owner:owner and posix:group have defaults.
      Parameters:
      user - the user name
      groups - the groups of the user
      Returns:
      this builder
    • noCurrentUser

      public Configuration.Builder noCurrentUser()
      Stops enforcing permissions. They are still stored.
      Returns:
      this builder
    • build

      public Configuration build()
      Builds the configuration.
      Returns:
      the configuration
      Throws:
      IllegalArgumentException - if the working directory is not an absolute path on one of the roots, the block size is larger than the capacity, or a default attribute is of a view that is not supported