protected boolean isFileScheme( final Path path ) { if ( path == null || path.getFileSystem() == null || path.getFileSystem().provider() == null ) { return false; } return path.getFileSystem().provider().getScheme().equals( "file" ); }
private String getRootDirectory( final org.kie.commons.java.nio.file.Path path ) { final Iterator<FileStore> fileStoreIterator = path.getFileSystem().getFileStores().iterator(); if ( fileStoreIterator.hasNext() ) { return fileStoreIterator.next().name(); } return ""; }
@Override public Path createDirectories( final Path dir, final Map<String, ?> attrs ) throws UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException { return new FileSystemSyncLock<Path>( dir.getFileSystem() ).execute( clusterService, new FutureTask<Path>( new Callable<Path>() { @Override public Path call() throws Exception { return service.createDirectories( dir, attrs ); } } ) ); }
@Override public Path setAttributes( final Path path, final FileAttribute<?>... attrs ) throws UnsupportedOperationException, IllegalArgumentException, ClassCastException, IOException, SecurityException { return new FileSystemSyncLock<Path>( path.getFileSystem() ).execute( clusterService, new FutureTask<Path>( new Callable<Path>() { @Override public Path call() throws Exception { return service.setAttributes( path, attrs ); } } ) ); }
@Override public Path write( final Path path, final String content, final Set<? extends OpenOption> options, final FileAttribute<?>... attrs ) throws IllegalArgumentException, IOException, UnsupportedOperationException { return new FileSystemSyncLock<Path>( path.getFileSystem() ).execute( clusterService, new FutureTask<Path>( new Callable<Path>() { @Override public Path call() throws Exception { return service.write( path, content, options, attrs ); } } ) ); }
@Override public Path write( final Path path, final String content, final Map<String, ?> attrs, final OpenOption... options ) throws IllegalArgumentException, IOException, UnsupportedOperationException { return new FileSystemSyncLock<Path>( path.getFileSystem() ).execute( clusterService, new FutureTask<Path>( new Callable<Path>() { @Override public Path call() throws Exception { return service.write( path, content, attrs, options ); } } ) ); }
@Override public Path setAttribute( final Path path, final String attribute, final Object value ) throws UnsupportedOperationException, IllegalArgumentException, ClassCastException, IOException, SecurityException { return new FileSystemSyncLock<Path>( path.getFileSystem() ).execute( clusterService, new FutureTask<Path>( new Callable<Path>() { @Override public Path call() throws Exception { return service.setAttribute( path, attribute, value ); } } ) ); }
@Override public Path write( final Path path, final byte[] bytes, final OpenOption... options ) throws IOException, UnsupportedOperationException, SecurityException { return new FileSystemSyncLock<Path>( path.getFileSystem() ).execute( clusterService, new FutureTask<Path>( new Callable<Path>() { @Override public Path call() throws Exception { return service.write( path, bytes, options ); } } ) ); }
@Override public Path write( final Path path, final Iterable<? extends CharSequence> lines, final Charset cs, final OpenOption... options ) throws IllegalArgumentException, IOException, UnsupportedOperationException, SecurityException { return new FileSystemSyncLock<Path>( path.getFileSystem() ).execute( clusterService, new FutureTask<Path>( new Callable<Path>() { @Override public Path call() throws Exception { return service.write( path, lines, cs, options ); } } ) ); }
@Override public Path write( final Path path, final String content, final OpenOption... options ) throws IllegalArgumentException, IOException, UnsupportedOperationException { return new FileSystemSyncLock<Path>( path.getFileSystem() ).execute( clusterService, new FutureTask<Path>( new Callable<Path>() { @Override public Path call() throws Exception { return service.write( path, content, options ); } } ) ); }
@Override public Path createDirectory( final Path dir, final FileAttribute<?>... attrs ) throws IllegalArgumentException, UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException { return new FileSystemSyncLock<Path>( dir.getFileSystem() ).execute( clusterService, new FutureTask<Path>( new Callable<Path>() { @Override public Path call() throws Exception { return service.createDirectory( dir, attrs ); } } ) ); }
@Override public long copy( final InputStream in, final Path target, final CopyOption... options ) throws IOException, FileAlreadyExistsException, DirectoryNotEmptyException, UnsupportedOperationException, SecurityException { return new FileSystemSyncLock<Long>( target.getFileSystem() ).execute( clusterService, new FutureTask<Long>( new Callable<Long>() { @Override public Long call() throws Exception { return service.copy( in, target, options ); } } ) ); }
@Override public Path write( final Path path, final String content, final Charset cs, final Map<String, ?> attrs, final OpenOption... options ) throws IllegalArgumentException, IOException, UnsupportedOperationException { return new FileSystemSyncLock<Path>( path.getFileSystem() ).execute( clusterService, new FutureTask<Path>( new Callable<Path>() { @Override public Path call() throws Exception { return service.write( path, content, cs, attrs, options ); } } ) ); }
@Override public Path createDirectories( final Path dir, final FileAttribute<?>... attrs ) throws UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException { return new FileSystemSyncLock<Path>( dir.getFileSystem() ).execute( clusterService, new FutureTask<Path>( new Callable<Path>() { @Override public Path call() throws Exception { return service.createDirectories( dir, attrs ); } } ) ); }
@Override public boolean deleteIfExists( final Path path, final DeleteOption... options ) throws IllegalArgumentException, DirectoryNotEmptyException, IOException, SecurityException { return new FileSystemSyncLock<Boolean>( path.getFileSystem() ).execute( clusterService, new FutureTask<Boolean>( new Callable<Boolean>() { @Override public Boolean call() throws Exception { return service.deleteIfExists( path, options ); } } ) ); }
@Override public Path copy( final Path source, final Path target, final CopyOption... options ) throws UnsupportedOperationException, FileAlreadyExistsException, DirectoryNotEmptyException, IOException, SecurityException { return new FileSystemSyncLock<Path>( target.getFileSystem() ).execute( clusterService, new FutureTask<Path>( new Callable<Path>() { @Override public Path call() throws Exception { return service.copy( source, target, options ); } } ) ); }
@Override public Path call() throws Exception { return new FileSystemSyncLock<Path>( target.getFileSystem() ).execute( clusterService, new FutureTask<Path>( new Callable<Path>() { @Override public Path call() throws Exception { return service.move( source, target, options ); } } ) ); } } ) );
@Override public Path write( final Path path, final String content, final Charset cs, final OpenOption... options ) throws IllegalArgumentException, IOException, UnsupportedOperationException { return new FileSystemSyncLock<Path>( path.getFileSystem() ).execute( clusterService, new FutureTask<Path>( new Callable<Path>() { @Override public Path call() throws Exception { return service.write( path, content, cs, options ); } } ) ); }
@Override public Path restore( final Path _path, final String comment ) { final org.kie.commons.java.nio.file.Path path = paths.convert( _path ); final org.kie.commons.java.nio.file.Path target = path.getFileSystem().getPath( path.toString() ); return paths.convert( ioService.copy( path, target, REPLACE_EXISTING, new CommentedOption( identity.getName(), comment ) ) ); } }
@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" ); }