Class SystemJimfsFileSystemProvider
FileSystemProvider
implementation 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 in java.nio.file
.
- Since:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final String
Env map key that maps to the already-createdFileSystem
instance innewFileSystem
.private static final ConcurrentMap
<URI, FileSystem> Cache of file systems that have been created but not closed. -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.Not intended to be called directly; this class is only for use by Java itself. -
Method Summary
Modifier and TypeMethodDescriptionvoid
checkAccess
(Path path, AccessMode... modes) void
copy
(Path source, Path target, CopyOption... options) void
createDirectory
(Path dir, FileAttribute<?>... attrs) void
<V extends FileAttributeView>
VgetFileAttributeView
(Path path, Class<V> type, LinkOption... options) getFileStore
(Path path) getFileSystem
(URI uri) boolean
boolean
isSameFile
(Path path, Path path2) private static boolean
isValidFileSystemUri
(URI uri) Returns whether or not the given URI is valid as a base file system URI.void
move
(Path source, Path target, CopyOption... options) newByteChannel
(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) newDirectoryStream
(Path dir, DirectoryStream.Filter<? super Path> filter) newFileSystem
(URI uri, Map<String, ?> env) newFileSystem
(Path path, Map<String, ?> env) <A extends BasicFileAttributes>
AreadAttributes
(Path path, Class<A> type, LinkOption... options) readAttributes
(Path path, String attributes, LinkOption... options) static Runnable
Returns a runnable that, when run, removes the file system with the given URI from this provider.void
setAttribute
(Path path, String attribute, Object value, LinkOption... options) private static URI
toFileSystemUri
(URI uri) Returns the given URI with any path, query or fragment stripped off.private static Path
toPath
(FileSystem fileSystem, URI uri) Invokes thetoPath(URI)
method on the givenFileSystem
.Methods inherited from class java.nio.file.spi.FileSystemProvider
createLink, createSymbolicLink, deleteIfExists, exists, installedProviders, newAsynchronousFileChannel, newFileChannel, newInputStream, newOutputStream, readAttributesIfExists, readSymbolicLink
-
Field Details
-
FILE_SYSTEM_KEY
Env map key that maps to the already-createdFileSystem
instance innewFileSystem
.- See Also:
-
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
FileSystems
orPaths.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.
-
-
Constructor Details
-
SystemJimfsFileSystemProvider
Deprecated.Not intended to be called directly; this class is only for use by Java itself.
-
-
Method Details
-
getScheme
- Specified by:
getScheme
in classFileSystemProvider
-
newFileSystem
- Specified by:
newFileSystem
in classFileSystemProvider
- Throws:
IOException
-
getFileSystem
- Specified by:
getFileSystem
in classFileSystemProvider
-
getPath
- Specified by:
getPath
in classFileSystemProvider
-
isValidFileSystemUri
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
Returns the given URI with any path, query or fragment stripped off. -
toPath
Invokes thetoPath(URI)
method on the givenFileSystem
. -
newFileSystem
- Overrides:
newFileSystem
in classFileSystemProvider
- Throws:
IOException
-
removeFileSystemRunnable
Returns a runnable that, when run, removes the file system with the given URI from this provider. -
newByteChannel
public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException - Specified by:
newByteChannel
in classFileSystemProvider
- Throws:
IOException
-
newDirectoryStream
public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException - Specified by:
newDirectoryStream
in classFileSystemProvider
- Throws:
IOException
-
createDirectory
- Specified by:
createDirectory
in classFileSystemProvider
- Throws:
IOException
-
delete
- Specified by:
delete
in classFileSystemProvider
- Throws:
IOException
-
copy
- Specified by:
copy
in classFileSystemProvider
- Throws:
IOException
-
move
- Specified by:
move
in classFileSystemProvider
- Throws:
IOException
-
isSameFile
- Specified by:
isSameFile
in classFileSystemProvider
- Throws:
IOException
-
isHidden
- Specified by:
isHidden
in classFileSystemProvider
- Throws:
IOException
-
getFileStore
- Specified by:
getFileStore
in classFileSystemProvider
- Throws:
IOException
-
checkAccess
- Specified by:
checkAccess
in classFileSystemProvider
- Throws:
IOException
-
getFileAttributeView
public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) - Specified by:
getFileAttributeView
in classFileSystemProvider
-
readAttributes
public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException - Specified by:
readAttributes
in classFileSystemProvider
- Throws:
IOException
-
readAttributes
public Map<String,Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException - Specified by:
readAttributes
in classFileSystemProvider
- Throws:
IOException
-
setAttribute
public void setAttribute(Path path, String attribute, Object value, LinkOption... options) throws IOException - Specified by:
setAttribute
in classFileSystemProvider
- Throws:
IOException
-