当前位置: 首页>>代码示例>>Java>>正文


Java Files.isSameFile方法代码示例

本文整理汇总了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);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:29,代码来源:MoreFiles.java

示例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);
}
 
开发者ID:revelc,项目名称:impsort-maven-plugin,代码行数:20,代码来源:Result.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:Archive.java

示例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);
	}
}
 
开发者ID:sfPlayer1,项目名称:Matcher,代码行数:13,代码来源:InputFile.java

示例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);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:15,代码来源:FileSystemServiceImpl.java

示例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);
    }
}
 
开发者ID:arquillian,项目名称:smart-testing,代码行数:9,代码来源:SmartTestingMavenConfigurer.java

示例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);
    }
}
 
开发者ID:arquillian,项目名称:smart-testing,代码行数:8,代码来源:ConfigLookupTest.java

示例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;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:PathFileObject.java

示例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;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:PathDocFileFactory.java

示例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;
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:Locations.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:Locations.java

示例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;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:StandardDocFileFactory.java

示例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));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:FaultyFileSystem.java

示例14: processChangedFile

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
protected void processChangedFile(Path filePath) throws Exception {
    if (Files.isSameFile(rossvyazFile, filePath)) {
        onUpdate.run();
    }
}
 
开发者ID:chukanov,项目名称:mnp,代码行数:7,代码来源:RossvyazMasksParser.java

示例15: processChangedFile

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
protected void processChangedFile(Path filePath) throws Exception {
    if (Files.isSameFile(config, filePath)) {
        onUpdate.run();
    }
}
 
开发者ID:chukanov,项目名称:mnp,代码行数:7,代码来源:CustomMasksParser.java


注:本文中的java.nio.file.Files.isSameFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。