Package com.google.common.jimfs
Class JimfsFileStore
- java.lang.Object
-
- java.nio.file.FileStore
-
- com.google.common.jimfs.JimfsFileStore
-
final class JimfsFileStore extends java.nio.file.FileStore
FileStore
implementation which provides methods for file creation, lookup and attribute handling.Most of these methods are actually implemented in another class:
FileTree
for lookup,FileFactory
for creating and copying files andAttributeService
for attribute handling. This class merely provides a single API through which to access the functionality of those classes.
-
-
Field Summary
Fields Modifier and Type Field Description private AttributeService
attributes
private HeapDisk
disk
private FileFactory
factory
private java.util.concurrent.locks.Lock
readLock
private FileSystemState
state
private com.google.common.collect.ImmutableSet<Feature>
supportedFeatures
private FileTree
tree
private java.util.concurrent.locks.Lock
writeLock
-
Constructor Summary
Constructors Constructor Description JimfsFileStore(FileTree tree, FileFactory factory, HeapDisk disk, AttributeService attributes, com.google.common.collect.ImmutableSet<Feature> supportedFeatures, FileSystemState state)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) File
copyWithoutContent(File file, AttributeCopyOption attributeCopyOption)
Creates a copy of the given file, copying its attributes as well according to the givenattributeCopyOption
.(package private) com.google.common.base.Supplier<Directory>
directoryCreator()
Returns a supplier that creates a new directory.java.lang.Object
getAttribute(java.lang.String attribute)
(package private) <V extends java.nio.file.attribute.FileAttributeView>
@Nullable VgetFileAttributeView(FileLookup lookup, java.lang.Class<V> type)
Returns an attribute view of the given type for the given file lookup callback, ornull
if the view type is not supported.<V extends java.nio.file.attribute.FileStoreAttributeView>
VgetFileStoreAttributeView(java.lang.Class<V> type)
(package private) @Nullable Directory
getRoot(Name name)
Returns the root directory with the given name ornull
if no such directory exists.(package private) com.google.common.collect.ImmutableSortedSet<Name>
getRootDirectoryNames()
Returns the names of the root directories in this store.long
getTotalSpace()
long
getUnallocatedSpace()
long
getUsableSpace()
boolean
isReadOnly()
(package private) DirectoryEntry
lookUp(File workingDirectory, JimfsPath path, java.util.Set<? super java.nio.file.LinkOption> options)
Looks up the file at the given path using the given link options.java.lang.String
name()
(package private) <A extends java.nio.file.attribute.BasicFileAttributes>
AreadAttributes(File file, java.lang.Class<A> type)
Returns attributes of the given file as an object of the given type.(package private) com.google.common.collect.ImmutableMap<java.lang.String,java.lang.Object>
readAttributes(File file, java.lang.String attributes)
Returns a map containing the attributes described by the given string mapped to their values.(package private) java.util.concurrent.locks.Lock
readLock()
Returns the read lock for this store.(package private) com.google.common.base.Supplier<RegularFile>
regularFileCreator()
Returns a supplier that creates a new regular file.(package private) void
setAttribute(File file, java.lang.String attribute, java.lang.Object value)
Sets the given attribute to the given value for the given file.(package private) void
setInitialAttributes(File file, java.nio.file.attribute.FileAttribute<?>... attrs)
Sets initial attributes on the given file.(package private) FileSystemState
state()
Returns the file system state object.(package private) com.google.common.collect.ImmutableSet<java.lang.String>
supportedFileAttributeViews()
Returns the file attribute views supported by this store.(package private) boolean
supportsFeature(Feature feature)
Returns whether or not the given feature is supported by this file store.boolean
supportsFileAttributeView(java.lang.Class<? extends java.nio.file.attribute.FileAttributeView> type)
boolean
supportsFileAttributeView(java.lang.String name)
(package private) com.google.common.base.Supplier<SymbolicLink>
symbolicLinkCreator(JimfsPath target)
Returns a supplier that creates a new symbolic link with the given target.java.lang.String
type()
(package private) java.util.concurrent.locks.Lock
writeLock()
Returns the write lock for this store.
-
-
-
Field Detail
-
tree
private final FileTree tree
-
disk
private final HeapDisk disk
-
attributes
private final AttributeService attributes
-
factory
private final FileFactory factory
-
supportedFeatures
private final com.google.common.collect.ImmutableSet<Feature> supportedFeatures
-
state
private final FileSystemState state
-
readLock
private final java.util.concurrent.locks.Lock readLock
-
writeLock
private final java.util.concurrent.locks.Lock writeLock
-
-
Constructor Detail
-
JimfsFileStore
public JimfsFileStore(FileTree tree, FileFactory factory, HeapDisk disk, AttributeService attributes, com.google.common.collect.ImmutableSet<Feature> supportedFeatures, FileSystemState state)
-
-
Method Detail
-
state
FileSystemState state()
Returns the file system state object.
-
readLock
java.util.concurrent.locks.Lock readLock()
Returns the read lock for this store.
-
writeLock
java.util.concurrent.locks.Lock writeLock()
Returns the write lock for this store.
-
getRootDirectoryNames
com.google.common.collect.ImmutableSortedSet<Name> getRootDirectoryNames()
Returns the names of the root directories in this store.
-
getRoot
@Nullable Directory getRoot(Name name)
Returns the root directory with the given name ornull
if no such directory exists.
-
supportsFeature
boolean supportsFeature(Feature feature)
Returns whether or not the given feature is supported by this file store.
-
lookUp
DirectoryEntry lookUp(File workingDirectory, JimfsPath path, java.util.Set<? super java.nio.file.LinkOption> options) throws java.io.IOException
Looks up the file at the given path using the given link options. If the path is relative, the lookup is relative to the given working directory.- Throws:
java.nio.file.NoSuchFileException
- if an element of the path other than the final element does not resolve to a directory or symbolic link (e.g. it doesn't exist or is a regular file)java.io.IOException
- if a symbolic link cycle is detected or the depth of symbolic link recursion otherwise exceeds a threshold
-
regularFileCreator
com.google.common.base.Supplier<RegularFile> regularFileCreator()
Returns a supplier that creates a new regular file.
-
directoryCreator
com.google.common.base.Supplier<Directory> directoryCreator()
Returns a supplier that creates a new directory.
-
symbolicLinkCreator
com.google.common.base.Supplier<SymbolicLink> symbolicLinkCreator(JimfsPath target)
Returns a supplier that creates a new symbolic link with the given target.
-
copyWithoutContent
File copyWithoutContent(File file, AttributeCopyOption attributeCopyOption) throws java.io.IOException
Creates a copy of the given file, copying its attributes as well according to the givenattributeCopyOption
.- Throws:
java.io.IOException
-
setInitialAttributes
void setInitialAttributes(File file, java.nio.file.attribute.FileAttribute<?>... attrs)
Sets initial attributes on the given file. Sets default attributes first, then attempts to set the given user-provided attributes.
-
getFileAttributeView
<V extends java.nio.file.attribute.FileAttributeView> @Nullable V getFileAttributeView(FileLookup lookup, java.lang.Class<V> type)
Returns an attribute view of the given type for the given file lookup callback, ornull
if the view type is not supported.
-
readAttributes
com.google.common.collect.ImmutableMap<java.lang.String,java.lang.Object> readAttributes(File file, java.lang.String attributes)
Returns a map containing the attributes described by the given string mapped to their values.
-
readAttributes
<A extends java.nio.file.attribute.BasicFileAttributes> A readAttributes(File file, java.lang.Class<A> type)
Returns attributes of the given file as an object of the given type.- Throws:
java.lang.UnsupportedOperationException
- if the given attributes type is not supported
-
setAttribute
void setAttribute(File file, java.lang.String attribute, java.lang.Object value)
Sets the given attribute to the given value for the given file.
-
supportedFileAttributeViews
com.google.common.collect.ImmutableSet<java.lang.String> supportedFileAttributeViews()
Returns the file attribute views supported by this store.
-
name
public java.lang.String name()
- Specified by:
name
in classjava.nio.file.FileStore
-
type
public java.lang.String type()
- Specified by:
type
in classjava.nio.file.FileStore
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnly
in classjava.nio.file.FileStore
-
getTotalSpace
public long getTotalSpace() throws java.io.IOException
- Specified by:
getTotalSpace
in classjava.nio.file.FileStore
- Throws:
java.io.IOException
-
getUsableSpace
public long getUsableSpace() throws java.io.IOException
- Specified by:
getUsableSpace
in classjava.nio.file.FileStore
- Throws:
java.io.IOException
-
getUnallocatedSpace
public long getUnallocatedSpace() throws java.io.IOException
- Specified by:
getUnallocatedSpace
in classjava.nio.file.FileStore
- Throws:
java.io.IOException
-
supportsFileAttributeView
public boolean supportsFileAttributeView(java.lang.Class<? extends java.nio.file.attribute.FileAttributeView> type)
- Specified by:
supportsFileAttributeView
in classjava.nio.file.FileStore
-
supportsFileAttributeView
public boolean supportsFileAttributeView(java.lang.String name)
- Specified by:
supportsFileAttributeView
in classjava.nio.file.FileStore
-
getFileStoreAttributeView
public <V extends java.nio.file.attribute.FileStoreAttributeView> V getFileStoreAttributeView(java.lang.Class<V> type)
- Specified by:
getFileStoreAttributeView
in classjava.nio.file.FileStore
-
getAttribute
public java.lang.Object getAttribute(java.lang.String attribute) throws java.io.IOException
- Specified by:
getAttribute
in classjava.nio.file.FileStore
- Throws:
java.io.IOException
-
-