private static FileSystemProvider providerOf( final Path path ) { return path.getFileSystem().provider(); }
@Override public URI toUri() throws IOException, SecurityException { if ( !isAbsolute() ) { return toAbsolutePath().toUri(); } if ( fs.provider().isDefault() && !isRealPath ) { try { return new URI( "default", host, toURIString(), null ); } catch ( URISyntaxException e ) { return null; } } try { return new URI( fs.provider().getScheme(), host, toURIString(), null ); } catch ( URISyntaxException e ) { return null; } }
final BasicFileAttributes fileAttrs = path.getFileSystem().provider().getFileAttributeView( path, BasicFileAttributeView.class ).readAttributes();
final BasicFileAttributes fileAttrs = path.getFileSystem().provider().getFileAttributeView( path, BasicFileAttributeView.class ).readAttributes();
public ConfigView( final AbstractPath path ) { super( path ); final BasicFileAttributes fileAttrs = path.getFileSystem().provider().getFileAttributeView( path, BasicFileAttributeView.class ).readAttributes();
final Map<String, Object> content = path.getAttrStorage().getContent(); final BasicFileAttributes fileAttrs = path.getFileSystem().provider().getFileAttributeView( path, BasicFileAttributeView.class ).readAttributes();
public static void buildDotFile( final Path path, final OutputStream out, final FileAttribute<?>... attrs ) { if ( attrs != null && attrs.length > 0 ) { final Properties properties = new Properties(); for ( final FileAttribute<?> attr : attrs ) { if ( attr.value() instanceof Serializable ) { properties.put( attr.name(), attr.value() ); } } try { properties.store( out ); } catch ( final Exception e ) { throw new IOException( e ); } if ( path instanceof AttrHolder ) { ( (AttrHolder) path ).getAttrStorage().loadContent( properties ); } } else { path.getFileSystem().provider().deleteIfExists( dot( path ) ); } }
@Test public void validateGetPath() { final SimpleFileSystemProvider fsProvider = new SimpleFileSystemProvider(); final URI uri = URI.create( "file:///path/to/file.txt" ); final Path path = fsProvider.getPath( uri ); assertThat( path ).isNotNull(); assertThat( path.isAbsolute() ).isTrue(); assertThat( path.getFileSystem() ).isEqualTo( fsProvider.getFileSystem( uri ) ); assertThat( path.getFileSystem().provider() ).isEqualTo( fsProvider ); assertThat( path.toString() ).isEqualTo( "/path/to/file.txt" ); }
@Test public void simpleTests() { final FileSystem fileSystem = new SimpleUnixFileSystem( fsProvider, "/" ); assertThat( fileSystem.isOpen() ).isTrue(); assertThat( fileSystem.isReadOnly() ).isFalse(); assertThat( fileSystem.getSeparator() ).isEqualTo( System.getProperty( "file.separator" ) ); assertThat( fileSystem.provider() ).isEqualTo( fsProvider ); assertThat( fileSystem.supportedFileAttributeViews() ).isNotEmpty().hasSize( 1 ).contains( "basic" ); assertThat( fileSystem.getPath( "/path/to/file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "/path/to/file.txt", false ) ); assertThat( fileSystem.getPath( "/path/to/file.txt", null ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "/path/to/file.txt", false ) ); assertThat( fileSystem.getPath( "/path", "to", "file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "/path/to/file.txt", false ) ); try { fileSystem.close(); fail( "can't close this fileSystem" ); } catch ( UnsupportedOperationException ex ) { } assertThat( fileSystem.getFileStores() ).isNotNull().hasSize( 1 ); assertThat( fileSystem.getFileStores().iterator().next().name() ).isEqualTo( "/" ); assertThat( fileSystem.getRootDirectories() ).isNotNull().hasSize( 1 ); assertThat( fileSystem.getRootDirectories().iterator().next().toString() ).isEqualTo( "/" ); assertThat( fileSystem.getRootDirectories().iterator().next().isAbsolute() ).isTrue(); }
@Test public void simpleTests() { final FileSystem fileSystem = new SimpleWindowsFileSystem( roots, fsProvider, "c:\\" ); assertThat( fileSystem.isOpen() ).isTrue(); assertThat( fileSystem.isReadOnly() ).isFalse(); assertThat( fileSystem.getSeparator() ).isEqualTo( "\\" ); assertThat( fileSystem.provider() ).isEqualTo( fsProvider ); assertThat( fileSystem.supportedFileAttributeViews() ).isNotEmpty().hasSize( 1 ).contains( "basic" ); assertThat( fileSystem.getPath( "c:\\path\\to\\file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "c:\\path\\to\\file.txt", false ) ); assertThat( fileSystem.getPath( "c:\\path\\to\\file.txt", null ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "c:\\path\\to\\file.txt", false ) ); assertThat( fileSystem.getPath( "c:\\path", "to", "file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "c:\\path\\to\\file.txt", false ) ); try { fileSystem.close(); fail( "can't close this fileSystem" ); } catch ( UnsupportedOperationException ex ) { } assertThat( fileSystem.getFileStores() ).isNotNull().hasSize( 2 ); assertThat( fileSystem.getFileStores().iterator().next().name() ).isEqualTo( "c:\\" ); assertThat( fileSystem.getRootDirectories() ).isNotNull().hasSize( 2 ); assertThat( fileSystem.getRootDirectories().iterator().next().toString() ).isEqualTo( "c:\\" ); assertThat( fileSystem.getRootDirectories().iterator().next().isAbsolute() ).isTrue(); }