use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class AbstractClasspathBasedModuleLoader method parseMultipleCsvFiles.
/**
* parses multiple files held in a index.txt file
*/
private void parseMultipleCsvFiles() {
// read files one by one
final String directory = this.resourcePath.substring(0, this.resourcePath.lastIndexOf('/') + 1);
final InputStream stream = ModuleLoader.class.getResourceAsStream(this.resourcePath);
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(stream));
String line = null;
while ((line = reader.readLine()) != null) {
if (!line.startsWith("--")) {
parseSingleFile(directory + line);
}
}
} catch (final IOException e) {
throw new StepInternalException("Unable to read index.txt file", e);
} finally {
closeQuietly(reader);
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class AbstractClasspathBasedModuleLoader method calculateSkipLines.
/**
* Calculates the number of lines to be skipped
* @param resourcePath the path to the resource
* @return
*/
private int calculateSkipLines(final String resourcePath) {
BufferedReader reader = null;
try {
int skipLines = 0;
reader = new BufferedReader(new InputStreamReader(ModuleLoader.class.getResourceAsStream(resourcePath)));
String line;
while ((line = reader.readLine()) != null && line.length() != 0 && line.charAt(0) == '#') {
LOG.trace("Skipping line...");
skipLines++;
}
return skipLines;
} catch (IOException ex) {
throw new StepInternalException("Failed to skip lines", ex);
} finally {
IOUtils.closeQuietly(reader);
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class Loader method init.
/**
* Creates the table and loads the initial data set
*/
public void init() {
if (this.inProgress) {
return;
}
this.totalProgress = 0;
try {
this.inProgress = true;
listenInJobs();
if (!Boolean.getBoolean("step.skipBookInstallation")) {
// remove any internet loader, because we are running locally first...
// THIS LINE IS ABSOLUTELY CRITICAL AS IT DISABLES HTTP INSTALLER ON AN APPLICATION-WIDE LEVEL
this.jswordModule.setOffline(true);
// attempt to reload the installer list. This ensures we have all the versions in the available bibles
// that we need
this.jswordModule.reloadInstallers();
final List<Book> availableModules = this.jswordModule.getAllModules(-1, BookCategory.BIBLE, BookCategory.COMMENTARY);
final String[] initials = new String[availableModules.size()];
// This may put too much stress on smaller systems, since indexing for all modules in
// package
// would result as happening at the same times
this.totalItems += availableModules.size() * 2;
for (int ii = 0; ii < availableModules.size(); ii++) {
final Book b = availableModules.get(ii);
installAndIndex(b.getInitials());
initials[ii] = b.getInitials();
}
this.jswordModule.waitForIndexes(initials);
}
// now we can load the data
loadData();
this.complete = true;
appManager.setAndSaveAppVersion(runningAppVersion);
} catch (Exception ex) {
// wrap it into an internal exception so that we get some logging.
throw new StepInternalException(ex.getMessage(), ex);
} finally {
if (workListener != null) {
JobManager.removeWorkListener(workListener);
}
this.jswordModule.setOffline(false);
this.inProgress = false;
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class HeadwordLineBasedLoader method parseFile.
@Override
protected void parseFile(final Reader reader, int skipLines) {
final BufferedReader bufferedReader = new BufferedReader(reader);
String line = null;
try {
while ((line = bufferedReader.readLine()) != null) {
parseLine(line);
}
} catch (final IOException e) {
throw new StepInternalException("Unable to read a line from the source file ", e);
}
// save last article
this.writer.save();
LOGGER.info("Loaded [{}] entries.", this.count);
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class AnalyzedPrefixSearchQueryParser method getPrefixQuery.
@Override
protected org.apache.lucene.search.Query getPrefixQuery(final String field, final String termStr) throws ParseException {
TokenStream source;
final Analyzer analyzer = super.getAnalyzer();
try {
source = analyzer.reusableTokenStream(field, new StringReader(termStr));
source.reset();
final BooleanQuery query = new BooleanQuery();
// now need to consume the stream
while (source.incrementToken()) {
final TermAttribute attribute = source.getAttribute(TermAttribute.class);
final String prefixTerm = attribute.term();
if (prefixTerm.length() != 0) {
final org.apache.lucene.search.Query prefixQuery = super.getPrefixQuery(field, prefixTerm);
query.add(prefixQuery, Occur.SHOULD);
}
}
return query;
} catch (final IOException e) {
throw new StepInternalException("Unable to make a prefix query", e);
}
}
Aggregations