FileInputStream fileInputStream = new FileInputStream(file);
try {
// Timer timer = new Timer();
String expected = "-- VERSION_" + AbstractAdditionalTokensInfo.version; //X is the version
InputStreamReader reader = new InputStreamReader(fileInputStream);
FastBufferedReader bufferedReader = new FastBufferedReader(reader);
FastStringBuffer string = bufferedReader.readLine();
ObjectsPoolMap objectsPoolMap = new ObjectsPool.ObjectsPoolMap();
if (string != null && string.startsWith("-- VERSION_")) {
Tuple tupWithResults = new Tuple(new Tuple3(null, null, null), null);
Tuple3 superTupWithResults = (Tuple3) tupWithResults.o1;
//tupWithResults.o2 = DiskCache
if (string.toString().equals(expected)) {
//OK, proceed with new I/O format!
try {
try {
FastStringBuffer line;
Map<Integer, String> dictionary = null;
FastStringBuffer tempBuf = new FastStringBuffer(1024);
while ((line = bufferedReader.readLine()) != null) {
if (line.startsWith("-- ")) {
if (line.startsWith("-- START TREE 1")) {
superTupWithResults.o1 = TreeIO.loadTreeFrom(bufferedReader, dictionary,
tempBuf.clear(), objectsPoolMap);
} else if (line.startsWith("-- START TREE 2")) {
superTupWithResults.o2 = TreeIO.loadTreeFrom(bufferedReader, dictionary,
tempBuf.clear(), objectsPoolMap);
} else if (line.startsWith("-- START DICTIONARY")) {
dictionary = TreeIO.loadDictFrom(bufferedReader, tempBuf.clear(),
objectsPoolMap);
} else if (line.startsWith("-- START DISKCACHE")) {
tupWithResults.o2 = DiskCache.loadFrom(bufferedReader, objectsPoolMap);
} else if (line.startsWith("-- VERSION_")) {
if (!line.endsWith("3")) {
throw new RuntimeException("Expected the version to be 3.");
}
} else if (line.startsWith("-- END TREE")) {
//just skip it in this situation.
} else {
throw new RuntimeException("Unexpected line: " + line);
}
}
}
} finally {
bufferedReader.close();
}
} finally {
reader.close();
}