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);
}
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) {
}
}
}
}
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) {
}
}
}
}
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) {
}
}
}
}
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;
}
}
Aggregations