DataObjectMerger extends AbstractElementMerger { static String getChecksum(File file) { FileInputStream inputStream = null; try { inputStream = new FileInputStream(file); MessageDigest md = MessageDigest.getInstance("MD5"); FileChannel channel = inputStream.getChannel(); ByteBuffer buff = ByteBuffer.allocate(2048); while (channel.read(buff) != -1) { buff.flip(); md.update(buff); buff.clear(); } final byte[] digest = md.digest(); StringBuilder digestResult = new StringBuilder(); for (byte aDigest : digest) { digestResult.append(Integer.toString((aDigest & 0xff) + 0x100, 16).substring(1)); } return digestResult.toString(); } catch (NoSuchAlgorithmException | IOException e) { return ""; } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { } } } } DataObjectMerger(String fileLocation); @Override void mergeNodes(List<Node> fromParents, Element toParent, Document toDocument);  }
@Test public void testGetChecksum_NotWorking() { final String checksum = DataObjectMerger.getChecksum(new File("")); assertEquals("", checksum); }
@Test public void testGetChecksum() { File file = new File(DataObjectMergerTest.class.getResource("justSomeDummyFileForCreatingAChecksum").getFile()); final String checksum = DataObjectMerger.getChecksum(file); assertEquals("e40ee529b406f33efb8f53ee5e26bcbf", checksum); }