本文整理汇总了Java中java.nio.file.Files.isSameFile方法的典型用法代码示例。如果您正苦于以下问题:Java Files.isSameFile方法的具体用法?Java Files.isSameFile怎么用?Java Files.isSameFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.Files
的用法示例。
在下文中一共展示了Files.isSameFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: equal
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Returns true if the files located by the given paths exist, are not directories, and contain
* the same bytes.
*
* @throws IOException if an I/O error occurs
* @since 22.0
*/
public static boolean equal(Path path1, Path path2) throws IOException {
checkNotNull(path1);
checkNotNull(path2);
if (Files.isSameFile(path1, path2)) {
return true;
}
/*
* Some operating systems may return zero as the length for files denoting system-dependent
* entities such as devices or pipes, in which case we must fall back on comparing the bytes
* directly.
*/
ByteSource source1 = asByteSource(path1);
ByteSource source2 = asByteSource(path2);
long len1 = source1.sizeIfKnown().or(0L);
long len2 = source2.sizeIfKnown().or(0L);
if (len1 != 0 && len2 != 0 && len1 != len2) {
return false;
}
return source1.contentEquals(source2);
}
示例2: saveSorted
import java.nio.file.Files; //导入方法依赖的package包/类
public void saveSorted(Path destination) throws IOException {
if (isSorted) {
if (!Files.isSameFile(path, destination)) {
saveBackup(destination);
}
return;
}
List<String> beforeImports = fileLines.subList(0, start);
List<String> importLines = Arrays.asList(newSection.split("\\n"));
List<String> afterImports = fileLines.subList(stop, fileLines.size());
List<String> allLines = new ArrayList<>(beforeImports.size() + importLines.size() + afterImports.size() + 1);
allLines.addAll(beforeImports);
allLines.addAll(importLines);
if (afterImports.size() > 0) {
allLines.add(""); // restore blank line lost by split("\\n")
}
allLines.addAll(afterImports);
Files.write(destination, allLines);
}
示例3: isSameLocation
import java.nio.file.Files; //导入方法依赖的package包/类
public static boolean isSameLocation(Archive archive, Archive other) {
if (archive.path == null || other.path == null)
return false;
if (archive.location != null && other.location != null &&
archive.location.equals(other.location)) {
return true;
}
if (archive.isJrt() || other.isJrt()) {
return false;
}
try {
return Files.isSameFile(archive.path, other.path);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例4: equals
import java.nio.file.Files; //导入方法依赖的package包/类
public boolean equals(Path path) {
try {
if (this.path != null) return Files.isSameFile(path, this.path);
if (!getSanitizedFileName(path).equals(fileName)) return false;
if (Files.size(path) != size) return false;
return Arrays.equals(sha256, hash(path));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例5: isSameFile
import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public boolean isSameFile(FileHandle handle1, String path1, FileHandle handle2, String path2)
{
final File file1 = getFile(handle1, path1);
final File file2 = getFile(handle2, path2);
try
{
return Files.isSameFile(file1.toPath(), file2.toPath());
}
catch( IOException e )
{
throw Throwables.propagate(e);
}
}
示例6: isProjectRootDirectory
import java.nio.file.Files; //导入方法依赖的package包/类
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);
}
}
示例7: isProjectRootDirectory
import java.nio.file.Files; //导入方法依赖的package包/类
private boolean isProjectRootDirectory(File dir) {
try {
return Files.isSameFile(dir.toPath(), temporaryFolder.getRoot().toPath());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例8: isSameFile
import java.nio.file.Files; //导入方法依赖的package包/类
public boolean isSameFile(PathFileObject other) {
try {
return Files.isSameFile(path, other.path);
} catch (IOException e) {
return false;
}
}
示例9: isSameFile
import java.nio.file.Files; //导入方法依赖的package包/类
/** 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;
}
}
示例10: contains
import java.nio.file.Files; //导入方法依赖的package包/类
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;
}
示例11: isCurrentPlatform
import java.nio.file.Files; //导入方法依赖的package包/类
private boolean isCurrentPlatform(Path p) {
try {
return Files.isSameFile(p, Locations.javaHome);
} catch (IOException ex) {
throw new IllegalArgumentException(p.toString(), ex);
}
}
示例12: isSameFile
import java.nio.file.Files; //导入方法依赖的package包/类
/** 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;
}
}
示例13: isSameFile
import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public boolean isSameFile(Path file, Path other) throws IOException {
triggerEx(file, "isSameFile");
return Files.isSameFile(unwrap(file), unwrap(other));
}
示例14: processChangedFile
import java.nio.file.Files; //导入方法依赖的package包/类
@Override
protected void processChangedFile(Path filePath) throws Exception {
if (Files.isSameFile(rossvyazFile, filePath)) {
onUpdate.run();
}
}
示例15: processChangedFile
import java.nio.file.Files; //导入方法依赖的package包/类
@Override
protected void processChangedFile(Path filePath) throws Exception {
if (Files.isSameFile(config, filePath)) {
onUpdate.run();
}
}