Мне нужно сравнить файлы с Java с кодом CRC32, предоставленным скриптом C #. Когда я вычисляю CRC32 с помощью java.util.zip.CRC32, результат совершенно другой ...
Я предполагаю, что polynom = 0x2033 скрипта C # отличается от используемого в zip.CRC32. Можно ли установить полином? Или какие-нибудь идеи java-класса для вычисления CRC32, где вы можете определить свой собственный полином?
ОБНОВЛЕНИЕ: проблема не в полимном. То же самое между C # и Java
Это мой код, может, что-то не так в том, как я читаю файл?
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 the contents of the given file. */
private static byte[] readBytesFromFile(File file)
{
try
{
InputStream is = new FileInputStream(file);
long length = file.length();
if (length > Integer.MAX_VALUE) {
// File is too 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 all the bytes have been read in
if (offset < bytes.length) {
System.out.println("Could not completely read file " + file.getName());
}
// Close the input stream and return bytes
is.close();
return bytes;
}
catch (IOException e)
{
System.out.println("IOException " + file.getName());
return null;
}
}
}
Большое спасибо,
Frank