org.kie.commons.java.nio.file.Path.isAbsolute()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(14.8k)|赞(0)|评价(0)|浏览(150)

本文整理了Java中org.kie.commons.java.nio.file.Path.isAbsolute()方法的一些代码示例,展示了Path.isAbsolute()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Path.isAbsolute()方法的具体详情如下:
包路径:org.kie.commons.java.nio.file.Path
类名称:Path
方法名:isAbsolute

Path.isAbsolute介绍

暂无

代码示例

代码示例来源:origin: org.kie.commons/kie-nio2-model

@Override
public Path resolve( final Path other ) {
  checkNotNull( "other", other );
  if ( other.isAbsolute() ) {
    return other;
  }
  if ( other.toString().trim().length() == 0 ) {
    return this;
  }
  final StringBuilder sb = new StringBuilder();
  sb.append( new String( path ) );
  if ( path[ path.length - 1 ] != getSeparator() ) {
    sb.append( getSeparator() );
  }
  sb.append( other.toString() );
  return newPath( fs, sb.toString(), host, isRealPath, false );
}

代码示例来源:origin: org.kie.commons/kie-nio2-model

@Override
public Path resolveSibling( final Path other ) {
  checkNotNull( "other", other );
  final Path parent = this.getParent();
  if ( parent == null || other.isAbsolute() ) {
    return other;
  }
  return parent.resolve( other );
}

代码示例来源:origin: org.kie.commons/kie-nio2-jgit

@Test
public void testSimpleBranchedGitRoot() {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs, "/", "master@my-host", false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/");
  assertThat(path.getRoot().toString()).isEqualTo("/");
  assertThat(path.getNameCount()).isEqualTo(0);
}

代码示例来源:origin: org.kie.commons/kie-nio2-jgit

@Test
public void testSimpleBranchedGitRelative() {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs, "home", "master@my-host", false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isFalse();
  assertThat(path.toString()).isEqualTo("home");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/:home");
  assertThat(path.getRoot().toString()).isEqualTo("");
  assertThat(path.getNameCount()).isEqualTo(1);
}

代码示例来源:origin: org.kie.commons/kie-nio2-jgit

@Test
public void testPathBranchRooted2() throws IOException, GitAPIException {
  final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class );
  when( fsProvider.isDefault() ).thenReturn( false );
  when( fsProvider.getScheme() ).thenReturn( "git" );
  final Git git = setupGit();
  final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() );
  final Path path = fileSystem.getPath( "test-branch", "/path/to", "some/place.txt" );
  assertThat( path ).isNotNull();
  assertThat( path.isAbsolute() ).isTrue();
  assertThat( path.toString() ).isEqualTo( "/path/to/some/place.txt" );
  assertThat( path.toUri().toString() ).isEqualTo( "git://test-branch@my-repo/path/to/some/place.txt" );
  assertThat( path.getNameCount() ).isEqualTo( 4 );
  assertThat( path.getName( 0 ).toString() ).isNotNull().isEqualTo( "path" );
  assertThat( path.getRoot().toString() ).isNotNull().isEqualTo( "/" );
}

代码示例来源:origin: org.kie.commons/kie-nio2-jgit

@Test
public void testPathBranchNonRooted2() throws IOException, GitAPIException {
  final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class );
  when( fsProvider.isDefault() ).thenReturn( false );
  when( fsProvider.getScheme() ).thenReturn( "git" );
  final Git git = setupGit();
  final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() );
  final Path path = fileSystem.getPath( "test-branch", "path/to", "some/place.txt" );
  assertThat( path ).isNotNull();
  assertThat( path.isAbsolute() ).isFalse();
  assertThat( path.toString() ).isEqualTo( "path/to/some/place.txt" );
  assertThat( path.toUri().toString() ).isEqualTo( "git://test-branch@my-repo/:path/to/some/place.txt" );
  assertThat( path.getNameCount() ).isEqualTo( 4 );
  assertThat( path.getName( 0 ).toString() ).isNotNull().isEqualTo( "path" );
  assertThat( path.getRoot().toString() ).isNotNull().isEqualTo( "" );
}

代码示例来源:origin: org.kie.commons/kie-nio2-jgit

@Test
public void testSimpleImplicitBranchGit() {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs, "/path/to/some/place.txt", "my-host", false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/path/to/some/place.txt");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/path/to/some/place.txt");
  assertThat(path.getNameCount()).isEqualTo(4);
  assertThat(path.getName(0).toString()).isNotNull().isEqualTo("path");
  assertThat(path.getRoot().toString()).isNotNull().isEqualTo("/");
}

代码示例来源:origin: org.kie.commons/kie-nio2-jgit

@Test
public void testSimpleBranchedGitRoot2() {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs, "/path/to/some/place.txt", "master@my-host", false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/path/to/some/place.txt");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/path/to/some/place.txt");
  assertThat(path.getNameCount()).isEqualTo(4);
  assertThat(path.getName(0).toString()).isNotNull().isEqualTo("path");
  assertThat(path.getRoot().toString()).isNotNull().isEqualTo("/");
}

代码示例来源:origin: org.kie.commons/kie-nio2-jgit

@Test
public void testPathBranchRooted() throws IOException, GitAPIException {
  final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class );
  when( fsProvider.isDefault() ).thenReturn( false );
  when( fsProvider.getScheme() ).thenReturn( "git" );
  final Git git = setupGit();
  final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() );
  final Path path = fileSystem.getPath( "test-branch", "/path/to/some/place.txt" );
  assertThat( path ).isNotNull();
  assertThat( path.isAbsolute() ).isTrue();
  assertThat( path.toString() ).isEqualTo( "/path/to/some/place.txt" );
  assertThat( path.toUri().toString() ).isEqualTo( "git://test-branch@my-repo/path/to/some/place.txt" );
  assertThat( path.getNameCount() ).isEqualTo( 4 );
  assertThat( path.getName( 0 ).toString() ).isNotNull().isEqualTo( "path" );
  assertThat( path.getRoot().toString() ).isNotNull().isEqualTo( "/" );
}

代码示例来源:origin: org.kie.commons/kie-nio2-jgit

@Test
public void testPathNonBranchRooted() throws IOException, GitAPIException {
  final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class );
  when( fsProvider.isDefault() ).thenReturn( false );
  when( fsProvider.getScheme() ).thenReturn( "git" );
  final Git git = setupGit();
  final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() );
  final Path path = fileSystem.getPath( "/path/to/some/place.txt" );
  assertThat( path ).isNotNull();
  assertThat( path.isAbsolute() ).isTrue();
  assertThat( path.toString() ).isEqualTo( "/path/to/some/place.txt" );
  assertThat( path.toUri().toString() ).isEqualTo( "git://master@my-repo/path/to/some/place.txt" );
  assertThat( path.getNameCount() ).isEqualTo( 4 );
  assertThat( path.getName( 0 ).toString() ).isNotNull().isEqualTo( "path" );
  assertThat( path.getRoot().toString() ).isNotNull().isEqualTo( "/" );
}

代码示例来源:origin: org.kie.commons/kie-nio2-jgit

@Test
public void testPathNonBranchNonRooted() throws IOException, GitAPIException {
  final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class );
  when( fsProvider.isDefault() ).thenReturn( false );
  when( fsProvider.getScheme() ).thenReturn( "git" );
  final Git git = setupGit();
  final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() );
  final Path path = fileSystem.getPath( "path/to/some/place.txt" );
  assertThat( path ).isNotNull();
  assertThat( path.isAbsolute() ).isFalse();
  assertThat( path.toString() ).isEqualTo( "path/to/some/place.txt" );
  assertThat( path.toUri().toString() ).isEqualTo( "git://master@my-repo/:path/to/some/place.txt" );
  assertThat( path.getNameCount() ).isEqualTo( 4 );
  assertThat( path.getName( 0 ).toString() ).isNotNull().isEqualTo( "path" );
  assertThat( path.getRoot().toString() ).isNotNull().isEqualTo( "" );
}

代码示例来源:origin: org.kie.commons/kie-nio2-jgit

@Test
public void testPathBranchNonRooted() throws IOException, GitAPIException {
  final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class );
  when( fsProvider.isDefault() ).thenReturn( false );
  when( fsProvider.getScheme() ).thenReturn( "git" );
  final Git git = setupGit();
  final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() );
  final Path path = fileSystem.getPath( "test-branch", "path/to/some/place.txt" );
  assertThat( path ).isNotNull();
  assertThat( path.isAbsolute() ).isFalse();
  assertThat( path.toString() ).isEqualTo( "path/to/some/place.txt" );
  assertThat( path.toUri().toString() ).isEqualTo( "git://test-branch@my-repo/:path/to/some/place.txt" );
  assertThat( path.getNameCount() ).isEqualTo( 4 );
  assertThat( path.getName( 0 ).toString() ).isNotNull().isEqualTo( "path" );
  assertThat( path.getRoot().toString() ).isNotNull().isEqualTo( "" );
}

代码示例来源:origin: org.kie.commons/kie-nio2-jgit

@Test
public void testSimpleBranchedGitRoot2Spaced() throws URIException {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs, URIUtil.decode("/path/to/some/some%20place.txt"), "master@my-host", false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/path/to/some/some place.txt");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/path/to/some/some%20place.txt");
  assertThat(path.getNameCount()).isEqualTo(4);
  assertThat(path.getName(0).toString()).isNotNull().isEqualTo("path");
  assertThat(path.getRoot().toString()).isNotNull().isEqualTo("/");
}

代码示例来源:origin: org.kie.commons/kie-nio2-jgit

@Test
public void testSimpleImplicitBranchGitRoot() {
  when(fs.getSeparator()).thenReturn("/");
  final Path path = JGitPathImpl.create(fs, "/", "my-host", false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/");
  assertThat(path.getRoot().toString()).isEqualTo("/");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/");
  assertThat(path.getNameCount()).isEqualTo(0);
  assertThat(path.getRoot().toString()).isNotNull().isEqualTo("/");
  try {
    assertThat(path.getName(0).toString()).isNotNull().isEqualTo("");
    failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
  } catch (IllegalArgumentException ex) {
  }
}

代码示例来源:origin: org.kie.commons/kie-nio2-fs

@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" );
}

代码示例来源:origin: org.kie.commons/kie-nio2-jgit

@Test
public void testSimpleBranchedGit() {
  final Path path = JGitPathImpl.create(fs, "", "master@my-host", false);
  assertThat(path).isNotNull();
  assertThat(path.isAbsolute()).isTrue();
  assertThat(path.toString()).isEqualTo("/");
  assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/");
  assertThat(path.getRoot()).isEqualTo(path);
  assertThat(path.getNameCount()).isEqualTo(0);
  assertThat(path.getRoot()).isNotNull().isEqualTo(path);
}

代码示例来源:origin: org.kie.commons/kie-nio2-fs

@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();
}

代码示例来源:origin: org.kie.commons/kie-nio2-fs

@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();
}

相关文章