Class RootedFileSystemProvider


  • public class RootedFileSystemProvider
    extends java.nio.file.spi.FileSystemProvider
    File system provider which provides a rooted file system. The file system only gives access to files under the root directory.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.nio.file.Path,​RootedFileSystem> fileSystems  
      protected org.slf4j.Logger log  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void checkAccess​(java.nio.file.Path path, java.nio.file.AccessMode... modes)  
      void copy​(java.nio.file.Path source, java.nio.file.Path target, java.nio.file.CopyOption... options)  
      void createDirectory​(java.nio.file.Path dir, java.nio.file.attribute.FileAttribute<?>... attrs)  
      void createLink​(java.nio.file.Path link, java.nio.file.Path existing)  
      void createSymbolicLink​(java.nio.file.Path link, java.nio.file.Path target, java.nio.file.attribute.FileAttribute<?>... attrs)  
      void delete​(java.nio.file.Path path)  
      boolean deleteIfExists​(java.nio.file.Path path)  
      private static java.nio.file.Path ensureDirectory​(java.nio.file.Path path)  
      private java.lang.String fixExceptionFileName​(java.nio.file.Path root, java.nio.file.Path rootedPath, java.lang.String fileName)  
      <V extends java.nio.file.attribute.FileAttributeView>
      V
      getFileAttributeView​(java.nio.file.Path path, java.lang.Class<V> type, java.nio.file.LinkOption... options)  
      java.nio.file.FileStore getFileStore​(java.nio.file.Path path)  
      java.nio.file.FileSystem getFileSystem​(java.net.URI uri)  
      protected RootedFileSystem getFileSystem​(java.nio.file.Path path)  
      java.nio.file.Path getPath​(java.net.URI uri)  
      java.lang.String getScheme()  
      boolean isHidden​(java.nio.file.Path path)  
      boolean isSameFile​(java.nio.file.Path path, java.nio.file.Path path2)  
      void move​(java.nio.file.Path source, java.nio.file.Path target, java.nio.file.CopyOption... options)  
      java.nio.channels.AsynchronousFileChannel newAsynchronousFileChannel​(java.nio.file.Path path, java.util.Set<? extends java.nio.file.OpenOption> options, java.util.concurrent.ExecutorService executor, java.nio.file.attribute.FileAttribute<?>... attrs)  
      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)  
      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.channels.FileChannel newFileChannel​(java.nio.file.Path path, java.util.Set<? extends java.nio.file.OpenOption> options, java.nio.file.attribute.FileAttribute<?>... attrs)  
      protected java.nio.file.FileSystem newFileSystem​(java.lang.Object src, java.nio.file.Path path, java.util.Map<java.lang.String,​?> env)  
      java.nio.file.FileSystem newFileSystem​(java.net.URI uri, java.util.Map<java.lang.String,​?> env)  
      java.nio.file.FileSystem newFileSystem​(java.nio.file.Path path, java.util.Map<java.lang.String,​?> env)  
      java.io.InputStream newInputStream​(java.nio.file.Path path, java.nio.file.OpenOption... options)  
      java.io.OutputStream newOutputStream​(java.nio.file.Path path, java.nio.file.OpenOption... options)  
      protected java.nio.file.spi.FileSystemProvider provider​(java.nio.file.Path path)  
      <A extends java.nio.file.attribute.BasicFileAttributes>
      A
      readAttributes​(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)  
      java.nio.file.Path readSymbolicLink​(java.nio.file.Path link)  
      protected java.nio.file.Path resolveLocalPath​(RootedPath path)  
      protected java.nio.file.DirectoryStream<java.nio.file.Path> root​(RootedFileSystem rfs, java.nio.file.DirectoryStream<java.nio.file.Path> ds)  
      protected java.nio.file.Path root​(RootedFileSystem rfs, java.nio.file.Path nat)  
      void setAttribute​(java.nio.file.Path path, java.lang.String attribute, java.lang.Object value, java.nio.file.LinkOption... options)  
      private java.io.IOException translateIoException​(java.io.IOException ex, java.nio.file.Path rootedPath)  
      protected java.nio.file.Path unroot​(java.nio.file.Path path)  
      protected java.nio.file.Path uriToPath​(java.net.URI uri)  
      • Methods inherited from class java.nio.file.spi.FileSystemProvider

        installedProviders
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • log

        protected final org.slf4j.Logger log
      • fileSystems

        private final java.util.Map<java.nio.file.Path,​RootedFileSystem> fileSystems
    • Constructor Detail

      • RootedFileSystemProvider

        public RootedFileSystemProvider()
    • Method Detail

      • getScheme

        public java.lang.String getScheme()
        Specified by:
        getScheme in class java.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:
        newFileSystem in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • getFileSystem

        public java.nio.file.FileSystem getFileSystem​(java.net.URI uri)
        Specified by:
        getFileSystem in class java.nio.file.spi.FileSystemProvider
      • newFileSystem

        public java.nio.file.FileSystem newFileSystem​(java.nio.file.Path path,
                                                      java.util.Map<java.lang.String,​?> env)
                                               throws java.io.IOException
        Overrides:
        newFileSystem in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • newFileSystem

        protected java.nio.file.FileSystem newFileSystem​(java.lang.Object src,
                                                         java.nio.file.Path path,
                                                         java.util.Map<java.lang.String,​?> env)
                                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • uriToPath

        protected java.nio.file.Path uriToPath​(java.net.URI uri)
      • ensureDirectory

        private static java.nio.file.Path ensureDirectory​(java.nio.file.Path path)
      • getPath

        public java.nio.file.Path getPath​(java.net.URI uri)
        Specified by:
        getPath in class java.nio.file.spi.FileSystemProvider
      • newInputStream

        public java.io.InputStream newInputStream​(java.nio.file.Path path,
                                                  java.nio.file.OpenOption... options)
                                           throws java.io.IOException
        Overrides:
        newInputStream in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • newOutputStream

        public java.io.OutputStream newOutputStream​(java.nio.file.Path path,
                                                    java.nio.file.OpenOption... options)
                                             throws java.io.IOException
        Overrides:
        newOutputStream in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • newFileChannel

        public java.nio.channels.FileChannel newFileChannel​(java.nio.file.Path path,
                                                            java.util.Set<? extends java.nio.file.OpenOption> options,
                                                            java.nio.file.attribute.FileAttribute<?>... attrs)
                                                     throws java.io.IOException
        Overrides:
        newFileChannel in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • newAsynchronousFileChannel

        public java.nio.channels.AsynchronousFileChannel newAsynchronousFileChannel​(java.nio.file.Path path,
                                                                                    java.util.Set<? extends java.nio.file.OpenOption> options,
                                                                                    java.util.concurrent.ExecutorService executor,
                                                                                    java.nio.file.attribute.FileAttribute<?>... attrs)
                                                                             throws java.io.IOException
        Overrides:
        newAsynchronousFileChannel in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • 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:
        newByteChannel in class java.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:
        newDirectoryStream in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • root

        protected java.nio.file.DirectoryStream<java.nio.file.Path> root​(RootedFileSystem rfs,
                                                                         java.nio.file.DirectoryStream<java.nio.file.Path> ds)
      • createDirectory

        public void createDirectory​(java.nio.file.Path dir,
                                    java.nio.file.attribute.FileAttribute<?>... attrs)
                             throws java.io.IOException
        Specified by:
        createDirectory in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • createSymbolicLink

        public void createSymbolicLink​(java.nio.file.Path link,
                                       java.nio.file.Path target,
                                       java.nio.file.attribute.FileAttribute<?>... attrs)
                                throws java.io.IOException
        Overrides:
        createSymbolicLink in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • createLink

        public void createLink​(java.nio.file.Path link,
                               java.nio.file.Path existing)
                        throws java.io.IOException
        Overrides:
        createLink in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • delete

        public void delete​(java.nio.file.Path path)
                    throws java.io.IOException
        Specified by:
        delete in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • deleteIfExists

        public boolean deleteIfExists​(java.nio.file.Path path)
                               throws java.io.IOException
        Overrides:
        deleteIfExists in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • readSymbolicLink

        public java.nio.file.Path readSymbolicLink​(java.nio.file.Path link)
                                            throws java.io.IOException
        Overrides:
        readSymbolicLink in class java.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:
        copy in class java.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:
        move in class java.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:
        isSameFile in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • isHidden

        public boolean isHidden​(java.nio.file.Path path)
                         throws java.io.IOException
        Specified by:
        isHidden in class java.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:
        getFileStore in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • getFileSystem

        protected RootedFileSystem getFileSystem​(java.nio.file.Path path)
                                          throws java.nio.file.FileSystemNotFoundException
        Throws:
        java.nio.file.FileSystemNotFoundException
      • checkAccess

        public void checkAccess​(java.nio.file.Path path,
                                java.nio.file.AccessMode... modes)
                         throws java.io.IOException
        Specified by:
        checkAccess in class java.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:
        getFileAttributeView in class java.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:
        readAttributes in class java.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:
        readAttributes in class java.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:
        setAttribute in class java.nio.file.spi.FileSystemProvider
        Throws:
        java.io.IOException
      • provider

        protected java.nio.file.spi.FileSystemProvider provider​(java.nio.file.Path path)
      • root

        protected java.nio.file.Path root​(RootedFileSystem rfs,
                                          java.nio.file.Path nat)
      • unroot

        protected java.nio.file.Path unroot​(java.nio.file.Path path)
        Parameters:
        path - The original (rooted) Path
        Returns:
        The actual absolute local Path represented by the rooted one
        Throws:
        java.lang.IllegalArgumentException - if null path argument
        java.nio.file.ProviderMismatchException - if not a RootedPath
        See Also:
        resolveLocalPath(RootedPath)
      • resolveLocalPath

        protected java.nio.file.Path resolveLocalPath​(RootedPath path)
        Parameters:
        path - The original RootedPath - never null
        Returns:
        The actual absolute local Path represented by the rooted one
        Throws:
        java.nio.file.InvalidPathException - If the resolved path is not a proper sub-path of the rooted file system
      • translateIoException

        private java.io.IOException translateIoException​(java.io.IOException ex,
                                                         java.nio.file.Path rootedPath)
      • fixExceptionFileName

        private java.lang.String fixExceptionFileName​(java.nio.file.Path root,
                                                      java.nio.file.Path rootedPath,
                                                      java.lang.String fileName)