本文整理汇总了Java中java.util.zip.CRC32.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java CRC32.getValue方法的具体用法?Java CRC32.getValue怎么用?Java CRC32.getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.CRC32
的用法示例。
在下文中一共展示了CRC32.getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeCrcOfCentralDir
import java.util.zip.CRC32; //导入方法依赖的package包/类
static long computeCrcOfCentralDir(RandomAccessFile raf, CentralDirectory dir) throws IOException {
CRC32 crc = new CRC32();
long stillToRead = dir.size;
raf.seek(dir.offset);
byte[] buffer = new byte[16384];
int length = raf.read(buffer, 0, (int) Math.min(16384, stillToRead));
while (length != -1) {
crc.update(buffer, 0, length);
stillToRead -= (long) length;
if (stillToRead == 0) {
break;
}
length = raf.read(buffer, 0, (int) Math.min(16384, stillToRead));
}
return crc.getValue();
}
示例2: CRCCheck
import java.util.zip.CRC32; //导入方法依赖的package包/类
/**
* Check if the CRC of the snapshot file matches the digest.
* @param f The snapshot file object
* @return The table list as a string
* @throws IOException If CRC does not match
*/
public static String CRCCheck(File f) throws IOException {
final FileInputStream fis = new FileInputStream(f);
try {
final BufferedInputStream bis = new BufferedInputStream(fis);
ByteBuffer crcBuffer = ByteBuffer.allocate(4);
if (4 != bis.read(crcBuffer.array())) {
throw new EOFException("EOF while attempting to read CRC from snapshot digest");
}
final int crc = crcBuffer.getInt();
final InputStreamReader isr = new InputStreamReader(bis, "UTF-8");
CharArrayWriter caw = new CharArrayWriter();
while (true) {
int nextChar = isr.read();
if (nextChar == -1) {
throw new EOFException("EOF while reading snapshot digest");
}
if (nextChar == '\n') {
break;
}
caw.write(nextChar);
}
String tableList = caw.toString();
byte tableListBytes[] = tableList.getBytes("UTF-8");
CRC32 tableListCRC = new CRC32();
tableListCRC.update(tableListBytes);
tableListCRC.update("\n".getBytes("UTF-8"));
final int calculatedValue = (int)tableListCRC.getValue();
if (crc != calculatedValue) {
throw new IOException("CRC of snapshot digest did not match digest contents");
}
return tableList;
} finally {
try {
if (fis != null)
fis.close();
} catch (IOException e) {}
}
}
示例3: _getCRC
import java.util.zip.CRC32; //导入方法依赖的package包/类
private static long _getCRC(int type, byte[] data)
{
CRC32 crc = new CRC32();
// First add in the type bytes
crc.update((type >> 24) & 0x000000ff);
crc.update((type >> 16) & 0x000000ff);
crc.update((type >> 8) & 0x000000ff);
crc.update(type & 0x000000ff);
// Now, add in the data
if (data != null)
crc.update(data);
return crc.getValue();
}
示例4: calculateChecksum
import java.util.zip.CRC32; //导入方法依赖的package包/类
/** Calcule le checksum CRC32 d'un fichier
* @param path
* @param fileName
* @return le checksum du fichier
* @throws MigrationException
*/
private int calculateChecksum(String path, String fileName) throws MigrationException {
final CRC32 crc32 = new CRC32();
try {
String file=path+fileName;
InputStream inputStream = getClass().getResourceAsStream(file);
Reader reader = new InputStreamReader(inputStream, Charset.forName(flywayConfiguration.getEncoding()));
String str = FileCopyUtils.copyToString(reader);
inputStream.close();
BufferedReader bufferedReader = new BufferedReader(new StringReader(str));
String line;
while ((line = bufferedReader.readLine()) != null) {
crc32.update(line.getBytes("UTF-8"));
}
} catch (Exception e) {
throw new MigrationException("Unable to calculate checksum pour "+fileName, e);
}
return (int) crc32.getValue();
}
示例5: file
import java.util.zip.CRC32; //导入方法依赖的package包/类
public static long file(File f) throws IOException {
FileInputStream fi = new FileInputStream(f);
byte[] buff = new byte[65536];
CRC32 crc32 = new CRC32();
while (true) {
try {
int len = fi.read(buff);
if (len == -1) {
break;
}
crc32.update(buff, 0, len);
} catch (Exception e) {
e.printStackTrace();
} finally {
fi.close();
}
}
return crc32.getValue();
}
示例6: calculateCRC
import java.util.zip.CRC32; //导入方法依赖的package包/类
private static long calculateCRC(@NonNull final InputStream in) throws IOException {
final CRC32 crc = new CRC32();
int last = -1;
int curr;
while ((curr = in.read()) != -1) {
if (curr != '\n' && last == '\r') { //NOI18N
crc.update('\n'); //NOI18N
}
if (curr != '\r') { //NOI18N
crc.update(curr);
}
last = curr;
}
if (last == '\r') { //NOI18N
crc.update('\n'); //NOI18N
}
return crc.getValue();
}
示例7: getCrc
import java.util.zip.CRC32; //导入方法依赖的package包/类
private long getCrc(ZipFile file, ZipEntry entry) throws IOException {
long crc = -1;
if (entry != null) {
crc = entry.getCrc();
if (crc < 0) {
CRC32 checksum = new CRC32();
final InputStream in = file.getInputStream(entry);
try {
final byte[] buffer = new byte[1024];
int count;
while ((count = in.read(buffer)) >= 0) {
checksum.update(buffer, 0, count);
}
in.close();
crc = checksum.getValue();
}
finally {
IOUtils.closeQuietly(in);
}
}
}
return crc;
}
示例8: getApkFileChecksum
import java.util.zip.CRC32; //导入方法依赖的package包/类
private static long getApkFileChecksum(Context context) {
String apkPath = context.getPackageCodePath();
Long chksum = null;
try {
// Open the file and build a CRC32 checksum.
FileInputStream fis = new FileInputStream(new File(apkPath));
CRC32 chk = new CRC32();
CheckedInputStream cis = new CheckedInputStream(fis, chk);
byte[] buff = new byte[80];
while (cis.read(buff) >= 0) ;
chksum = chk.getValue();
} catch (Exception e) {
e.printStackTrace();
}
return chksum;
}
示例9: crc32
import java.util.zip.CRC32; //导入方法依赖的package包/类
public static int crc32(ByteBuffer buf) {
CRC32 checksum = new CRC32();
while (buf.hasRemaining()) {
checksum.update(buf.get());
}
return (int) checksum.getValue();
}
示例10: setSeed
import java.util.zip.CRC32; //导入方法依赖的package包/类
public void setSeed(long seeds) {
CRC32 crc32 = new CRC32();
ByteBuffer buffer = ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN);
buffer.putInt((int) seeds);
crc32.update(buffer.array());
this.seed = crc32.getValue();
}
示例11: deflate
import java.util.zip.CRC32; //导入方法依赖的package包/类
public static DeflateResult deflate(ByteBuffer input) {
byte[] inputBuf;
int inputOffset;
int inputLength = input.remaining();
if (input.hasArray()) {
inputBuf = input.array();
inputOffset = input.arrayOffset() + input.position();
input.position(input.limit());
} else {
inputBuf = new byte[inputLength];
inputOffset = 0;
input.get(inputBuf);
}
CRC32 crc32 = new CRC32();
crc32.update(inputBuf, inputOffset, inputLength);
long crc32Value = crc32.getValue();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Deflater deflater = new Deflater(9, true);
deflater.setInput(inputBuf, inputOffset, inputLength);
deflater.finish();
byte[] buf = new byte[65536];
while (!deflater.finished()) {
int chunkSize = deflater.deflate(buf);
out.write(buf, 0, chunkSize);
}
return new DeflateResult(inputLength, crc32Value, out.toByteArray());
}
示例12: testCRC32Checksum
import java.util.zip.CRC32; //导入方法依赖的package包/类
@Test
public void testCRC32Checksum() throws IOException {
CRC32 crc32 = new CRC32();
crc32.update(TEST_DARA.getBytes());
long expectedCRC32Checksum = crc32.getValue();
CRC32ChecksumCalculatingInputStream crc32InputStream = new CRC32ChecksumCalculatingInputStream(new ByteArrayInputStream(TEST_DARA.getBytes()));
while(crc32InputStream.read() != -1);
assertEquals(expectedCRC32Checksum, crc32InputStream.getCRC32Checksum());
}
示例13: getCrc32
import java.util.zip.CRC32; //导入方法依赖的package包/类
public static long getCrc32(final InputStream input) throws IOException {
CRC32 crc = new CRC32();
final byte[] buffer = new byte[BUFFER_SIZE];
int readLength;
while ((readLength = input.read(buffer)) != -1) {
crc.update(buffer, 0, readLength);
}
return crc.getValue();
}
示例14: testCrc32Checksum
import java.util.zip.CRC32; //导入方法依赖的package包/类
@Test
public void testCrc32Checksum() throws IOException {
CRC32 crc32 = new CRC32();
crc32.update(TEST_DATA.getBytes());
long expectedCRC32Checksum = crc32.getValue();
Crc32ChecksumCalculatingInputStream crc32InputStream =
new Crc32ChecksumCalculatingInputStream(new ByteArrayInputStream(TEST_DATA.getBytes()));
while (crc32InputStream.read() != -1) {
;
}
assertEquals(expectedCRC32Checksum, crc32InputStream.getCrc32Checksum());
}
示例15: getChecksum
import java.util.zip.CRC32; //导入方法依赖的package包/类
public long getChecksum(ModelDefinition.XMLBindingType bindingType)
{
final CRC32 crc = new CRC32();
// construct the crc directly from the model's xml stream
toXML(bindingType, new OutputStream() {
public void write(int b) throws IOException
{
crc.update(b);
}
});
return crc.getValue();
}