use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class EntityConfiguration method loadProperties.
/**
* Loads the properties from file
*
* @param entityName the name of the entity
* @return the set of properties
*/
private Properties loadProperties(final String entityName) {
InputStream resourceAsStream = null;
try {
resourceAsStream = getClass().getResourceAsStream(entityName + ".properties");
final Properties properties = new Properties();
properties.load(resourceAsStream);
return properties;
} catch (final IOException e) {
throw new StepInternalException("Unable to load entity configuration " + entityName, e);
} finally {
IOUtils.closeQuietly(resourceAsStream);
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class EntityIndexWriterImpl method addDocument.
/**
* adds a document to the index
*/
@SuppressWarnings("PMD")
private void addDocument() {
try {
if (this.doc != null) {
this.writer.addDocument(this.doc);
this.doc = null;
}
} catch (final IOException e) {
throw new StepInternalException("Unable to write document", e);
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class EntityIndexReaderImpl method openDirectory.
/**
* Gets the best implementation of the directory
*
* @param configuration config
* @param memoryMapDirectory memory mapped directories
*/
private void openDirectory(final EntityConfiguration configuration, final boolean memoryMapDirectory) {
try {
final URI entityIndexPath = configuration.getLocation();
final File path = new File(entityIndexPath);
if (!path.exists()) {
return;
}
if (memoryMapDirectory) {
this.directory = MMapDirectory.open(path);
}
this.directory = FSDirectory.open(path);
} catch (final IOException e) {
throw new StepInternalException("Unable to read directory", e);
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class StreamingCsvModuleLoader method parseCsvFile.
/**
* Default method for parsing file, uses column strategy
*
* @param csvReader the csv reader
*/
protected void parseCsvFile(final CSVReader csvReader) {
String[] line = null;
String[] headerLine;
try {
headerLine = csvReader.readNext();
while ((line = csvReader.readNext()) != null) {
processFields(line, headerLine);
this.writer.save();
}
} catch (final IOException e) {
throw new StepInternalException("Failed to read file", e);
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class EntityIndexWriterImpl method close.
/**
* writes the index to the relevant file location
*
* @return the number of entries in the index
*/
public int close() {
final int numEntries = getNumEntriesInIndex();
final File file = new File(this.config.getLocation());
Directory destination;
try {
// we've finished writing entries now, so close our writer
this.writer.close();
// open up a location on disk
destination = FSDirectory.open(file);
final IndexWriter fsWriter = new IndexWriter(destination, this.config.getAnalyzerInstance(), true, IndexWriter.MaxFieldLength.UNLIMITED);
fsWriter.addIndexesNoOptimize(new Directory[] { this.ramDirectory });
fsWriter.optimize();
fsWriter.close();
destination.close();
this.ramDirectory.close();
this.manager.refresh(this.config.getName());
} catch (final IOException e) {
throw new StepInternalException("Unable to write index", e);
}
return numEntries;
}
Aggregations