private void addDirectoryToZipEntryList( File directory, String currentPath, ImmutableMap.Builder<File, ZipEntry> zipEntriesBuilder) throws IOException { Preconditions.checkNotNull(currentPath); for (File inputFile : directory.listFiles()) { String childPath = currentPath + (currentPath.isEmpty() ? "" : "/") + inputFile.getName(); if (inputFile.isDirectory()) { addDirectoryToZipEntryList(inputFile, childPath, zipEntriesBuilder); } else { ZipEntry nextEntry = new ZipEntry(childPath); long fileLength = inputFile.length(); if (fileLength > maxDeflatedBytes || EXTENSIONS_NOT_TO_DEFLATE.contains(Files.getFileExtension(inputFile.getName()))) { nextEntry.setMethod(ZipEntry.STORED); nextEntry.setCompressedSize(inputFile.length()); nextEntry.setSize(inputFile.length()); HashCode crc = ByteStreams.hash(Files.newInputStreamSupplier(inputFile), Hashing.crc32()); nextEntry.setCrc(crc.padToLong()); } zipEntriesBuilder.put(inputFile, nextEntry); } } }
@BeforeClass(groups = {"integration", "live"}) @Override public void setUpResourcesOnThisThread(ITestContext testContext) throws Exception { super.setUpResourcesOnThisThread(testContext); oneHundredOneConstitutions = getTestDataSupplier(); oneHundredOneConstitutionsMD5 = ByteStreams.hash(oneHundredOneConstitutions, md5()).asBytes(); }
private boolean haveSameContents(File file, final JarFile jar, final JarEntry entry) throws IOException { HashFunction hashFun = Hashing.md5(); HashCode fileHash = Files.hash(file, hashFun); HashCode streamHash = ByteStreams.hash( new InputSupplier<InputStream>() { public InputStream getInput() throws IOException { return jar.getInputStream(entry); } }, hashFun); return fileHash.equals(streamHash); }
/** * Get the MD5 hash of the given stream. * * @param fis the input stream to use * @return a byte array of the MD5 hash * @throws java.security.NoSuchAlgorithmException if MD5 is not available * @throws IOException if an I/O error occurs */ private static byte[] md5(InputStream fis) throws NoSuchAlgorithmException, IOException { return ByteStreams.hash( ByteStreams.newInputStreamSupplier(ByteStreams.toByteArray(fis)), Hashing.md5()) .asBytes(); }