use of java.util.zip.CheckedInputStream in project ats-framework by Axway.
the class MimePackage method getPartChecksum.
/**
* Return the CRC checksum of a given part
*
* @param partIndex
* the index of the part
* @param isAttachment
* true if the part is an attachment
* @return the part checksum
* @throws PackageException
*/
@PublicAtsApi
public long getPartChecksum(int partIndex, boolean isAttachment) throws PackageException {
InputStream partDataStream = getPartData(partIndex, isAttachment);
if (partDataStream != null) {
try {
SeekInputStream seekDataStream = new SeekInputStream(partDataStream);
seekDataStream.seek(0);
// create a new crc and reset it
CRC32 crc = new CRC32();
// use checked stream to get the checksum
CheckedInputStream stream = new CheckedInputStream(seekDataStream, crc);
int bufLen = 4096;
byte[] buffer = new byte[bufLen];
int numBytesRead = bufLen;
while (numBytesRead == bufLen) {
numBytesRead = stream.read(buffer, 0, bufLen);
}
long checksum = stream.getChecksum().getValue();
stream.close();
return checksum;
} catch (IOException ioe) {
throw new PackageException(ioe);
}
} else {
throw new MimePartWithoutContentException("MIME part does not have any content");
}
}
use of java.util.zip.CheckedInputStream in project ddf by codice.
the class Adler32ChecksumProvider method calculateChecksum.
@Override
public String calculateChecksum(InputStream inputStream) throws IOException, NoSuchAlgorithmException {
if (inputStream == null) {
throw new IllegalArgumentException("InputStream cannot be null");
}
long checksumValue = 0L;
try (CheckedInputStream cis = new CheckedInputStream(inputStream, new Adler32())) {
byte[] buf = new byte[4096];
while (cis.read(buf, 0, buf.length - 1) != -1) {
}
checksumValue = cis.getChecksum().getValue();
}
return Long.toHexString(checksumValue);
}
use of java.util.zip.CheckedInputStream in project processdash by dtuma.
the class PackageLaunchProfile method calcChecksum.
private long calcChecksum(File f, Checksum cksum) throws IOException {
CheckedInputStream in = new CheckedInputStream(new BufferedInputStream(new FileInputStream(f)), cksum);
while (in.read() != -1) ;
in.close();
return cksum.getValue();
}
use of java.util.zip.CheckedInputStream in project cassandra by apache.
the class VerifyTest method simpleFullChecksum.
protected long simpleFullChecksum(String filename) throws IOException {
try (FileInputStream inputStream = new FileInputStream(filename)) {
CRC32 checksum = new CRC32();
CheckedInputStream cinStream = new CheckedInputStream(inputStream, checksum);
byte[] b = new byte[128];
while (cinStream.read(b) >= 0) {
}
return cinStream.getChecksum().getValue();
}
}
use of java.util.zip.CheckedInputStream in project zookeeper by apache.
the class CRCTest method getCheckSum.
/** return if checksum matches for a snapshot **/
private boolean getCheckSum(FileSnap snap, File snapFile) throws IOException {
DataTree dt = new DataTree();
Map<Long, Integer> sessions = new ConcurrentHashMap<Long, Integer>();
InputStream snapIS = new BufferedInputStream(new FileInputStream(snapFile));
CheckedInputStream crcIn = new CheckedInputStream(snapIS, new Adler32());
InputArchive ia = BinaryInputArchive.getArchive(crcIn);
try {
snap.deserialize(dt, sessions, ia);
} catch (IOException ie) {
// we failed on the most recent snapshot
// must be incomplete
// try reading the next one
// after corrupting
snapIS.close();
crcIn.close();
throw ie;
}
long checksum = crcIn.getChecksum().getValue();
long val = ia.readLong("val");
snapIS.close();
crcIn.close();
return (val != checksum);
}
Aggregations