Java CRC32: not the same as CRC from C# -
i have compare files java crc32 code provided c# script. when calculate crc32 java.util.zip.crc32 result different ...
my guess polynom = 0x2033 of c# script not same used in zip.crc32. possible set polynom ? or ideas of java-class calculating crc32 can define own polynom?
update: problem not polymnom. same between c# , java
this code, maybe wrong in way read file?
package com.mine.digits.internal.contentupdater; import java.io.file; import java.io.fileinputstream; import java.io.ioexception; import java.io.inputstream; import java.util.zip.crc32; public class crc { public static string doconvert32(file file) { byte[] bytes = readbytesfromfile(file); // readfromfile(file).getbytes(); crc32 x = new crc32(); x.update(bytes); return (long.tohexstring(x.getvalue())).touppercase(); } /** read contents of given file. */ private static byte[] readbytesfromfile(file file) { try { inputstream = new fileinputstream(file); long length = file.length(); if (length > integer.max_value) { // file large } byte[] bytes = new byte[(int)length]; int offset = 0; int numread = 0; while (offset < bytes.length && (numread=is.read(bytes, offset, bytes.length-offset)) >= 0) { offset += numread; } // ensure bytes have been read in if (offset < bytes.length) { system.out.println("could not read file " + file.getname()); } // close input stream , return bytes is.close(); return bytes; } catch (ioexception e) { system.out.println("ioexception " + file.getname()); return null; } } } thanks lot, frank
the standard (ieee) crc32 polynomial 0x04c11db7 corresponds to:
x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1 this java.util.zip.crc32 uses. don't know c# script mention...
you can find code snippet useful:
Comments
Post a Comment