Package com.google.common.jimfs
Class Configuration.Builder
java.lang.Object
com.google.common.jimfs.Configuration.Builder
- Enclosing class:
- Configuration
Mutable builder for
Configuration
objects.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
8 KB.static final long
Equal to the configured max size.static final long
4 GB. -
Method Summary
Modifier and TypeMethodDescriptionaddAttributeProvider
(AttributeProvider provider) Adds an attribute provider for a custom view for the file system to support.build()
Creates a new immutable configuration object from this builder.setAttributeViews
(String first, String... more) Sets the attribute views the file system should support.setBlockSize
(int blockSize) Sets the block size (in bytes) for the file system to use.setDefaultAttributeValue
(String attribute, Object value) Sets the default value to use for the given file attribute when creating new files.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.setMaxSize
(long maxSize) Sets the maximum size (in bytes) for the file system's in-memory file storage.setNameCanonicalNormalization
(PathNormalization first, PathNormalization... more) Returns the normalizations that will be applied to the canonical form of filenames in the file system.setNameDisplayNormalization
(PathNormalization first, PathNormalization... more) Sets the normalizations that will be applied to the display form of filenames.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.Sets the roots for the file system.setSupportedFeatures
(Feature... features) Sets the given features to be supported by the file system.Sets the configuration thatWatchService
instances created by the file system should use.setWorkingDirectory
(String workingDirectory) Sets the path to the working directory for the file system.
-
Field Details
-
DEFAULT_BLOCK_SIZE
public static final int DEFAULT_BLOCK_SIZE8 KB.- See Also:
-
DEFAULT_MAX_SIZE
public static final long DEFAULT_MAX_SIZE4 GB.- See Also:
-
DEFAULT_MAX_CACHE_SIZE
public static final long DEFAULT_MAX_CACHE_SIZEEqual to the configured max size.- See Also:
-
-
Method Details
-
setNameDisplayNormalization
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
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. -
setPathEqualityUsesCanonicalForm
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
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
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
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
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
Adds an attribute provider for a custom view for the file system to support. -
setDefaultAttributeValue
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>
-
setRoots
Sets the roots for the file system.- Throws:
InvalidPathException
- if any of the given roots is not a valid path for this builder's path typeIllegalArgumentException
- 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
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:
InvalidPathException
- if the given path is not valid for this builder's path typeIllegalArgumentException
- if the given path is valid for this builder's path type but is not an absolute path
-
setSupportedFeatures
Sets the given features to be supported by the file system. Any features not provided here will not be supported. -
setWatchServiceConfiguration
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
-
build
Creates a new immutable configuration object from this builder.
-