Package com.google.common.jimfs
Class Configuration.Builder
- java.lang.Object
-
- com.google.common.jimfs.Configuration.Builder
-
- Enclosing class:
- Configuration
public static final class Configuration.Builder extends java.lang.Object
Mutable builder forConfiguration
objects.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.regex.Pattern
ATTRIBUTE_PATTERN
private java.util.Set<AttributeProvider>
attributeProviders
private com.google.common.collect.ImmutableSet<java.lang.String>
attributeViews
private int
blockSize
static int
DEFAULT_BLOCK_SIZE
8 KB.static long
DEFAULT_MAX_CACHE_SIZE
Equal to the configured max size.static long
DEFAULT_MAX_SIZE
4 GB.private java.util.Map<java.lang.String,java.lang.Object>
defaultAttributeValues
private java.lang.String
displayName
private FileTimeSource
fileTimeSource
private long
maxCacheSize
private long
maxSize
private com.google.common.collect.ImmutableSet<PathNormalization>
nameCanonicalNormalization
private com.google.common.collect.ImmutableSet<PathNormalization>
nameDisplayNormalization
private boolean
pathEqualityUsesCanonicalForm
private PathType
pathType
private com.google.common.collect.ImmutableSet<java.lang.String>
roots
private com.google.common.collect.ImmutableSet<Feature>
supportedFeatures
private WatchServiceConfiguration
watchServiceConfig
private java.lang.String
workingDirectory
-
Constructor Summary
Constructors Modifier Constructor Description private
Builder(Configuration configuration)
private
Builder(PathType pathType)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Configuration.Builder
addAttributeProvider(AttributeProvider provider)
Adds an attribute provider for a custom view for the file system to support.Configuration
build()
Creates a new immutable configuration object from this builder.private static void
checkNormalizationNotSet(PathNormalization n, @Nullable PathNormalization set)
private com.google.common.collect.ImmutableSet<PathNormalization>
checkNormalizations(java.util.List<PathNormalization> normalizations)
Configuration.Builder
setAttributeViews(java.lang.String first, java.lang.String... more)
Sets the attribute views the file system should support.Configuration.Builder
setBlockSize(int blockSize)
Sets the block size (in bytes) for the file system to use.Configuration.Builder
setDefaultAttributeValue(java.lang.String attribute, java.lang.Object value)
Sets the default value to use for the given file attribute when creating new files.private Configuration.Builder
setDisplayName(java.lang.String displayName)
Configuration.Builder
setFileTimeSource(FileTimeSource source)
Sets theFileTimeSource
that will supply the current time for this file system.Configuration.Builder
setMaxCacheSize(long maxCacheSize)
Sets the maximum amount of unused space (in bytes) in the file system's in-memory file storage that should be cached for reuse.Configuration.Builder
setMaxSize(long maxSize)
Sets the maximum size (in bytes) for the file system's in-memory file storage.Configuration.Builder
setNameCanonicalNormalization(PathNormalization first, PathNormalization... more)
Returns the normalizations that will be applied to the canonical form of filenames in the file system.Configuration.Builder
setNameDisplayNormalization(PathNormalization first, PathNormalization... more)
Sets the normalizations that will be applied to the display form of filenames.Configuration.Builder
setPathEqualityUsesCanonicalForm(boolean useCanonicalForm)
Sets whetherPath
objects in the file system use the canonical form (true) or the display form (false) of filenames for determining equality of two paths.Configuration.Builder
setRoots(java.lang.String first, java.lang.String... more)
Sets the roots for the file system.Configuration.Builder
setSupportedFeatures(Feature... features)
Sets the given features to be supported by the file system.Configuration.Builder
setWatchServiceConfiguration(WatchServiceConfiguration config)
Sets the configuration thatWatchService
instances created by the file system should use.Configuration.Builder
setWorkingDirectory(java.lang.String workingDirectory)
Sets the path to the working directory for the file system.
-
-
-
Field Detail
-
DEFAULT_BLOCK_SIZE
public static final int DEFAULT_BLOCK_SIZE
8 KB.- See Also:
- Constant Field Values
-
DEFAULT_MAX_SIZE
public static final long DEFAULT_MAX_SIZE
4 GB.- See Also:
- Constant Field Values
-
DEFAULT_MAX_CACHE_SIZE
public static final long DEFAULT_MAX_CACHE_SIZE
Equal to the configured max size.- See Also:
- Constant Field Values
-
pathType
private final PathType pathType
-
nameDisplayNormalization
private com.google.common.collect.ImmutableSet<PathNormalization> nameDisplayNormalization
-
nameCanonicalNormalization
private com.google.common.collect.ImmutableSet<PathNormalization> nameCanonicalNormalization
-
pathEqualityUsesCanonicalForm
private boolean pathEqualityUsesCanonicalForm
-
blockSize
private int blockSize
-
maxSize
private long maxSize
-
maxCacheSize
private long maxCacheSize
-
attributeViews
private com.google.common.collect.ImmutableSet<java.lang.String> attributeViews
-
attributeProviders
private java.util.Set<AttributeProvider> attributeProviders
-
defaultAttributeValues
private java.util.Map<java.lang.String,java.lang.Object> defaultAttributeValues
-
fileTimeSource
private FileTimeSource fileTimeSource
-
watchServiceConfig
private WatchServiceConfiguration watchServiceConfig
-
roots
private com.google.common.collect.ImmutableSet<java.lang.String> roots
-
workingDirectory
private java.lang.String workingDirectory
-
supportedFeatures
private com.google.common.collect.ImmutableSet<Feature> supportedFeatures
-
displayName
private java.lang.String displayName
-
ATTRIBUTE_PATTERN
private static final java.util.regex.Pattern ATTRIBUTE_PATTERN
-
-
Constructor Detail
-
Builder
private Builder(PathType pathType)
-
Builder
private Builder(Configuration configuration)
-
-
Method Detail
-
setNameDisplayNormalization
@CanIgnoreReturnValue public Configuration.Builder setNameDisplayNormalization(PathNormalization first, PathNormalization... more)
Sets the normalizations that will be applied to the display form of filenames. The display form is used in thetoString()
ofPath
objects.
-
setNameCanonicalNormalization
@CanIgnoreReturnValue public Configuration.Builder setNameCanonicalNormalization(PathNormalization first, PathNormalization... more)
Returns the normalizations that will be applied to the canonical form of filenames in the file system. The canonical form is used to determine the equality of two filenames when performing a file lookup.
-
checkNormalizations
private com.google.common.collect.ImmutableSet<PathNormalization> checkNormalizations(java.util.List<PathNormalization> normalizations)
-
checkNormalizationNotSet
private static void checkNormalizationNotSet(PathNormalization n, @Nullable PathNormalization set)
-
setPathEqualityUsesCanonicalForm
@CanIgnoreReturnValue public Configuration.Builder setPathEqualityUsesCanonicalForm(boolean useCanonicalForm)
Sets whetherPath
objects in the file system use the canonical form (true) or the display form (false) of filenames for determining equality of two paths.The default is false.
-
setBlockSize
@CanIgnoreReturnValue public Configuration.Builder setBlockSize(int blockSize)
Sets the block size (in bytes) for the file system to use. All regular files will be allocated blocks of the given size, so this is the minimum granularity for file size.The default is 8192 bytes (8 KB).
-
setMaxSize
@CanIgnoreReturnValue public Configuration.Builder setMaxSize(long maxSize)
Sets the maximum size (in bytes) for the file system's in-memory file storage. This maximum size determines the maximum number of blocks that can be allocated to regular files, so it should generally be a multiple of the block size. The actual maximum size will be the nearest multiple of the block size that is less than or equal to the given size.Note: The in-memory file storage will not be eagerly initialized to this size, so it won't use more memory than is needed for the files you create. Also note that in addition to this limit, you will of course be limited by the amount of heap space available to the JVM and the amount of heap used by other objects, both in the file system and elsewhere.
The default is 4 GB.
-
setMaxCacheSize
@CanIgnoreReturnValue public Configuration.Builder setMaxCacheSize(long maxCacheSize)
Sets the maximum amount of unused space (in bytes) in the file system's in-memory file storage that should be cached for reuse. By default, this will be equal to the maximum size of the storage, meaning that all space that is freed when files are truncated or deleted is cached for reuse. This helps to avoid lots of garbage collection when creating and deleting many files quickly. This can be set to 0 to disable caching entirely (all freed blocks become available for garbage collection) or to some other number to put an upper bound on the maximum amount of unused space the file system will keep around.Like the maximum size, the actual value will be the closest multiple of the block size that is less than or equal to the given size.
-
setAttributeViews
@CanIgnoreReturnValue public Configuration.Builder setAttributeViews(java.lang.String first, java.lang.String... more)
Sets the attribute views the file system should support. By default, the following views may be specified:Name View Interface Attributes Interface "basic"
BasicFileAttributeView
BasicFileAttributes
"owner"
FileOwnerAttributeView
-- "posix"
PosixFileAttributeView
PosixFileAttributes
"unix"
-- -- "dos"
DosFileAttributeView
DosFileAttributes
"acl"
AclFileAttributeView
-- "user"
UserDefinedFileAttributeView
-- If any other views should be supported, attribute providers for those views must be added.
-
addAttributeProvider
@CanIgnoreReturnValue public Configuration.Builder addAttributeProvider(AttributeProvider provider)
Adds an attribute provider for a custom view for the file system to support.
-
setDefaultAttributeValue
@CanIgnoreReturnValue public Configuration.Builder setDefaultAttributeValue(java.lang.String attribute, java.lang.Object value)
Sets the default value to use for the given file attribute when creating new files. The attribute must be in the form "view:attribute". The value must be of a type that the provider for the view accepts.For the included attribute views, default values can be set for the following attributes:
Attribute Legal Types "owner:owner"
String
(user name)"posix:group"
String
(group name)"posix:permissions"
String
(format "rwxrw-r--"),Set<PosixFilePermission>
"dos:readonly"
Boolean
"dos:hidden"
Boolean
"dos:archive"
Boolean
"dos:system"
Boolean
"acl:acl"
List<AclEntry>
-
setFileTimeSource
@CanIgnoreReturnValue public Configuration.Builder setFileTimeSource(FileTimeSource source)
Sets theFileTimeSource
that will supply the current time for this file system.- Since:
- 1.3
-
setRoots
@CanIgnoreReturnValue public Configuration.Builder setRoots(java.lang.String first, java.lang.String... more)
Sets the roots for the file system.- Throws:
java.nio.file.InvalidPathException
- if any of the given roots is not a valid path for this builder's path typejava.lang.IllegalArgumentException
- if any of the given roots is a valid path for this builder's path type but is not a root path with no name elements
-
setWorkingDirectory
@CanIgnoreReturnValue public Configuration.Builder setWorkingDirectory(java.lang.String workingDirectory)
Sets the path to the working directory for the file system. The working directory must be an absolute path starting with one of the configured roots.- Throws:
java.nio.file.InvalidPathException
- if the given path is not valid for this builder's path typejava.lang.IllegalArgumentException
- if the given path is valid for this builder's path type but is not an absolute path
-
setSupportedFeatures
@CanIgnoreReturnValue public Configuration.Builder setSupportedFeatures(Feature... features)
Sets the given features to be supported by the file system. Any features not provided here will not be supported.
-
setWatchServiceConfiguration
@CanIgnoreReturnValue public Configuration.Builder setWatchServiceConfiguration(WatchServiceConfiguration config)
Sets the configuration thatWatchService
instances created by the file system should use. The default configuration polls watched directories for changes every 5 seconds.- Since:
- 1.1
-
setDisplayName
@CanIgnoreReturnValue private Configuration.Builder setDisplayName(java.lang.String displayName)
-
build
public Configuration build()
Creates a new immutable configuration object from this builder.
-
-