MD5Digester { @Nullable public String digestFileAs32ByteHex(@Nonnull File file) { requireNonNull(file, "Null file passed to MD5Digester.digestFileAs32ByteHex()"); if (Files.isReadable(file.toPath())) { try (FileInputStream inStream = new FileInputStream(file)) { reset(); byte[] inBytes = new byte[bufferSize]; int inBytesRead; while ((inBytesRead = inStream.read(inBytes)) > 0) { update(inBytes, 0, inBytesRead); } return digestAs32ByteHex(); } catch (final IOException ioexc) { Log.error("error digesting file: " + file.getPath() + "; exception follows..."); Log.exception(ioexc); } } return null; } MD5Digester();  MD5Digester(@Nonnull int bufferSize); byte[] digestAsBytes(); @Nullable String digestFileAs32ByteHex(@Nonnull File file); void reset(); void update(byte[] bytes, int off, int len); String digestAs32ByteHex(); @Nullable String digestFileAs32ByteHex(@Nonnull File file, @Nullable Charset charset); @Nullable String digestFileAs32ByteHex(@Nonnull File file, @Nullable Charset charset,
	                                    boolean doesNeedConvertLineEndings); @Nullable String digestFileAs32ByteHex(@Nonnull File file, @Nullable Charset charset,
	                                    boolean isRequireLineEndingConvert, @Nullable ClientLineEnding clientLineEnding); void update(String str); void update(byte[] bytes); @Deprecated void update(ByteBuffer byteBuf);  }
@Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndings() { String actual = md5Digester.digestFileAs32ByteHex(normTestFile, Charset.forName("UTF-8"), true); assertThat(actual, is(expectedTestFileMd5)); if (OSUtils.isWindows()) { actual = md5Digester.digestFileAs32ByteHex(windowsTestFile, Charset.forName("UTF-8"), true); assertThat(actual, is(expectedTestFileMd5)); } }
@Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndingsClientLineEnding() { String actual = md5Digester.digestFileAs32ByteHex(windowsTestFile, Charset.forName("UTF-8"), false, null); assertThat(actual, is(expectedTestFileMd5Win)); actual = md5Digester.digestFileAs32ByteHex(normTestFile, Charset.forName("UTF-8"), false, null); assertThat(actual, is(expectedTestFileMd5)); }
@Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndingsClientLineEndingNonCharset() { String actual = md5Digester.digestFileAs32ByteHex(windowsTestFile, null, false, null); assertThat(actual, is(expectedTestFileMd5Win)); actual = md5Digester.digestFileAs32ByteHex(normTestFile, null, false, null); assertThat(actual, is(expectedTestFileMd5)); }
@Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndingsClientLineEndingNonCharset_needConvertLindEnding() { String actual = md5Digester.digestFileAs32ByteHex(normTestFile, Charset.forName("UTF-8"), true, null); assertThat(actual, is(expectedTestFileMd5)); actual = md5Digester.digestFileAs32ByteHex(windowsTestFile, Charset.forName("UTF-8"), true, null); }
@DisplayName("test digestFileAs32ByteHex(File file, Charset charset, boolean doesNeedConvertLineEndings, ClientLineEnding clientLineEnding) throw exception") @Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndingsClientLineEndingNonCharset_throwException() { File dirAsFile = new File(System.getProperty("java.io.tmpdir")); String actual = md5Digester.digestFileAs32ByteHex(dirAsFile, Charset.forName("UTF-8"), true, null); assertNull(actual); }
@Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndingsClientLineEndingNonCharset_nonNullClientLineEnding() { String actual = md5Digester.digestFileAs32ByteHex(windowsTestFile, Charset.forName("UTF-8"), true, ClientLineEnding.FST_L_CR); assertThat(actual, is(expectedTestFileMd5WinNonNullEnding)); actual = md5Digester.digestFileAs32ByteHex(normTestFile, Charset.forName("UTF-8"), true, ClientLineEnding.FST_L_CR); assertThat(actual, is(expectedTestFileMd5)); }
@Test public void testDigestFileAs32ByteHexFile() { String actual = md5Digester.digestFileAs32ByteHex(windowsTestFile); assertThat(actual, is(expectedTestFileMd5Win)); actual = md5Digester.digestFileAs32ByteHex(normTestFile); assertThat(actual, is(expectedTestFileMd5)); }
@Test public void testDigestFileAs32ByteHex_file_charset() { String actual = md5Digester.digestFileAs32ByteHex(windowsTestFile, Charset.forName("UTF-8")); assertThat(actual, is(expectedTestFileMd5Win)); actual = md5Digester.digestFileAs32ByteHex(normTestFile, Charset.forName("UTF-8")); assertThat(actual, is(expectedTestFileMd5)); }
@DisplayName("test digestFileAs32ByteHexFile(File file) throws an exception") @Test public void testDigestFileAs32ByteHexFile_withException() { File dirAsFile = new File(System.getProperty("java.io.tmpdir")); String actual = md5Digester.digestFileAs32ByteHex(dirAsFile); assertNull(actual); }
@Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndings() throws Exception { String actual = md5Digester.digestFileAs32ByteHex(testFile, Charset.forName("UTF-8"), true); assertThat(actual, is(expectedTestFileMd5)); }
@Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndingsClientLineEnding() throws Exception { String actual = md5Digester.digestFileAs32ByteHex(testFile, Charset.forName("UTF-8"), false, null); assertThat(actual, is(isWindows ? expectedTestFileMd5Win : expectedTestFileMd5)); }
@Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndingsClientLineEndingNonCharset() throws Exception { String actual = md5Digester.digestFileAs32ByteHex(testFile, null, false, null); assertThat(actual, is(isWindows ? expectedTestFileMd5Win : expectedTestFileMd5)); }
@Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndingsClientLineEndingNonCharset_needConvertLindEnding() throws Exception { String actual = md5Digester.digestFileAs32ByteHex(testFile, Charset.forName("UTF-8"), true, null); assertThat(actual, is(expectedTestFileMd5)); }
@DisplayName("test digestFileAs32ByteHex(File file, Charset charset, boolean doesNeedConvertLineEndings, ClientLineEnding clientLineEnding) throw exception") @Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndingsClientLineEndingNonCharset_throwException() throws Exception { File dirAsFile = new File(System.getProperty("java.io.tmpdir")); String actual = md5Digester.digestFileAs32ByteHex(dirAsFile, Charset.forName("UTF-8"), true, null); assertNull(actual); }
@Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndingsClientLineEndingNonCharset_nonNullClientLineEnding() throws Exception { String actual = md5Digester.digestFileAs32ByteHex(testFile, Charset.forName("UTF-8"), true, ClientLineEnding.FST_L_CR); assertThat(actual, is(isWindows ? expectedTestFileMd5WinNonNullEnding : expectedTestFileMd5)); }
@Test public void testDigestFileAs32ByteHexFile() throws Exception { String actual = md5Digester.digestFileAs32ByteHex(testFile); assertThat(actual, is(isWindows ? expectedTestFileMd5Win : expectedTestFileMd5)); }
@Test public void testDigestFileAs32ByteHex_file_charset() throws Exception { String actual = md5Digester.digestFileAs32ByteHex(testFile, Charset.forName("UTF-8")); assertThat(actual, is(isWindows ? expectedTestFileMd5Win : expectedTestFileMd5)); }
@DisplayName("test digestFileAs32ByteHexFile(File file) throws an exception") @Test public void testDigestFileAs32ByteHexFile_withException() throws Exception { File dirAsFile = new File(System.getProperty("java.io.tmpdir")); String actual = md5Digester.digestFileAs32ByteHex(dirAsFile); assertNull(actual); }
@Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndings() throws Exception { RpcPerforceFile testFile = new RpcPerforceFile(testFileName, RpcPerforceFileType.FST_BINARY, ClientLineEnding.FST_L_LF); String actual = md5Digester.digestFileAs32ByteHex(testFile, Charset.forName("UTF-8")); assertThat(actual, is(isWindows ? expectedTestFileMd5Win : expectedTestFileMd5)); }
@Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndingsClientLineEnding() throws Exception { RpcPerforceFile testFile = new RpcPerforceFile(testFileName, RpcPerforceFileType.FST_BINARY, ClientLineEnding.FST_L_LF); String actual = md5Digester.digestFileAs32ByteHex(testFile, Charset.forName("UTF-8")); assertThat(actual, is(isWindows ? expectedTestFileMd5Win : expectedTestFileMd5)); }
@Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndingsClientLineEndingNonCharset() throws Exception { RpcPerforceFile testFile = new RpcPerforceFile(testFileName, RpcPerforceFileType.FST_BINARY, ClientLineEnding.FST_L_LF); String actual = md5Digester.digestFileAs32ByteHex(testFile, null); assertThat(actual, is(isWindows ? expectedTestFileMd5Win : expectedTestFileMd5)); }
@Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndingsClientLineEndingNonCharset_needConvertLindEnding() throws Exception { RpcPerforceFile testFile = new RpcPerforceFile(testFileName, RpcPerforceFileType.FST_BINARY, ClientLineEnding.FST_L_LF); String actual = md5Digester.digestFileAs32ByteHex(testFile, Charset.forName("UTF-8")); assertThat(actual, is(isWindows ? expectedTestFileMd5Win : expectedTestFileMd5)); }
@Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndingsClientLineEndingNonCharset_throwException() throws Exception { RpcPerforceFile testFile = new RpcPerforceFile(System.getProperty("java.io.tmpdir"), RpcPerforceFileType.FST_BINARY, ClientLineEnding.FST_L_LF); String actual = md5Digester.digestFileAs32ByteHex(testFile, Charset.forName("UTF-8")); assertNull(actual); }
@Test public void testDigestFileAs32ByteHexForFileCharsetConvertLineEndingsClientLineEndingNonCharset_nonNullClientLineEnding() throws Exception { RpcPerforceFile testFile = new RpcPerforceFile(testFileName, RpcPerforceFileType.FST_BINARY, ClientLineEnding.FST_L_LF); String actual = md5Digester.digestFileAs32ByteHex(testFile, Charset.forName("UTF-8")); assertThat(actual, is(isWindows ? expectedTestFileMd5Win : expectedTestFileMd5)); }
@Test public void testDigestFileAs32ByteHexFile() throws Exception { RpcPerforceFile testFile = new RpcPerforceFile(testFileName, RpcPerforceFileType.FST_BINARY, ClientLineEnding.FST_L_LF); String actual = md5Digester.digestFileAs32ByteHex(testFile); assertThat(actual, is(isWindows ? expectedTestFileMd5Win : expectedTestFileMd5)); }
@Test public void testDigestFileAs32ByteHex_file_charset() throws Exception { RpcPerforceFile testFile = new RpcPerforceFile(testFileName, RpcPerforceFileType.FST_BINARY, ClientLineEnding.FST_L_LF); String actual = md5Digester.digestFileAs32ByteHex(testFile, Charset.forName("UTF-8")); assertThat(actual, is(isWindows ? expectedTestFileMd5Win : expectedTestFileMd5)); }
@Test public void testDigestFileAs32ByteHexFile_withException() throws Exception { File dirAsFile = new File(System.getProperty("java.io.tmpdir")); String actual = md5Digester.digestFileAs32ByteHex(dirAsFile); assertNull(actual); }