HashCalculator { public HashCalculationResult calculateSuperHash(File file) throws IOException { long fileSize = file.length(); if (fileSize <= FILE_MIN_SIZE_THRESHOLD) { logger.debug("Ignored file " + file.getName() + " (" + FileUtils.byteCountToDisplaySize(fileSize) + "): minimum file size is 512B"); return null; } if (fileSize >= FILE_MAX_SIZE_THRESHOLD){ logger.debug("Ignore file {}, ({}): maximum file size is 2GB", file.getName(), FileUtils.byteCountToDisplaySize(fileSize)); return null; } HashCalculationResult result = null; try { result = calculateSuperHash(FileUtils.readFileToByteArray(file)); } catch (OutOfMemoryError e) { logger.debug(MessageFormat.format("Failed calculating SHA-1 for file {0}: size too big {1}", file.getAbsolutePath(), FileUtils.byteCountToDisplaySize(fileSize))); } return result; }  HashCalculationResult calculateSuperHash(File file); HashCalculationResult calculateSuperHash(byte[] bytes); String calculateSHA1(File resourceFile); String calculateHash(File resourceFile, HashAlgorithm algorithm); String calculateByteArraySHA1(byte[] byteArray); String calculateByteArrayHash(byte[] byteArray, HashAlgorithm algorithm); Map<ChecksumType, String> calculateJavaScriptHashes(File file); Map<ChecksumType, String> calculateJavaScriptHashes(byte[] byteArray); String calculateSha1ByGAVCoordinatesAndType(String groupId, String artifactId, String version,
                                                                DependencyType dependencyType); String calculateSha1ByNameVersionArchitectureAndType(String name, String version, String architecture,
                                                                DependencyType dependencyType); String calculateSha1ByNameVersionAndType(String name, String version, DependencyType dependencyType);  }
@Test public void testSuperHash() throws IOException { HashCalculator hashCalculator = new HashCalculator(); File originFile = new File(URLDecoder.decode(getClass().getResource("/superHash/origin.txt").getFile(), "utf-8")); HashCalculationResult originFileHashResult = hashCalculator.calculateSuperHash(originFile); File whitespaceChangesFile = new File(URLDecoder.decode(getClass().getResource("/superHash/whitespace-changes.txt").getFile(), "utf-8")); HashCalculationResult whitespaceFileHashResult = hashCalculator.calculateSuperHash(whitespaceChangesFile); File msbTestFile = new File(URLDecoder.decode(getClass().getResource("/superHash/msb-test.txt").getFile(), "utf-8")); HashCalculationResult msbTestFileHashResult = hashCalculator.calculateSuperHash(msbTestFile); File lsbTestFile = new File(URLDecoder.decode(getClass().getResource("/superHash/lsb-test.txt").getFile(), "utf-8")); HashCalculationResult lsbTestFileHashResult = hashCalculator.calculateSuperHash(lsbTestFile); Assert.assertEquals("Files must match despite whitespace changes", originFileHashResult.getFullHash(), whitespaceFileHashResult.getFullHash()); Assert.assertEquals("File msb hashes must match", originFileHashResult.getMostSigBitsHash(), msbTestFileHashResult.getMostSigBitsHash()); Assert.assertEquals("File lsb hashes must match", originFileHashResult.getLeastSigBitsHash(), lsbTestFileHashResult.getLeastSigBitsHash()); File smallFile = new File(URLDecoder.decode(getClass().getResource("/superHash/small-file.txt").getFile(), "utf-8")); HashCalculationResult smallFileHashResult = hashCalculator.calculateSuperHash(smallFile); assertNull(smallFileHashResult); }