use of org.crosswire.jsword.book.sword.SwordBookMetaData in project step by STEPBible.
the class DirectoryListingInstaller method extraConfFile.
/**
* Extracts a single conf file to read its details
*
* @param zipFile the zip file in question
*/
private void extraConfFile(BookDriver fakeDriver, File zipFile) {
InputStream in = null;
ZipInputStream zin = null;
try {
ConfigEntry.resetStatistics();
in = NetUtil.getInputStream(zipFile.toURI());
zin = new ZipInputStream(in);
while (true) {
ZipEntry entry = zin.getNextEntry();
if (entry == null) {
break;
}
String internal = entry.getName();
if (internal.endsWith(SwordConstants.EXTENSION_CONF)) {
LOGGER.trace("Reading a conf file [{}]", entry.getName());
try {
int size = (int) entry.getSize();
ByteArrayOutputStream os = new ByteArrayOutputStream();
byte[] bytes = new byte[1024];
int read;
while ((read = zin.read(bytes)) > 0) {
os.write(bytes, 0, read);
}
internal = internal.substring(0, internal.length() - 5);
if (internal.startsWith(SwordConstants.DIR_CONF + '/')) {
internal = internal.substring(7);
}
SwordBookMetaData sbmd = new SwordBookMetaData(os.toByteArray(), internal);
sbmd.setDriver(fakeDriver);
Book book = new SwordBook(sbmd, new NullBackend());
entries.put(book.getName(), book);
// assume 1 conf file per zip file
return;
} catch (Exception ex) {
LOGGER.error("Failed to load config for entry: {}", internal, ex);
}
}
}
ConfigEntry.dumpStatistics();
} catch (IOException ex) {
LOGGER.error("Failed to configuration from [{}]", zipFile.getName());
throw new StepInternalException("Error reading directory of zip files.", ex);
} finally {
IOUtil.close(zin);
IOUtil.close(in);
}
}
Aggregations