Example usage for java.util.zip CheckedInputStream close

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

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes this input stream and releases any system resources associated with the stream.

Usage

From source file:com.yifanlu.PSXperiaTool.ZpakCreate.java

public static long getCRC32(File file) throws IOException {
    CheckedInputStream cis = null;
    long fileSize = 0;
    // Computer CRC32 checksum
    cis = new CheckedInputStream(new FileInputStream(file), new CRC32());

    fileSize = file.length();/*from   w w w.j  a  va  2s  .co  m*/

    byte[] buf = new byte[128];
    while (cis.read(buf) != -1)
        ;

    long checksum = cis.getChecksum().getValue();
    cis.close();
    Logger.verbose("CRC32 of %s is %d", file.getPath(), checksum);
    return checksum;
}

From source file:AbstractFileSystemHelper.java

public static long getChecksum(InputStream is) {
    CheckedInputStream cis = null;
    long checksum = 0;
    try {/*w  w  w  .  ja  v a 2 s  . c  o m*/
        cis = new CheckedInputStream(is, new Adler32());
        byte[] tempBuf = new byte[128];
        while (cis.read(tempBuf) >= 0) {
        }
        checksum = cis.getChecksum().getValue();
    } catch (IOException e) {
        checksum = 0;
    } finally {
        if (cis != null) {
            try {
                cis.close();
            } catch (IOException ioe) {
            }
        }
    }
    return checksum;
}

From source file:Main.java

public static String getCRC32(File file) {
    CRC32 crc32 = new CRC32();
    CheckedInputStream checkedinputstream = null;
    String crc = null;/*from  w w w. ja v  a  2 s.  c  om*/
    try {
        checkedinputstream = new CheckedInputStream(new FileInputStream(file), crc32);
        byte[] buf = new byte[1024];
        while (checkedinputstream.read(buf) >= 0) {
        }
        crc = Long.toHexString(crc32.getValue()).toUpperCase();
    } catch (Exception e) {
        Log.w(TAG, e);
        Log.e("WxException", e.getMessage(), e);
    } finally {
        if (checkedinputstream != null) {
            try {
                checkedinputstream.close();
            } catch (IOException e) {
            }
        }
    }
    return crc;
}

From source file:MultiFileChecksumHelper.java

public static long getChecksum(File[] files) {
    CheckedInputStream cis = null;
    FileInputStream is = null;// w  w w  .  ja va 2s . c om
    Checksum checksum = new Adler32();
    byte[] tempBuf = new byte[128];

    for (int i = 0; i < files.length && files[i] != null && files[i].exists() && files[i].isFile(); i++) {
        try {
            is = new FileInputStream(files[i]);
            cis = new CheckedInputStream(is, checksum);
            while (cis.read(tempBuf) >= 0) {
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            if (cis != null) {
                try {
                    cis.close();
                } catch (IOException ioe) {
                }
                cis = null;
            }
            if (is != null) {
                try {
                    is.close();
                } catch (IOException ioe) {
                }
                is = null;
            }
        }
    }
    return checksum.getValue();
}

From source file:com.blockwithme.longdb.tools.Utils.java

/** Get checksum CRC32 for the file content.
 * //  w  w w.j a  v  a2s.  c o m
 * @param theFile
 *        the file
 * @param isCommpressed
 *        true if commpressed
 * @return the checksum (CRC32) of the file.
 * @throws Exception */
@SuppressWarnings("resource")
public static long getCRC32(final File theFile, final boolean isCommpressed) throws Exception {
    CheckedInputStream cis = null;
    try {
        final CRC32 checksum = new CRC32();
        // TODO: Would a buffered input stream make this faster?
        cis = new CheckedInputStream((isCommpressed ? new GZIPInputStream(new FileInputStream(theFile))
                : new FileInputStream(theFile)), checksum);
        final byte[] tempBuf = new byte[ONE_K];
        while (cis.read(tempBuf) >= 0)
            ; // just read the full stream. // $codepro.audit.disable
        return checksum.getValue();
    } finally {
        if (cis != null)
            cis.close();
    }
}

From source file:com.adito.core.CoreUtil.java

/**
 * @param f/* w ww  . ja  v  a 2 s.c o m*/
 * @return long
 * @throws IOException
 */
public static long generateChecksum(File f) throws IOException {
    Adler32 alder = new Adler32();
    FileInputStream fin = new FileInputStream(f);
    CheckedInputStream in = new CheckedInputStream(fin, alder);
    byte[] buf = new byte[32768];
    Util.readFullyIntoBuffer(in, buf);
    alder = (Adler32) in.getChecksum();
    try {
        in.close();
    } catch (IOException ex) {
    }
    try {
        fin.close();
    } catch (IOException ex1) {
    }
    return alder.getValue();
}

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

private Long getCRC(URL zipUrl) {
    Long result = -1l;//w ww .  jav  a  2s.  c om
    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.talend.utils.io.FilesUtils.java

public static long getChecksumAlder32(File file) throws IOException {
    BufferedInputStream bufferedInputStream = null;
    CheckedInputStream cis = null;
    try {/*from w  ww.  j a v  a2s.  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();
        }
    }
}