Example usage for java.util.zip CheckedInputStream read

List of usage examples for java.util.zip CheckedInputStream read

Introduction

In this page you can find the example usage for java.util.zip CheckedInputStream read.

Prototype

public int read(byte b[]) throws IOException 

Source Link

Document

Reads up to b.length bytes of data from this input stream into an array of bytes.

Usage

From source file:com.panet.imeta.core.row.ValueDataUtil.java

public static Long ChecksumAdler32(ValueMetaInterface metaA, Object dataA) {
    long checksum = 0;
    FileObject file = null;/*from  w  w  w. j av  a2s.  co  m*/
    try {
        file = KettleVFS.getFileObject(dataA.toString());
        CheckedInputStream cis = null;

        // Computer Adler-32 checksum
        cis = new CheckedInputStream((FileInputStream) ((LocalFile) file).getInputStream(), new Adler32());

        byte[] buf = new byte[128];
        while (cis.read(buf) >= 0) {
        }
        checksum = cis.getChecksum().getValue();

    } catch (Exception e) {
        //throw new Exception(e);
    } finally {
        if (file != null)
            try {
                file.close();
            } catch (Exception e) {
            }
        ;
    }
    return checksum;
}

From source file:com.alcatel_lucent.nz.wnmsextract.reader.FileUtilities.java

public long checksum(File input) {
    long checksum = -1;
    try {/*from  w  ww. j ava  2  s. c o  m*/
        FileInputStream fis = null;
        CheckedInputStream cis = null;
        Adler32 adler = null;
        fis = new FileInputStream(input);
        adler = new Adler32();
        cis = new CheckedInputStream(fis, adler);

        byte[] buffer = new byte[1024];
        while (cis.read(buffer) >= 0) {
            checksum = cis.getChecksum().getValue();
        }

    } catch (IOException e) {
        jlog.fatal("IO Exception on " + input.getAbsolutePath() + e);
    }

    return checksum;

}

From source file:com.neusoft.clw.infomanage.ridingplan.action.RidingPlanAction.java

private String doChecksum(String fileName) {
    long checksum = 0;
    try {/*from w  ww  . j a va  2s.com*/
        CheckedInputStream cis = null;
        try {
            // Computer CRC32 checksum
            cis = new CheckedInputStream(new FileInputStream(fileName), new CRC32());
        } catch (FileNotFoundException e) {
            LOG.error("File not found.");
        }

        byte[] buf = new byte[128];
        while (cis.read(buf) >= 0) {
        }
        checksum = cis.getChecksum().getValue();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return String.valueOf(checksum);
}

From source file:org.apache.cassandra.db.VerifyTest.java

protected long simpleFullChecksum(String filename) throws IOException {
    FileInputStream inputStream = new FileInputStream(filename);
    Adler32 adlerChecksum = new Adler32();
    CheckedInputStream cinStream = new CheckedInputStream(inputStream, adlerChecksum);
    byte[] b = new byte[128];
    while (cinStream.read(b) >= 0) {
    }/*ww  w.ja  va 2 s.  c  o m*/
    return cinStream.getChecksum().getValue();
}

From source file:org.broadleafcommerce.common.util.StringUtil.java

public static long getChecksum(String test) {
    try {// w w w . j  av a 2  s  .  c o m
        byte buffer[] = test.getBytes();
        ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
        CheckedInputStream cis = new CheckedInputStream(bais, new Adler32());
        byte readBuffer[] = new byte[buffer.length];
        cis.read(readBuffer);
        return cis.getChecksum().getValue();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.efaps.db.databases.OracleDatabase.java

/**
 * @param _name name//from   w  ww. ja  v  a2 s .c  o  m
 * @param _maxLength maximum length
 * @return new name
 * @throws EFapsException on error
 */
protected String getName4DB(final String _name, final int _maxLength) throws EFapsException {
    String ret = _name;
    if (_name.length() > 30) {
        try {
            final byte[] buffer = _name.getBytes("UTF8");
            final ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
            final CheckedInputStream cis = new CheckedInputStream(bais, new Adler32());
            final byte[] readBuffer = new byte[5];
            long value = 0;
            while (cis.read(readBuffer) >= 0) {
                value = cis.getChecksum().getValue();
            }
            final String valueSt = String.valueOf(value);
            ret = ret.substring(0, 30);
            final int sizeSuf = ret.length() - valueSt.length();
            ret = ret.substring(0, sizeSuf) + value;
        } catch (final UnsupportedEncodingException e) {
            throw new EFapsException("UnsupportedEncodingException", e);
        } catch (final IOException e) {
            throw new EFapsException("IOException", e);
        }
    }
    return ret;
}

From source file:org.kuali.rice.krad.datadictionary.URLMonitor.java

private Long getCRC(URL zipUrl) {
    Long result = -1l;/*from   ww  w.  jav a  2s.  co  m*/
    try {
        CRC32 crc = new CRC32();
        CheckedInputStream cis = new CheckedInputStream(zipUrl.openStream(), crc);

        byte[] buffer = new byte[1024];
        int length;

        //read the entry from zip file and extract it to disk
        while ((length = cis.read(buffer)) > 0)
            ;

        cis.close();

        result = crc.getValue();
    } catch (IOException e) {
        LOG.warn("Unable to calculate CRC, resource doesn't exist?", e);
    }
    return result;
}

From source file:org.mule.transports.vfs.VFSReceiver.java

protected boolean hasChanged(FileObject fileObject) {
    boolean changed = false;
    String key = fileObject.getName().getPath();
    long checksum = 0;
    if (checksumMap.containsKey(key)) {
        checksum = ((Long) checksumMap.get(key)).longValue();
    }/* w w  w  .  j  a v  a2s.  c  om*/
    long newChecksum = 0;
    CheckedInputStream checkedInputStream = null;
    try {
        InputStream inputStream = fileObject.getContent().getInputStream();
        checkedInputStream = new CheckedInputStream(inputStream, new Adler32());
        int bufferSize = 1;
        if (inputStream.available() > 0) {
            bufferSize = inputStream.available();
        }
        byte[] buffer = new byte[bufferSize];
        while (checkedInputStream.read(buffer) > -1) {
            ;
        }
        newChecksum = checkedInputStream.getChecksum().getValue();
        if (newChecksum != checksum) {
            if (logger.isDebugEnabled()) {
                logger.debug("calculated a new checksum of " + newChecksum);
            }
            checksumMap.put(key, new Long(newChecksum));
            changed = true;
        }
    } catch (IOException e) {
        connector.handleException(e);
    }
    return changed;
}

From source file:org.openossad.util.core.row.ValueDataUtil.java

public static Long ChecksumCRC32(ValueMetaInterface metaA, Object dataA) {
    long checksum = 0;
    FileObject file = null;/* ww  w  . j a  v a  2s .c  o  m*/
    try {
        file = OpenDESIGNERVFS.getFileObject(dataA.toString());
        CheckedInputStream cis = null;

        // Computer CRC32 checksum
        cis = new CheckedInputStream((FileInputStream) ((LocalFile) file).getInputStream(), new CRC32());
        byte[] buf = new byte[128];
        while (cis.read(buf) >= 0) {
        }

        checksum = cis.getChecksum().getValue();

    } catch (Exception e) {
    } finally {
        if (file != null)
            try {
                file.close();
            } catch (Exception e) {
            }
        ;
    }
    return checksum;
}

From source file:org.openossad.util.core.row.ValueDataUtil.java

public static Long ChecksumAdler32(ValueMetaInterface metaA, Object dataA) {
    long checksum = 0;
    FileObject file = null;//from  ww  w  .j  ava  2  s . c  om
    try {
        file = OpenDESIGNERVFS.getFileObject(dataA.toString());
        CheckedInputStream cis = null;

        // Computer Adler-32 checksum
        cis = new CheckedInputStream((FileInputStream) ((LocalFile) file).getInputStream(), new Adler32());

        byte[] buf = new byte[128];
        while (cis.read(buf) >= 0) {
        }
        checksum = cis.getChecksum().getValue();

    } catch (Exception e) {
        //throw new Exception(e);
    } finally {
        if (file != null)
            try {
                file.close();
            } catch (Exception e) {
            }
        ;
    }
    return checksum;
}