if (file.isFile()) {
stream = new FileInputStream(file);
final byte[] bytes = new byte[SIZE];
final int readSize = stream.read(bytes);
if (readSize < SIZE) {
throw new CorruptVolumeException("Volume file " + file + " too short: " + readSize);
}
/*
* Check out the fixed Volume file and learn the buffer
* size.
*/
if (!verifySignature(bytes)) {
throw new CorruptVolumeException("Invalid signature");
}
final int version = getVersion(bytes);
if (version < MIN_SUPPORTED_VERSION || version > MAX_SUPPORTED_VERSION) {
throw new CorruptVolumeException("Version " + version
+ " is not supported by Persistit version " + Persistit.version());
}
final int pageSize = getPageSize(bytes);
final long nextAvailablePage = getNextAvailablePage(bytes);
final long id = getId(bytes);
final long totalPages = file.length() / pageSize;
if (totalPages < nextAvailablePage) {
throw new CorruptVolumeException(String.format("Volume has been truncated: "
+ "minimum required/actual lengths=%,d/%,d bytes", nextAvailablePage * pageSize,
file.length()));
}
final long globalTimestamp = getGlobalTimestamp(bytes);
if (globalTimestamp > systemTimestamp) {
throw new CorruptVolumeException("Volume " + file + " has a global timestamp greater than "
+ "system timestamp: " + globalTimestamp + " > " + systemTimestamp);
}
specification.setVersion(version);
specification.setPageSize(pageSize);
specification.setId(id);
} else {
throw new CorruptVolumeException("Volume file " + file + " is a directory");
}
return true;
} else {
return false;
}