/** * Computes the checksum of a file using the CRC32 checksum routine. * The value of the checksum is returned. * * @param file the file to checksum, must not be {@code null} * @return the checksum value * @throws NullPointerException if the file or checksum is {@code null} * @throws IllegalArgumentException if the file is a directory * @throws IOException if an IO error occurs reading the file * @since 1.3 */ public static long checksumCRC32(final File file) throws IOException { final CRC32 crc = new CRC32(); checksum(file, crc); return crc.getValue(); }
/** * Computes the checksum of a file using the CRC32 checksum routine. * The value of the checksum is returned. * * @param file the file to checksum, must not be <code>null</code> * @return the checksum value * @throws NullPointerException if the file or checksum is <code>null</code> * @throws IllegalArgumentException if the file is a directory * @throws IOException if an IO error occurs reading the file * @since Commons IO 1.3 */ public static long checksumCRC32(File file) throws IOException { CRC32 crc = new CRC32(); checksum(file, crc); return crc.getValue(); }
@Test public void testChecksumOnDirectory() throws Exception { try { FileUtils.checksum(new File("."), new CRC32()); fail(); } catch (final IllegalArgumentException ex) { // expected } }
@Test public void testChecksumOnNullFile() throws Exception { try { FileUtils.checksum(null, new CRC32()); fail(); } catch (final NullPointerException ex) { // expected } }
@Test public void testChecksumDouble() throws Exception { // create a test file final String text1 = "Imagination is more important than knowledge - Einstein"; final File file1 = new File(getTestDirectory(), "checksum-test.txt"); FileUtils.writeStringToFile(file1, text1, "US-ASCII"); // create a second test file final String text2 = "To be or not to be - Shakespeare"; final File file2 = new File(getTestDirectory(), "checksum-test2.txt"); FileUtils.writeStringToFile(file2, text2, "US-ASCII"); // compute the expected checksum final Checksum expectedChecksum = new CRC32(); expectedChecksum.update(text1.getBytes("US-ASCII"), 0, text1.length()); expectedChecksum.update(text2.getBytes("US-ASCII"), 0, text2.length()); final long expectedValue = expectedChecksum.getValue(); // compute the checksum of the file final Checksum testChecksum = new CRC32(); FileUtils.checksum(file1, testChecksum); FileUtils.checksum(file2, testChecksum); final long resultValue = testChecksum.getValue(); assertEquals(expectedValue, resultValue); }
@Test public void testChecksum() throws Exception { // create a test file final String text = "Imagination is more important than knowledge - Einstein"; final File file = new File(getTestDirectory(), "checksum-test.txt"); FileUtils.writeStringToFile(file, text, "US-ASCII"); // compute the expected checksum final Checksum expectedChecksum = new CRC32(); expectedChecksum.update(text.getBytes("US-ASCII"), 0, text.length()); final long expectedValue = expectedChecksum.getValue(); // compute the checksum of the file final Checksum testChecksum = new CRC32(); final Checksum resultChecksum = FileUtils.checksum(file, testChecksum); final long resultValue = resultChecksum.getValue(); assertSame(testChecksum, resultChecksum); assertEquals(expectedValue, resultValue); }
@Test public void testChecksumOnNullChecksum() throws Exception { // create a test file final String text = "Imagination is more important than knowledge - Einstein"; final File file = new File(getTestDirectory(), "checksum-test.txt"); FileUtils.writeStringToFile(file, text, "US-ASCII"); try { FileUtils.checksum(file, null); fail(); } catch (final NullPointerException ex) { // expected } }
/** * Computes the checksum of a file using the CRC32 checksum routine. * The value of the checksum is returned. * * @param file the file to checksum, must not be {@code null} * @return the checksum value * @throws NullPointerException if the file or checksum is {@code null} * @throws IllegalArgumentException if the file is a directory * @throws IOException if an IO error occurs reading the file * @since 1.3 */ public static long checksumCRC32(File file) throws IOException { CRC32 crc = new CRC32(); checksum(file, crc); return crc.getValue(); }
/** * Computes the checksum of a file using the CRC32 checksum routine. * The value of the checksum is returned. * * @param file the file to checksum, must not be <code>null</code> * @return the checksum value * @throws NullPointerException if the file or checksum is <code>null</code> * @throws IllegalArgumentException if the file is a directory * @throws IOException if an IO error occurs reading the file * @since 1.3 */ public static long checksumCRC32(File file) throws IOException { CRC32 crc = new CRC32(); checksum(file, crc); return crc.getValue(); }
/** * Computes the checksum of a file using the CRC32 checksum routine. * The value of the checksum is returned. * * @param file the file to checksum, must not be <code>null</code> * @return the checksum value * @throws NullPointerException if the file or checksum is <code>null</code> * @throws IllegalArgumentException if the file is a directory * @throws IOException if an IO error occurs reading the file * @since Commons IO 1.3 */ public static long checksumCRC32(File file) throws IOException { CRC32 crc = new CRC32(); checksum(file, crc); return crc.getValue(); }
/** * Computes the checksum of a file using the CRC32 checksum routine. * The value of the checksum is returned. * * @param file the file to checksum, must not be {@code null} * @return the checksum value * @throws NullPointerException if the file or checksum is {@code null} * @throws IllegalArgumentException if the file is a directory * @throws IOException if an IO error occurs reading the file * @since 1.3 */ public static long checksumCRC32(final File file) throws IOException { final CRC32 crc = new CRC32(); checksum(file, crc); return crc.getValue(); }
/** * Computes the checksum of a file using the CRC32 checksum routine. * The value of the checksum is returned. * * @param file the file to checksum, must not be <code>null</code> * @return the checksum value * @throws NullPointerException if the file or checksum is <code>null</code> * @throws IllegalArgumentException if the file is a directory * @throws IOException if an IO error occurs reading the file * @since Commons IO 1.3 */ public static long checksumCRC32(File file) throws IOException { CRC32 crc = new CRC32(); checksum(file, crc); return crc.getValue(); }
/** * Computes the checksum of a file using the CRC32 checksum routine. * The value of the checksum is returned. * * @param file the file to checksum, must not be {@code null} * @return the checksum value * @throws NullPointerException if the file or checksum is {@code null} * @throws IllegalArgumentException if the file is a directory * @throws IOException if an IO error occurs reading the file * @since 1.3 */ public static long checksumCRC32(final File file) throws IOException { final CRC32 crc = new CRC32(); checksum(file, crc); return crc.getValue(); }
public static Checksum checksum(File file, Checksum checksum) { try { return FileUtils.checksum(file, checksum); } catch (IOException e) { throw new UncheckedIOException(e); } }
private void validateFiles(String[] files, long[] checksums){ //Validate files: try { for (int i = 0; i < files.length; i++) { File f = new File(files[i]); Checksum adler = new Adler32(); long checksum = f.exists() ? FileUtils.checksum(f, adler).getValue() : -1; if (!f.exists() || checksum != checksums[i]) { throw new IllegalStateException("Failed checksum: expected " + checksums[i] + ", got " + checksum + " for file: " + f); } } } catch (Exception e) { throw new RuntimeException(e); } }
log.info("Verifying download..."); Checksum adler = new Adler32(); FileUtils.checksum(cachedFile, adler); long localChecksum = adler.getValue(); log.info("Checksum local is " + localChecksum + ", expecting " + expectedChecksum);
log.info("Verifying download..."); Checksum adler = new Adler32(); FileUtils.checksum(tmpFile, adler); long localChecksum = adler.getValue(); log.info("Checksum local is " + localChecksum + ", expecting "+expectedChecksum(set));
sum = checksum.getValue(); } finally { install = sum != FileUtils.checksum(f, (Checksum) new MD5Checksum()).getValue();