private static String queryRepository(File repositoryFile,
String zipEntryName,
DeviceRepositoryQuery query)
throws RepositoryException {
if (!repositoryFile.canRead()) {
throw new RepositoryException(
exceptionLocalizer.format(
"file-cannot-be-read",
repositoryFile));
}
InputStream is = null;
String queryResult = null;
try {
ZipFile repositoryZip =
new ZipFile(repositoryFile, ZipFile.OPEN_READ);
ZipEntry versionEntry = repositoryZip.getEntry(zipEntryName);
is = repositoryZip.getInputStream(versionEntry);
queryResult = query.doQuery(is);
} catch (IOException e) {
logger.error("unexpected-ioexception", e);
throw new RepositoryException(
exceptionLocalizer.format(
"unexpected-ioexception"),
e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
logger.error("unexpected-ioexception", e);
if (queryResult != null) {
// A null queryResult would indicate that another exception
// was thrown so only throw on a close() exception if this
// has not happened to avoid hiding the real problem.
throw new RepositoryException(
exceptionLocalizer.format(
"unexpected-ioexception"),
e);
}
}