use of org.python.pydev.core.FastBufferedReader in project Pydev by fabioz.
the class DiskCacheTest method testDiskCacheWithZipModulesKey.
public void testDiskCacheWithZipModulesKey() throws Exception {
DiskCache cache = new DiskCache(new File(baseDir, ".cache"), "_test_disk_cache");
cache.add(new CompleteIndexKey(new ModulesKey("mod1", new File(baseDir, "f1")), 100));
cache.add(new CompleteIndexKey(new ModulesKey("modnull", null), 100));
cache.add(new CompleteIndexKey(new ModulesKeyForZip("mod2", new File(baseDir, "my.zip"), "path", true), 100));
cache.add(new CompleteIndexKey(new ModulesKeyForZip("mod3", new File(baseDir, "my.zip"), "path2", false), 100));
FastStringBuffer tempBuf = new FastStringBuffer();
cache.writeTo(tempBuf);
FastBufferedReader reader = new FastBufferedReader(new StringReader(tempBuf.toString()));
//
FastStringBuffer line = reader.readLine();
assertEquals(line.toString(), "-- START DISKCACHE_" + DiskCache.VERSION);
ObjectsPoolMap objectsPoolMap = new ObjectsPoolMap();
DiskCache loadFrom = DiskCache.loadFrom(reader, objectsPoolMap);
assertEquals(cache.keys(), loadFrom.keys());
assertEquals(cache.getFolderToPersist(), loadFrom.getFolderToPersist());
CompleteIndexKey mod = cache.keys().get(new CompleteIndexKey("mod2"));
ModulesKeyForZip zip = (ModulesKeyForZip) mod.key;
assertEquals(zip.zipModulePath, "path");
mod = loadFrom.keys().get(new CompleteIndexKey("mod2"));
zip = (ModulesKeyForZip) mod.key;
assertEquals(zip.zipModulePath, "path");
mod = loadFrom.keys().get(new CompleteIndexKey("modnull"));
assertNull(mod.key.file);
mod = loadFrom.keys().get(new CompleteIndexKey("mod3"));
zip = (ModulesKeyForZip) mod.key;
assertEquals(zip.zipModulePath, "path2");
assertTrue(zip.isFile);
}
use of org.python.pydev.core.FastBufferedReader in project Pydev by fabioz.
the class AbstractAdditionalDependencyInfo method loadContentsFromFile.
private Object loadContentsFromFile(File file, IPythonNature nature) throws FileNotFoundException, IOException, MisconfigurationException {
FileInputStream fileInputStream = new FileInputStream(file);
try {
// Timer timer = new Timer();
// X is the version
String expected = "-- VERSION_" + AbstractAdditionalTokensInfo.version;
InputStreamReader reader = new InputStreamReader(fileInputStream);
FastBufferedReader bufferedReader = new FastBufferedReader(reader);
FastStringBuffer string = bufferedReader.readLine();
ObjectsPoolMap objectsPoolMap = new ObjectsInternPool.ObjectsPoolMap();
if (string != null && string.startsWith("-- VERSION_")) {
Tuple<Tuple3<Object, Object, Object>, Object> tupWithResults = new Tuple<Tuple3<Object, Object, Object>, Object>(new Tuple3<Object, Object, Object>(null, null, null), null);
Tuple3<Object, Object, Object> superTupWithResults = 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, nature);
} else if (line.startsWith("-- START TREE 2")) {
superTupWithResults.o2 = TreeIO.loadTreeFrom(bufferedReader, dictionary, tempBuf.clear(), objectsPoolMap, nature);
} else if (line.startsWith("-- START DICTIONARY")) {
dictionary = TreeIO.loadDictFrom(bufferedReader, tempBuf.clear(), objectsPoolMap);
} else if (line.startsWith("-- START DISKCACHE")) {
if (!line.startsWith("-- START DISKCACHE_" + DiskCache.VERSION)) {
throw new RuntimeException("Disk cache version changed");
}
tupWithResults.o2 = DiskCache.loadFrom(bufferedReader, objectsPoolMap);
} else if (line.startsWith("-- VERSION_")) {
if (!line.endsWith(String.valueOf(AbstractAdditionalTokensInfo.version))) {
throw new RuntimeException("Expected the version to be: " + AbstractAdditionalTokensInfo.version + " Found: " + line);
}
} 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();
}
restoreSavedInfo(tupWithResults);
// timer.printDiff("Time taken");
return tupWithResults;
} else {
throw new RuntimeException("Version does not match. Found: " + string + ". Expected: " + expected);
}
} else {
// Try the old way of loading it (backward compatibility).
fileInputStream.close();
// Timer timer2 = new Timer();
Object tupWithResults = IOUtils.readFromFile(file);
restoreSavedInfo(tupWithResults);
// timer2.printDiff("IOUtils time");
// Save in new format!
save();
return tupWithResults;
}
} finally {
try {
fileInputStream.close();
} catch (Exception e) {
// Ignore error closing.
}
}
}
Aggregations