List of usage examples for java.util.zip CheckedInputStream read
public int read(byte b[]) throws IOException
b.length
bytes of data from this input stream into an array of bytes. From source file:org.pentaho.di.core.row.ValueDataUtil.java
public static Long ChecksumCRC32(ValueMetaInterface metaA, Object dataA) { long checksum = 0; FileObject file = null;/*from ww w. java 2s.co m*/ try { file = KettleVFS.getFileObject(dataA.toString()); CheckedInputStream cis = null; // Computer CRC32 checksum cis = new CheckedInputStream(((LocalFile) file).getInputStream(), new CRC32()); byte[] buf = new byte[128]; int readSize = 0; do { readSize = cis.read(buf); } while (readSize >= 0); checksum = cis.getChecksum().getValue(); } catch (Exception e) { // ignore - should likely log the exception } finally { if (file != null) { try { file.close(); file = null; } catch (Exception e) { // Ignore } } } return checksum; }
From source file:org.pentaho.di.core.row.ValueDataUtil.java
public static Long ChecksumAdler32(ValueMetaInterface metaA, Object dataA) { long checksum = 0; FileObject file = null;/*from w ww. j av a2 s . c o m*/ try { file = KettleVFS.getFileObject(dataA.toString()); CheckedInputStream cis = null; // Computer Adler-32 checksum cis = new CheckedInputStream(((LocalFile) file).getInputStream(), new Adler32()); byte[] buf = new byte[128]; int readSize = 0; do { readSize = cis.read(buf); } while (readSize >= 0); checksum = cis.getChecksum().getValue(); } catch (Exception e) { // throw new Exception(e); } finally { if (file != null) { try { file.close(); file = null; } catch (Exception e) { // Ignore } } } return checksum; }
From source file:org.talend.commons.runtime.utils.io.IOUtils.java
public static long computeCRC(InputStream in) { long unitCRC = 0; BufferedInputStream bufferedInputStream = null; try {//from w w w . java 2 s.c o m bufferedInputStream = new BufferedInputStream(in); // Compute Adler-32 checksum CheckedInputStream cis = new CheckedInputStream(bufferedInputStream, new Adler32()); byte[] tempBuf = new byte[128]; while (cis.read(tempBuf) >= 0) { // do nothing } unitCRC = cis.getChecksum().getValue(); } catch (IOException e) { return -1; } finally { try { bufferedInputStream.close(); } catch (Exception e) { // ignore me even if i'm null } } return unitCRC; }
From source file:org.talend.utils.io.FilesUtils.java
public static long getChecksumAlder32(File file) throws IOException { BufferedInputStream bufferedInputStream = null; CheckedInputStream cis = null; try {// w w w. ja va 2s . c o 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 {//from w w w.j a v a 2 s.co 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. *//*from w ww . java 2 s .co 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; }