當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。