Search in sources :

Example 1 with CheckedInputStream

use of java.util.zip.CheckedInputStream in project zookeeper by apache.

the class SnapshotFormatter method run.

public void run(String snapshotFileName) throws IOException {
    InputStream is = new CheckedInputStream(new BufferedInputStream(new FileInputStream(snapshotFileName)), new Adler32());
    InputArchive ia = BinaryInputArchive.getArchive(is);
    FileSnap fileSnap = new FileSnap(null);
    DataTree dataTree = new DataTree();
    Map<Long, Integer> sessions = new HashMap<Long, Integer>();
    fileSnap.deserialize(dataTree, sessions, ia);
    printDetails(dataTree, sessions);
}
Also used : FileSnap(org.apache.zookeeper.server.persistence.FileSnap) BufferedInputStream(java.io.BufferedInputStream) HashMap(java.util.HashMap) CheckedInputStream(java.util.zip.CheckedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) InputArchive(org.apache.jute.InputArchive) BinaryInputArchive(org.apache.jute.BinaryInputArchive) CheckedInputStream(java.util.zip.CheckedInputStream) FileInputStream(java.io.FileInputStream) Adler32(java.util.zip.Adler32)

Example 2 with CheckedInputStream

use of java.util.zip.CheckedInputStream in project android_frameworks_base by ParanoidAndroid.

the class FileUtils method checksumCrc32.

/**
     * 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 null
     * @return the checksum value or an exception is thrown.
     */
public static long checksumCrc32(File file) throws FileNotFoundException, IOException {
    CRC32 checkSummer = new CRC32();
    CheckedInputStream cis = null;
    try {
        cis = new CheckedInputStream(new FileInputStream(file), checkSummer);
        byte[] buf = new byte[128];
        while (cis.read(buf) >= 0) {
        // Just read for checksum to get calculated.
        }
        return checkSummer.getValue();
    } finally {
        if (cis != null) {
            try {
                cis.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : CRC32(java.util.zip.CRC32) IOException(java.io.IOException) CheckedInputStream(java.util.zip.CheckedInputStream) FileInputStream(java.io.FileInputStream)

Example 3 with CheckedInputStream

use of java.util.zip.CheckedInputStream in project XobotOS by xamarin.

the class FileUtils method checksumCrc32.

/**
     * 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 null
     * @return the checksum value or an exception is thrown.
     */
public static long checksumCrc32(File file) throws FileNotFoundException, IOException {
    CRC32 checkSummer = new CRC32();
    CheckedInputStream cis = null;
    try {
        cis = new CheckedInputStream(new FileInputStream(file), checkSummer);
        byte[] buf = new byte[128];
        while (cis.read(buf) >= 0) {
        // Just read for checksum to get calculated.
        }
        return checkSummer.getValue();
    } finally {
        if (cis != null) {
            try {
                cis.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : CRC32(java.util.zip.CRC32) IOException(java.io.IOException) CheckedInputStream(java.util.zip.CheckedInputStream) FileInputStream(java.io.FileInputStream)

Example 4 with CheckedInputStream

use of java.util.zip.CheckedInputStream in project android_frameworks_base by DirtyUnicorns.

the class FileUtils method checksumCrc32.

/**
     * 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 null
     * @return the checksum value or an exception is thrown.
     */
public static long checksumCrc32(File file) throws FileNotFoundException, IOException {
    CRC32 checkSummer = new CRC32();
    CheckedInputStream cis = null;
    try {
        cis = new CheckedInputStream(new FileInputStream(file), checkSummer);
        byte[] buf = new byte[128];
        while (cis.read(buf) >= 0) {
        // Just read for checksum to get calculated.
        }
        return checkSummer.getValue();
    } finally {
        if (cis != null) {
            try {
                cis.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : CRC32(java.util.zip.CRC32) IOException(java.io.IOException) CheckedInputStream(java.util.zip.CheckedInputStream) FileInputStream(java.io.FileInputStream)

Example 5 with CheckedInputStream

use of java.util.zip.CheckedInputStream in project lwjgl by LWJGL.

the class AppletLoader method isZipValid.

/**
	 * This method will check if a zip file is valid by running through it
	 * and checking for any corruption and CRC failures
	 * 
	 * @param file - zip file to test
	 * @return boolean - runs false if the file is corrupt
	 */
protected boolean isZipValid(File file) {
    try {
        ZipFile zipFile = new ZipFile(file);
        try {
            Enumeration e = zipFile.entries();
            byte[] buffer = new byte[4096];
            while (e.hasMoreElements()) {
                ZipEntry zipEntry = (ZipEntry) e.nextElement();
                CRC32 crc = new CRC32();
                BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(zipEntry));
                CheckedInputStream cis = new CheckedInputStream(bis, crc);
                while (cis.read(buffer, 0, buffer.length) != -1) {
                // scroll through zip entry
                }
                if (crc.getValue() != zipEntry.getCrc()) {
                    // CRC match failed, corrupt zip
                    return false;
                }
            }
            // valid zip file
            return true;
        } finally {
            zipFile.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
}
Also used : Enumeration(java.util.Enumeration) ZipFile(java.util.zip.ZipFile) CRC32(java.util.zip.CRC32) BufferedInputStream(java.io.BufferedInputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) CheckedInputStream(java.util.zip.CheckedInputStream)

Aggregations

CheckedInputStream (java.util.zip.CheckedInputStream)18 FileInputStream (java.io.FileInputStream)14 IOException (java.io.IOException)13 CRC32 (java.util.zip.CRC32)11 BufferedInputStream (java.io.BufferedInputStream)8 InputStream (java.io.InputStream)6 Adler32 (java.util.zip.Adler32)6 File (java.io.File)3 BinaryInputArchive (org.apache.jute.BinaryInputArchive)3 InputArchive (org.apache.jute.InputArchive)3 MimePartWithoutContentException (com.axway.ats.action.objects.model.MimePartWithoutContentException)1 NoSuchMimePackageException (com.axway.ats.action.objects.model.NoSuchMimePackageException)1 PackageException (com.axway.ats.action.objects.model.PackageException)1 PublicAtsApi (com.axway.ats.common.PublicAtsApi)1 SeekInputStream (com.axway.ats.core.io.SeekInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1