use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class JSwordStrongNumberHelper method applySearchCounts.
/**
* Applies the search counts for every strong number.
*
* @param bookName the book name
* @param augmentedByStrong the augmented strongs found in the original augmentation querys
*/
private void applySearchCounts(final String bookName, final Map<String, EntityDoc> augmentedByStrong) {
try {
final IndexSearcher is = jSwordSearchService.getIndexSearcher(this.isOT ? STRONG_OT_VERSION_BOOK.getInitials() : STRONG_NT_VERSION_BOOK.getInitials());
final TermDocs termDocs = is.getIndexReader().termDocs();
for (final Entry<String, BookAndBibleCount> strong : this.allStrongs.entrySet()) {
final String strongKey = strong.getKey();
termDocs.seek(new Term(LuceneIndex.FIELD_STRONG, this.strongAugmentationService.reduce(strongKey)));
final EntityDoc entityDoc = augmentedByStrong.get(strongKey);
final String references = entityDoc != null ? entityDoc.get("references") : null;
// we'll never need more than 200 documents as this is the cut off point
int bible = 0;
int book = 0;
while (termDocs.next()) {
final int freq = termDocs.freq();
final Document doc = is.doc(termDocs.doc());
final String docRef = doc.get(LuceneIndex.FIELD_KEY);
if ((references == null || augmentedVersionInVerse(docRef, references))) {
if (docRef != null && docRef.startsWith(bookName)) {
book += freq;
}
bible += freq;
}
}
final BookAndBibleCount value = strong.getValue();
value.setBible(bible);
value.setBook(book);
}
} catch (final IOException e) {
throw new StepInternalException(e.getMessage(), e);
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class SupportRequestServiceImpl method readImage.
private byte[] readImage(final InputStream imageData) {
ByteArrayOutputStream outputStream = null;
BufferedOutputStream bos = null;
BufferedInputStream bis = null;
try {
outputStream = new ByteArrayOutputStream();
bos = new BufferedOutputStream(outputStream);
bis = new BufferedInputStream(imageData);
int b;
while ((b = bis.read()) != -1) {
bos.write(b);
}
bos.flush();
return outputStream.toByteArray();
} catch (IOException ex) {
throw new StepInternalException("Unable to read image data");
} finally {
IOUtils.closeQuietly(bos);
IOUtils.closeQuietly(bis);
IOUtils.closeQuietly(outputStream);
IOUtils.closeQuietly(imageData);
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class SupportRequestServiceImpl method readResponse.
private String readResponse(final HttpEntity entity) {
if (entity == null) {
return "";
}
InputStream content = null;
BufferedReader reader = null;
InputStreamReader inputStreamReader = null;
try {
content = entity.getContent();
if (content == null) {
return "";
}
inputStreamReader = new InputStreamReader(content);
reader = new BufferedReader(inputStreamReader);
final StringBuilder response = new StringBuilder(256);
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
return response.toString().replaceAll("[\\n\\r]", "");
} catch (IOException e) {
throw new StepInternalException("Unable to parse response", e);
} finally {
EntityUtils.consumeQuietly(entity);
IOUtils.closeQuietly(reader);
IOUtils.closeQuietly(inputStreamReader);
IOUtils.closeQuietly(content);
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class SwingServiceImpl method addDirectoryInstaller.
@Override
public BibleInstaller addDirectoryInstaller() {
ResourceBundle bundle = ResourceBundle.getBundle("HtmlBundle", clientSessionProvider.get().getLocale());
setDefaultUILookAndFeel();
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
chooser.setDialogTitle(bundle.getString("select_directory"));
chooser.setRequestFocusEnabled(true);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
return moduleService.addDirectoryInstaller(chooser.getSelectedFile().getAbsolutePath());
}
throw new StepInternalException("Unable to select a directory - exit ungracefully");
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class UserServiceImpl method readUsersFile.
/**
* @return a set of users
*/
private synchronized Set<String> readUsersFile() {
final Set<String> usersFromFile = new HashSet<String>();
if (!this.usersFile.exists()) {
return usersFromFile;
}
FileInputStream fis = null;
BufferedReader reader = null;
InputStreamReader isr = null;
try {
fis = new FileInputStream(this.usersFile);
isr = new InputStreamReader(fis);
reader = new BufferedReader(isr);
String line = null;
while ((line = reader.readLine()) != null) {
final String[] userEntry = line.split("[,]+");
if (userEntry.length < 2) {
LOGGER.warn("Invalid user entry: [{}]", line);
continue;
}
// add email to hashset
usersFromFile.add(userEntry[0]);
}
} catch (final IOException e) {
throw new StepInternalException("Unable to read file", e);
} finally {
IOUtils.closeQuietly(fis);
IOUtils.closeQuietly(isr);
IOUtils.closeQuietly(reader);
}
return usersFromFile;
}
Aggregations