MCPcopy Create free account
hub / github.com/google/guava / equal

Method equal

android/guava/src/com/google/common/io/MoreFiles.java:366–386  ·  view source on GitHub ↗

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

(Path path1, Path path2)

Source from the content-addressed store, hash-verified

364 * @since 22.0
365 */
366 public static boolean equal(Path path1, Path path2) throws IOException {
367 checkNotNull(path1);
368 checkNotNull(path2);
369 if (Files.isSameFile(path1, path2)) {
370 return true;
371 }
372
373 /*
374 * Some operating systems may return zero as the length for files denoting system-dependent
375 * entities such as devices or pipes, in which case we must fall back on comparing the bytes
376 * directly.
377 */
378 ByteSource source1 = asByteSource(path1);
379 ByteSource source2 = asByteSource(path2);
380 long len1 = source1.sizeIfKnown().or(0L);
381 long len2 = source2.sizeIfKnown().or(0L);
382 if (len1 != 0 && len2 != 0 && len1 != len2) {
383 return false;
384 }
385 return source1.contentEquals(source2);
386 }
387
388 /**
389 * Like the unix command of the same name, creates an empty file or updates the last modified

Callers 2

testEqualMethod · 0.95
testEqual_linksMethod · 0.95

Calls 5

asByteSourceMethod · 0.95
sizeIfKnownMethod · 0.95
contentEqualsMethod · 0.95
checkNotNullMethod · 0.45
orMethod · 0.45

Tested by 2

testEqualMethod · 0.76
testEqual_linksMethod · 0.76