Search in sources :

Example 51 with StepInternalException

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);
    }
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties)

Example 52 with StepInternalException

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);
    }
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) IOException(java.io.IOException)

Example 53 with StepInternalException

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);
    }
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) IOException(java.io.IOException) URI(java.net.URI) File(java.io.File)

Example 54 with StepInternalException

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);
    }
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) IOException(java.io.IOException)

Example 55 with StepInternalException

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;
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) IndexWriter(org.apache.lucene.index.IndexWriter) IOException(java.io.IOException) File(java.io.File) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory)

Aggregations

StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)62 IOException (java.io.IOException)25 Book (org.crosswire.jsword.book.Book)9 Key (org.crosswire.jsword.passage.Key)7 EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)5 OsisWrapper (com.tyndalehouse.step.core.models.OsisWrapper)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 ParseException (org.apache.lucene.queryParser.ParseException)4 BookException (org.crosswire.jsword.book.BookException)4 Versification (org.crosswire.jsword.versification.Versification)4 LocalisedException (com.tyndalehouse.step.core.exceptions.LocalisedException)3 TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)3 KeyWrapper (com.tyndalehouse.step.core.models.KeyWrapper)3 FileInputStream (java.io.FileInputStream)3 TransformingSAXEventProvider (org.crosswire.common.xml.TransformingSAXEventProvider)3 XMLUtil.writeToString (org.crosswire.common.xml.XMLUtil.writeToString)3 NoSuchKeyException (org.crosswire.jsword.passage.NoSuchKeyException)3 BibleBook (org.crosswire.jsword.versification.BibleBook)3 AllResultsCollector (com.tyndalehouse.step.core.data.AllResultsCollector)2