/** * @throws IllegalArgumentException * @see <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/file/Paths.html#get(java.lang.String, java.lang.String...)">JDK JavaDoc</a> */ public static Path get(final String first, final String... more) throws IllegalArgumentException { checkNotNull("first", first); if (first.trim().length() == 0) { return FileSystems.getDefault().getPath(first); } URI uri = null; if (more == null || more.length == 0) { try { uri = new URI(first); } catch (URISyntaxException ex) { try { uri = URI.create(first); } catch (IllegalArgumentException e) { uri = null; } } } if (uri != null && uri.getScheme() != null) { return get(uri); } return FileSystems.getDefault().getPath(first, more); }
@Override public boolean endsWith( final String other ) throws InvalidPathException { checkNotNull( "other", other ); return endsWith( getFileSystem().getPath( other ) ); }
@Override public boolean startsWith( final String other ) throws InvalidPathException { checkNotNull( "other", other ); return startsWith( getFileSystem().getPath( other ) ); }
@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 simpleRootTests() throws URISyntaxException { final SimpleFileSystemProvider fs = new SimpleFileSystemProvider(); final FileSystem fileSystem = new SimpleUnixFileSystem( fsProvider, "/" ); assertThat( fileSystem.getPath( "/" ) ).isEqualTo( fileSystem.getPath( "/path" ).getParent() ); final URL parentUrl = this.getClass().getResource( "/" ); final Path parentNioPath = fs.getPath( parentUrl.toURI() ); final URL childUrl = this.getClass().getResource( "/Folder" ); final Path childNioPath = fs.getPath( childUrl.toURI() ); final Path childParentNioPath = childNioPath.getParent(); System.out.println( parentNioPath ); assertThat( parentNioPath ).isEqualTo( childParentNioPath ); }
final Path fsPath = path.getFileSystem().getPath( null ); PROVIDER.delete( fsPath ); assertThat( fsPath.getFileSystem().isOpen() ).isEqualTo( false );
@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(); }
assertThat( fs.getPath( "file.txt" ).toFile() ).isNotNull().exists();