Class SystemJimfsFileSystemProvider
- java.lang.Object
-
- java.nio.file.spi.FileSystemProvider
-
- com.google.common.jimfs.SystemJimfsFileSystemProvider
-
@AutoService(java.nio.file.spi.FileSystemProvider.class) public final class SystemJimfsFileSystemProvider extends java.nio.file.spi.FileSystemProviderFileSystemProviderimplementation for Jimfs that is loaded by the system as a service. This implementation only serves as a cache for file system instances and does not implement actual file system operations.While this class is public, it should not be used directly. To create a new file system instance, see
Jimfs. For other operations, use the public APIs injava.nio.file.- Since:
- 1.1
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.StringFILE_SYSTEM_KEYEnv map key that maps to the already-createdFileSysteminstance innewFileSystem.private static java.util.concurrent.ConcurrentMap<java.net.URI,java.nio.file.FileSystem>fileSystemsCache of file systems that have been created but not closed.
-
Constructor Summary
Constructors Constructor Description SystemJimfsFileSystemProvider()Deprecated.Not intended to be called directly; this class is only for use by Java itself.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckAccess(java.nio.file.Path path, java.nio.file.AccessMode... modes)voidcopy(java.nio.file.Path source, java.nio.file.Path target, java.nio.file.CopyOption... options)voidcreateDirectory(java.nio.file.Path dir, java.nio.file.attribute.FileAttribute<?>... attrs)voiddelete(java.nio.file.Path path)<V extends java.nio.file.attribute.FileAttributeView>
VgetFileAttributeView(java.nio.file.Path path, java.lang.Class<V> type, java.nio.file.LinkOption... options)java.nio.file.FileStoregetFileStore(java.nio.file.Path path)java.nio.file.FileSystemgetFileSystem(java.net.URI uri)java.nio.file.PathgetPath(java.net.URI uri)java.lang.StringgetScheme()booleanisHidden(java.nio.file.Path path)booleanisSameFile(java.nio.file.Path path, java.nio.file.Path path2)private static booleanisValidFileSystemUri(java.net.URI uri)Returns whether or not the given URI is valid as a base file system URI.voidmove(java.nio.file.Path source, java.nio.file.Path target, java.nio.file.CopyOption... options)java.nio.channels.SeekableByteChannelnewByteChannel(java.nio.file.Path path, java.util.Set<? extends java.nio.file.OpenOption> options, java.nio.file.attribute.FileAttribute<?>... attrs)java.nio.file.DirectoryStream<java.nio.file.Path>newDirectoryStream(java.nio.file.Path dir, java.nio.file.DirectoryStream.Filter<? super java.nio.file.Path> filter)java.nio.file.FileSystemnewFileSystem(java.net.URI uri, java.util.Map<java.lang.String,?> env)java.nio.file.FileSystemnewFileSystem(java.nio.file.Path path, java.util.Map<java.lang.String,?> env)<A extends java.nio.file.attribute.BasicFileAttributes>
AreadAttributes(java.nio.file.Path path, java.lang.Class<A> type, java.nio.file.LinkOption... options)java.util.Map<java.lang.String,java.lang.Object>readAttributes(java.nio.file.Path path, java.lang.String attributes, java.nio.file.LinkOption... options)static java.lang.RunnableremoveFileSystemRunnable(java.net.URI uri)Returns a runnable that, when run, removes the file system with the given URI from this provider.voidsetAttribute(java.nio.file.Path path, java.lang.String attribute, java.lang.Object value, java.nio.file.LinkOption... options)private static java.net.URItoFileSystemUri(java.net.URI uri)Returns the given URI with any path, query or fragment stripped off.private static java.nio.file.PathtoPath(java.nio.file.FileSystem fileSystem, java.net.URI uri)Invokes thetoPath(URI)method on the givenFileSystem.
-
-
-
Field Detail
-
FILE_SYSTEM_KEY
static final java.lang.String FILE_SYSTEM_KEY
Env map key that maps to the already-createdFileSysteminstance innewFileSystem.- See Also:
- Constant Field Values
-
fileSystems
private static final java.util.concurrent.ConcurrentMap<java.net.URI,java.nio.file.FileSystem> fileSystems
Cache of file systems that have been created but not closed.This cache is static to ensure that even when this provider isn't loaded by the system class loader, meaning that a new instance of it must be created each time one of the methods on
FileSystemsorPaths.get(URI)is called, cached file system instances are still available.The cache uses weak values so that it doesn't prevent file systems that are created but not closed from being garbage collected if no references to them are held elsewhere. This is a compromise between ensuring that any file URI continues to work as long as the file system hasn't been closed (which is technically the correct thing to do but unlikely to be something that most users care about) and ensuring that users don't get unexpected leaks of large amounts of memory because they're creating many file systems in tests but forgetting to close them (which seems likely to happen sometimes). Users that want to ensure that a file system won't be garbage collected just need to ensure they hold a reference to it somewhere for as long as they need it to stick around.
-
-
Method Detail
-
getScheme
public java.lang.String getScheme()
- Specified by:
getSchemein classjava.nio.file.spi.FileSystemProvider
-
newFileSystem
public java.nio.file.FileSystem newFileSystem(java.net.URI uri, java.util.Map<java.lang.String,?> env) throws java.io.IOException- Specified by:
newFileSystemin classjava.nio.file.spi.FileSystemProvider- Throws:
java.io.IOException
-
getFileSystem
public java.nio.file.FileSystem getFileSystem(java.net.URI uri)
- Specified by:
getFileSystemin classjava.nio.file.spi.FileSystemProvider
-
getPath
public java.nio.file.Path getPath(java.net.URI uri)
- Specified by:
getPathin classjava.nio.file.spi.FileSystemProvider
-
isValidFileSystemUri
private static boolean isValidFileSystemUri(java.net.URI uri)
Returns whether or not the given URI is valid as a base file system URI. It must not have a path, query or fragment.
-
toFileSystemUri
private static java.net.URI toFileSystemUri(java.net.URI uri)
Returns the given URI with any path, query or fragment stripped off.
-
toPath
private static java.nio.file.Path toPath(java.nio.file.FileSystem fileSystem, java.net.URI uri)Invokes thetoPath(URI)method on the givenFileSystem.
-
newFileSystem
public java.nio.file.FileSystem newFileSystem(java.nio.file.Path path, java.util.Map<java.lang.String,?> env) throws java.io.IOException- Overrides:
newFileSystemin classjava.nio.file.spi.FileSystemProvider- Throws:
java.io.IOException
-
removeFileSystemRunnable
public static java.lang.Runnable removeFileSystemRunnable(java.net.URI uri)
Returns a runnable that, when run, removes the file system with the given URI from this provider.
-
newByteChannel
public java.nio.channels.SeekableByteChannel newByteChannel(java.nio.file.Path path, java.util.Set<? extends java.nio.file.OpenOption> options, java.nio.file.attribute.FileAttribute<?>... attrs) throws java.io.IOException- Specified by:
newByteChannelin classjava.nio.file.spi.FileSystemProvider- Throws:
java.io.IOException
-
newDirectoryStream
public java.nio.file.DirectoryStream<java.nio.file.Path> newDirectoryStream(java.nio.file.Path dir, java.nio.file.DirectoryStream.Filter<? super java.nio.file.Path> filter) throws java.io.IOException- Specified by:
newDirectoryStreamin classjava.nio.file.spi.FileSystemProvider- Throws:
java.io.IOException
-
createDirectory
public void createDirectory(java.nio.file.Path dir, java.nio.file.attribute.FileAttribute<?>... attrs) throws java.io.IOException- Specified by:
createDirectoryin classjava.nio.file.spi.FileSystemProvider- Throws:
java.io.IOException
-
delete
public void delete(java.nio.file.Path path) throws java.io.IOException- Specified by:
deletein classjava.nio.file.spi.FileSystemProvider- Throws:
java.io.IOException
-
copy
public void copy(java.nio.file.Path source, java.nio.file.Path target, java.nio.file.CopyOption... options) throws java.io.IOException- Specified by:
copyin classjava.nio.file.spi.FileSystemProvider- Throws:
java.io.IOException
-
move
public void move(java.nio.file.Path source, java.nio.file.Path target, java.nio.file.CopyOption... options) throws java.io.IOException- Specified by:
movein classjava.nio.file.spi.FileSystemProvider- Throws:
java.io.IOException
-
isSameFile
public boolean isSameFile(java.nio.file.Path path, java.nio.file.Path path2) throws java.io.IOException- Specified by:
isSameFilein classjava.nio.file.spi.FileSystemProvider- Throws:
java.io.IOException
-
isHidden
public boolean isHidden(java.nio.file.Path path) throws java.io.IOException- Specified by:
isHiddenin classjava.nio.file.spi.FileSystemProvider- Throws:
java.io.IOException
-
getFileStore
public java.nio.file.FileStore getFileStore(java.nio.file.Path path) throws java.io.IOException- Specified by:
getFileStorein classjava.nio.file.spi.FileSystemProvider- Throws:
java.io.IOException
-
checkAccess
public void checkAccess(java.nio.file.Path path, java.nio.file.AccessMode... modes) throws java.io.IOException- Specified by:
checkAccessin classjava.nio.file.spi.FileSystemProvider- Throws:
java.io.IOException
-
getFileAttributeView
public <V extends java.nio.file.attribute.FileAttributeView> V getFileAttributeView(java.nio.file.Path path, java.lang.Class<V> type, java.nio.file.LinkOption... options)- Specified by:
getFileAttributeViewin classjava.nio.file.spi.FileSystemProvider
-
readAttributes
public <A extends java.nio.file.attribute.BasicFileAttributes> A readAttributes(java.nio.file.Path path, java.lang.Class<A> type, java.nio.file.LinkOption... options) throws java.io.IOException- Specified by:
readAttributesin classjava.nio.file.spi.FileSystemProvider- Throws:
java.io.IOException
-
readAttributes
public java.util.Map<java.lang.String,java.lang.Object> readAttributes(java.nio.file.Path path, java.lang.String attributes, java.nio.file.LinkOption... options) throws java.io.IOException- Specified by:
readAttributesin classjava.nio.file.spi.FileSystemProvider- Throws:
java.io.IOException
-
setAttribute
public void setAttribute(java.nio.file.Path path, java.lang.String attribute, java.lang.Object value, java.nio.file.LinkOption... options) throws java.io.IOException- Specified by:
setAttributein classjava.nio.file.spi.FileSystemProvider- Throws:
java.io.IOException
-
-