filesLock.acquireWriteLock();
try {
for (long fileId : files.keySet()) {
OFileClassic fileClassic = files.get(fileId);
boolean fileIsCorrect;
try {
if (commandOutputListener != null)
commandOutputListener.onMessage("Flashing file " + fileClassic.getName() + "... ");
flush(fileId);
if (commandOutputListener != null)
commandOutputListener.onMessage("Start verification of content of " + fileClassic.getName() + "file ...");
long time = System.currentTimeMillis();
long filledUpTo = fileClassic.getFilledUpTo();
fileIsCorrect = true;
for (long pos = 0; pos < filledUpTo; pos += pageSize) {
boolean checkSumIncorrect = false;
boolean magicNumberIncorrect = false;
byte[] data = new byte[pageSize];
fileClassic.read(pos, data, data.length);
long magicNumber = OLongSerializer.INSTANCE.deserializeNative(data, 0);
if (magicNumber != MAGIC_NUMBER) {
magicNumberIncorrect = true;
if (commandOutputListener != null)
commandOutputListener.onMessage("Error: Magic number for page " + (pos / pageSize) + " in file "
+ fileClassic.getName() + " does not much !!!");
fileIsCorrect = false;
}
final int storedCRC32 = OIntegerSerializer.INSTANCE.deserializeNative(data, OLongSerializer.LONG_SIZE);
final int calculatedCRC32 = calculatePageCrc(data);
if (storedCRC32 != calculatedCRC32) {
checkSumIncorrect = true;
if (commandOutputListener != null)
commandOutputListener.onMessage("Error: Checksum for page " + (pos / pageSize) + " in file "
+ fileClassic.getName() + " is incorrect !!!");
fileIsCorrect = false;
}
if (magicNumberIncorrect || checkSumIncorrect)
errors.add(new OPageDataVerificationError(magicNumberIncorrect, checkSumIncorrect, pos / pageSize, fileClassic
.getName()));
if (commandOutputListener != null && System.currentTimeMillis() - time > notificationTimeOut) {
time = notificationTimeOut;
commandOutputListener.onMessage((pos / pageSize) + " pages were processed ...");
}
}
} catch (IOException ioe) {
if (commandOutputListener != null)
commandOutputListener.onMessage("Error: Error during processing of file " + fileClassic.getName() + ". "
+ ioe.getMessage());
fileIsCorrect = false;
}
if (!fileIsCorrect) {
if (commandOutputListener != null)
commandOutputListener.onMessage("Verification of file " + fileClassic.getName() + " is finished with errors.");
} else {
if (commandOutputListener != null)
commandOutputListener.onMessage("Verification of file " + fileClassic.getName() + " is successfully finished.");
}
}
return errors.toArray(new OPageDataVerificationError[errors.size()]);
} finally {