List of usage examples for java.util.zip CheckedInputStream CheckedInputStream
public CheckedInputStream(InputStream in, Checksum cksum)
From source file:org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils.java
public boolean checkFileCRCCode(File targetFile, File sourceFile) throws Exception { // Cyclic Redundancy Check(CRC) if (!targetFile.exists() || !sourceFile.exists()) { return true; }/*w ww . j ava 2 s . c o m*/ FileInputStream tagetFilestream = new FileInputStream(targetFile); CRC32 targertCrc32 = new CRC32(); for (CheckedInputStream checkedinputstream = new CheckedInputStream(tagetFilestream, targertCrc32); checkedinputstream.read() != -1;) { // } FileInputStream sourceFilestream = new FileInputStream(sourceFile); CRC32 sourceCrc32 = new CRC32(); for (CheckedInputStream checkedinputstream = new CheckedInputStream(sourceFilestream, sourceCrc32); checkedinputstream.read() != -1;) { // } tagetFilestream.close(); sourceFilestream.close(); return Long.toHexString(targertCrc32.getValue()).equals(Long.toHexString(sourceCrc32.getValue())); }
From source file:org.talend.utils.io.FilesUtils.java
public static long getChecksumAlder32(File file) throws IOException { BufferedInputStream bufferedInputStream = null; CheckedInputStream cis = null; try {/*from w ww . ja v a 2 s . co m*/ bufferedInputStream = new BufferedInputStream(new FileInputStream(file)); // Compute Adler-32 checksum cis = new CheckedInputStream(bufferedInputStream, new Adler32()); byte[] tempBuf = new byte[128]; while (cis.read(tempBuf) >= 0) { // do nothing } return cis.getChecksum().getValue(); } catch (IOException e) { throw e; } finally { if (bufferedInputStream != null) { bufferedInputStream.close(); } if (cis != null) { cis.close(); } } }
From source file:org.yccheok.jstock.analysis.Utils.java
public static long getChecksum(File file) { FileInputStream stream = null; CheckedInputStream cis = null; try {// ww w . j a va 2s. c o m // Compute Adler-32 checksum stream = new FileInputStream(file); cis = new CheckedInputStream(stream, new Adler32()); byte[] tempBuf = new byte[128]; while (cis.read(tempBuf) >= 0) { } long checksum = cis.getChecksum().getValue(); return checksum; } catch (IOException ex) { log.error(null, ex); } finally { org.yccheok.jstock.file.Utils.close(cis); org.yccheok.jstock.file.Utils.close(stream); } return 0; }
From source file:watne.seis720.project.AES_Utilities.java
/** * Compute the Adler-32 checksum of the specified file. Code based on * "e457. Calculating the Checksum of a File", "The Java * Developers Almanac 1.4", <a * href="http://www.exampledepot.com/egs/java.util.zip/ChecksumFile.html">http://www.exampledepot.com/egs/java.util.zip/ChecksumFile.html</a> * @param checkFile the file to be checked. * @return the Adler-32 checkusm of the specified file. * @throws IOException if an error occurs reading checkFile. *///ww w.j a v a 2 s .c o m public static long getFileChecksum(File checkFile) throws IOException { long checksum = -1; CheckedInputStream cis = new CheckedInputStream(new FileInputStream(checkFile), new Adler32()); byte[] tempBuf = new byte[128]; while (cis.read(tempBuf) >= 0) { } checksum = cis.getChecksum().getValue(); return checksum; }