< prev index next >
src/java.base/share/classes/java/nio/file/Files.java
Print this page
*** 89,98 ****
--- 89,101 ----
*
* @since 1.7
*/
public final class Files {
+ // buffer size used for reading and writing
+ static final int BUFFER_SIZE = 8192;
+
private Files() { }
/**
* Returns the {@code FileSystemProvider} to delegate to.
*/
*** 1528,1537 ****
--- 1531,1587 ----
*/
public static boolean isSameFile(Path path, Path path2) throws IOException {
return provider(path).isSameFile(path, path2);
}
+
+ /**
+ * Finds and returns the index of the first mismatched byte in the content
+ * of two files, or returns -1 if the files are equal.
+ *
+ * <p> Two files are considered equal if they satisfy one of the following
+ * conditions:
+ * <ul>
+ * <li> {@link #isSameFile(Path, Path) isSameFile(path, path2)} returns true,</li>
+ * <li> the files are the same length, and every byte of the first file equals
+ * the corresponding byte of the second file.</li>
+ * </ul>
+ *
+ * <p>Otherwise, there is a mismatch between the two files. This method returns
+ * a mismatch value, computed as follows:
+ * <ul>
+ * <li> the index of the first position in the files at which mismatched bytes
+ * are found, or</li>
+ * <li> the length of the smaller file, if the files are of unequal length,
+ * and if every byte of the smaller file equals the corresponding byte of
+ * the larger file.</li>
+ * </ul>
+ *
+ * <p>This method may not be atomic with respect to other file system operations.
+ *
+ * @param path
+ * the path to the first file
+ * @param path2
+ * the path to the second file
+ *
+ * @return the index of the first mismatch between the two files, or {@code -1}
+ * if there is no mismatch.
+ *
+ * @throws IOException
+ * if an I/O error occurs, or path or path2 does not exist unless
+ * they are the same object
+ * @throws SecurityException
+ * In the case of the default provider, and a security manager is
+ * installed, the {@link SecurityManager#checkRead(String) checkRead}
+ * method is invoked to check read access to both files.
+ * @since 12
+ *
+ */
+ public static long mismatch(Path path, Path path2) throws IOException {
+ return FilesMismatch.mismatch(path, path2);
+ }
+
/**
* Tells whether or not a file is considered <em>hidden</em>. The exact
* definition of hidden is platform or provider dependent. On UNIX for
* example a file is considered to be hidden if its name begins with a
* period character ('.'). On Windows a file is considered hidden if it
*** 2800,2811 ****
}
// -- Utility methods for simple usages --
- // buffer size used for reading and writing
- private static final int BUFFER_SIZE = 8192;
/**
* Opens a file for reading, returning a {@code BufferedReader} that may be
* used to read text from the file in an efficient manner. Bytes from the
* file are decoded into characters using the specified charset. Reading
--- 2850,2859 ----
< prev index next >