isusechecksumfile=true;
}else{
System.out.println("can`t found checksum file "+checksumfile);
}
ChecksumIndexInput input = new ChecksumIndexInput(directory.openInput(segmentFileName));
generation = generationFromSegmentsFileName(segmentFileName);
lastGeneration = generation;
try {
int format = input.readInt();
// check that it is a format we can understand
if (format > FORMAT_MINIMUM) {
throw new IndexFormatTooOldException(input, format,
FORMAT_MINIMUM, FORMAT_MAXIMUM);
}
if (format < FORMAT_MAXIMUM) {
throw new IndexFormatTooNewException(input, format,
FORMAT_MINIMUM, FORMAT_MAXIMUM);
}
version = input.readLong(); // read version
counter = input.readInt(); // read counter
for (int i = input.readInt(); i > 0; i--) { // read segmentInfos
SegmentInfo si = new SegmentInfo(directory, format, input);
if (si.getVersion() == null) {
// It's a pre-3.1 segment, upgrade its version to either 3.0 or 2.x
Directory dir = directory;
if (si.getDocStoreOffset() != -1) {
if (si.getDocStoreIsCompoundFile()) {
dir = new CompoundFileReader(dir, IndexFileNames.segmentFileName(
si.getDocStoreSegment(),
IndexFileNames.COMPOUND_FILE_STORE_EXTENSION),IndexFileNames.segmentFileName(
si.getDocStoreSegment(),
IndexFileNames.COMPOUND_FILE_STORE_EXTENSION_POS), 1024);
}
} else if (si.getUseCompoundFile()) {
dir = new CompoundFileReader(dir, IndexFileNames.segmentFileName(
si.name, IndexFileNames.COMPOUND_FILE_EXTENSION),IndexFileNames.segmentFileName(
si.name, IndexFileNames.COMPOUND_FILE_EXTENSION_POS), 1024);
}
try {
String store = si.getDocStoreOffset() != -1 ? si.getDocStoreSegment() : si.name;
si.setVersion(FieldsReader.detectCodeVersion(dir, store));
} finally {
// If we opened the directory, close it
if (dir != directory) dir.close();
}
}
add(si);
}
if(format >= 0){ // in old format the version number may be at the end of the file
if (input.getFilePointer() >= input.length())
version = System.currentTimeMillis(); // old file format without version number
else
version = input.readLong(); // read version
}
if (format <= FORMAT_USER_DATA) {
if (format <= FORMAT_DIAGNOSTICS) {
userData = input.readStringStringMap();
} else if (0 != input.readByte()) {
userData = Collections.singletonMap("userData", input.readString());
} else {
userData = Collections.<String,String>emptyMap();
}
} else {
userData = Collections.<String,String>emptyMap();
}
if (format <= FORMAT_CHECKSUM) {
final long checksumNow = input.getChecksum();
long checksumThen = checksum;
if (!isusechecksumfile) {
checksumThen = input.readLong();
}
if (checksumNow != checksumThen)
throw new CorruptIndexException("checksum mismatch in segments file (resource: " + input + ")");
}
success = true;
}
finally {
input.close();
if (!success) {
// Clear any segment infos we had loaded so we
// have a clean slate on retry:
this.clear();
}