Java Code Examples for java.nio.file.Files#isSameFile()

The following examples show how to use java.nio.file.Files#isSameFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AtlasMainDexHelper.java    From atlas with Apache License 2.0 6 votes vote down vote up
public void updateMainDexFile(File oldFile, File newFile) {
    for (BuildAtlasEnvTask.FileIdentity id : mainDexJar) {
        if (!id.file.exists()){
            continue;
        }
        try {
            if (Files.isSameFile(oldFile.toPath(), id.file.toPath())) {
                id.file = newFile;
                break;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
 
Example 2
Source File: DirectoryConnector.java    From brooklin with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void initializeDatastream(Datastream stream, List<Datastream> allDatastreams)
    throws DatastreamValidationException {
  Validate.notNull(stream);
  Validate.notNull(allDatastreams);

  LOG.info("validating datastream " + stream.toString());

  String sourceDirectoryPath = stream.getSource().getConnectionString();
  validateDirectoryPath(sourceDirectoryPath);

  String destDirectoryPath = stream.getDestination().getConnectionString();
  validateDirectoryPath(destDirectoryPath);

  try {
    if (Files.isSameFile(Paths.get(sourceDirectoryPath), Paths.get(destDirectoryPath))) {
      throw new DatastreamValidationException("Source and destination paths cannot refer to the same directory");
    }
  } catch (IOException ex) {
    throw new DatastreamValidationException("Could not verify if source and destination paths are different", ex);
  }

  // single partition datastream
  stream.getSource().setPartitions(1);
}
 
Example 3
Source File: SmartTestingMavenConfigurer.java    From smart-testing with Apache License 2.0 5 votes vote down vote up
private boolean isProjectRootDirectory(File file) {
    try {
        return file.isDirectory()
            && Files.isSameFile(file.toPath(), new File(System.getenv("MAVEN_PROJECTBASEDIR")).toPath());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 4
Source File: ConfigLookupTest.java    From smart-testing with Apache License 2.0 5 votes vote down vote up
private boolean isProjectRootDirectory(File dir) {
    try {
        return Files.isSameFile(dir.toPath(), temporaryFolder.getRoot().toPath());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 5
Source File: PathFileObject.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public boolean isSameFile(PathFileObject other) {
    try {
        return Files.isSameFile(path, other.path);
    } catch (IOException e) {
        return false;
    }
}
 
Example 6
Source File: PathDocFileFactory.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/** Return true if this file is the same as another. */
public boolean isSameFile(DocFile other) {
    if (!(other instanceof StandardDocFile))
        return false;

    try {
        return Files.isSameFile(file, ((StandardDocFile) other).file);
    } catch (IOException e) {
        return false;
    }
}
 
Example 7
Source File: Main.java    From Java-Coding-Problems with MIT License 5 votes vote down vote up
public static void main(String[] args) throws IOException {

        Path path1 = Paths.get("/learning/packt/JavaModernChallenge.pdf");
        Path path2 = Paths.get("/LEARNING/PACKT/JavaModernChallenge.pdf");
        Path path3 = Paths.get("D:/learning/packt/JavaModernChallenge.pdf");

        boolean path1EqualsPath2 = path1.equals(path2);
        boolean path2EqualsPath3 = path2.equals(path3);
        System.out.println("path1.equals(path2): " + path1EqualsPath2);
        System.out.println("path2.equals(path3): " + path2EqualsPath3);

        boolean path1IsSameFilePath2 = Files.isSameFile(path1, path2);
        boolean path1IsSameFilePath3 = Files.isSameFile(path1, path3);
        boolean path2IsSameFilePath3 = Files.isSameFile(path2, path3);
        System.out.println("\nisSameFile(path1, path2): " + path1IsSameFilePath2);
        System.out.println("isSameFile(path1, path3): " + path1IsSameFilePath3);
        System.out.println("isSameFile(path2, path3): " + path2IsSameFilePath3);

        int path1compareToPath2 = path1.compareTo(path2);
        int path1compareToPath3 = path1.compareTo(path3);
        int path2compareToPath3 = path2.compareTo(path3);
        System.out.println("\npath1.compareTo(path2): " + path1compareToPath2);
        System.out.println("path1.compareTo(path3): " + path1compareToPath3);
        System.out.println("path2.compareTo(path3): " + path2compareToPath3);

        boolean sw = path1.startsWith("/learning/packt");
        boolean ew = path1.endsWith("JavaModernChallenge.pdf");
        System.out.println("\nStart width: " + sw);
        System.out.println("End with: " + ew);
    }
 
Example 8
Source File: Locations.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private boolean contains(Collection<Path> searchPath, Path file) throws IOException {

        if (searchPath == null) {
            return false;
        }

        Path enclosingJar = null;
        if (file.getFileSystem().provider() == fsInfo.getJarFSProvider()) {
            URI uri = file.toUri();
            if (uri.getScheme().equals("jar")) {
                String ssp = uri.getSchemeSpecificPart();
                int sep = ssp.lastIndexOf("!");
                if (ssp.startsWith("file:") && sep > 0) {
                    enclosingJar = Paths.get(URI.create(ssp.substring(0, sep)));
                }
            }
        }

        Path nf = normalize(file);
        for (Path p : searchPath) {
            Path np = normalize(p);
            if (np.getFileSystem() == nf.getFileSystem()
                    && Files.isDirectory(np)
                    && nf.startsWith(np)) {
                return true;
            }
            if (enclosingJar != null
                    && Files.isSameFile(enclosingJar, np)) {
                return true;
            }
        }

        return false;
    }
 
Example 9
Source File: StandardDocFileFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/** Return true if this file is the same as another. */
@Override
public boolean isSameFile(DocFile other) {
    if (!(other instanceof StandardDocFile))
        return false;

    try {
        return Files.isSameFile(file, ((StandardDocFile) other).file);
    } catch (IOException e) {
        return false;
    }
}
 
Example 10
Source File: PathFileObject.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public boolean isSameFile(PathFileObject other) {
    try {
        return Files.isSameFile(path, other.path);
    } catch (IOException e) {
        return false;
    }
}
 
Example 11
Source File: PathFileObject.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public boolean isSameFile(PathFileObject other) {
    try {
        return Files.isSameFile(path, other.path);
    } catch (IOException e) {
        return false;
    }
}
 
Example 12
Source File: JdepsTask.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private boolean hasSameFile(List<Path> paths, Path p2) throws IOException {
    for (Path p1 : paths) {
        if (Files.isSameFile(p1, p2)) {
            return true;
        }
    }
    return false;
}
 
Example 13
Source File: FaultyFileSystem.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isSameFile(Path file, Path other) throws IOException {
    triggerEx(file, "isSameFile");
    return Files.isSameFile(unwrap(file), unwrap(other));
}
 
Example 14
Source File: FaultyFileSystem.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isSameFile(Path file, Path other) throws IOException {
    triggerEx(file, "isSameFile");
    return Files.isSameFile(unwrap(file), unwrap(other));
}
 
Example 15
Source File: DatabaseRestorerImpl.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean isRestoreFromLocation(final File location) throws IOException {
  return Files.isSameFile(restoreFromLocation.toPath(), location.toPath());
}
 
Example 16
Source File: EncryptedFileSystemProvider.java    From encfs4j with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isSameFile(Path file, Path other) throws IOException {
	return Files.isSameFile(EncryptedFileSystem.dismantle(file),
			EncryptedFileSystem.dismantle(other));
}
 
Example 17
Source File: GuiUtils.java    From TerasologyLauncher with Apache License 2.0 4 votes vote down vote up
private static boolean deleteProposedDirectoryIfUnused(Path proposed, Path selected) throws IOException {
    return selected != null
            && !Files.isSameFile(proposed, selected)
            && !LauncherDirectoryUtils.containsFiles(proposed)
            && !Files.deleteIfExists(proposed);
}
 
Example 18
Source File: FaultyFileSystem.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isSameFile(Path file, Path other) throws IOException {
    triggerEx(file, "isSameFile");
    return Files.isSameFile(unwrap(file), unwrap(other));
}
 
Example 19
Source File: FaultyFileSystem.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isSameFile(Path file, Path other) throws IOException {
    triggerEx(file, "isSameFile");
    return Files.isSameFile(unwrap(file), unwrap(other));
}
 
Example 20
Source File: FaultyFileSystem.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isSameFile(Path file, Path other) throws IOException {
    triggerEx(file, "isSameFile");
    return Files.isSameFile(unwrap(file), unwrap(other));
}