@Override
public synchronized void init() throws IOException, IllegalStateException {
Preconditions.checkState(!this.initialized && !this.closed);
this.initialized = true;
InputStream stream = null;
try {
if (this.fileSystem.exists(this.filePath)) {
stream = Files.readWithBackup(this.fileSystem, this.filePath);
final RDFFormat format = RDFFormat.forFileName(this.filePath.getName());
final List<Record> records = Record.decode(
RDFUtil.readRDF(stream, format, null, null, false),
ImmutableSet.of(KS.RESOURCE, KS.MENTION, KS.ENTITY, KS.CONTEXT), false)
.toList();
for (final Record record : records) {
final URI id = Preconditions.checkNotNull(record.getID());
final URI type = Preconditions.checkNotNull(record.getSystemType());
MemoryDataStore.this.tables.get(type).put(id, record);
}
MemoryDataStore.LOGGER.info("{} initialized, {} records loaded", this.getClass()
.getSimpleName(), records.size());
} else {
MemoryDataStore.LOGGER.info("{} initialized, no record loaded", this.getClass()
.getSimpleName());
}
} finally {
Util.closeQuietly(stream);
}
}