use of org.apache.aries.util.IORuntimeException in project aries by apache.
the class FileSystemImpl method getFSRoot.
public static ICloseableDirectory getFSRoot(InputStream is) {
File tempFile = null;
try {
tempFile = File.createTempFile("inputStreamExtract", ".zip");
} catch (IOException e1) {
throw new IORuntimeException("IOException in IDirectory.getFSRoot", e1);
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(tempFile);
IOUtils.copy(is, fos);
} catch (IOException e) {
return null;
} finally {
IOUtils.close(fos);
}
IDirectory dir = getFSRoot(tempFile, null);
if (dir == null)
return null;
else
return new InputStreamClosableDirectory(dir, tempFile);
}
use of org.apache.aries.util.IORuntimeException in project aries by apache.
the class FileSystemImpl method isValidZip.
/**
* Check whether a file is actually a valid zip
* @param zip
* @return
*/
public static boolean isValidZip(File zip) {
try {
ZipFile zf = new ZipFile(zip);
zf.close();
return true;
} catch (IOException e) {
throw new IORuntimeException("Not a valid zip: " + zip, e);
}
}
use of org.apache.aries.util.IORuntimeException in project aries by apache.
the class NestedZipDirectory method getFile.
public IFile getFile(String name) {
Map<String, ZipEntry> entries = new HashMap<String, ZipEntry>();
ZipEntry ze;
if (cache != null && !!!cache.isClosed()) {
ZipFile zip = cache.getZipFile();
String[] segments = name.split("/");
StringBuilder path = new StringBuilder();
for (String s : segments) {
path.append(s).append('/');
ZipEntry p = zip.getEntry(path.toString());
if (p != null)
entries.put(path.toString(), p);
}
ze = zip.getEntry(name);
} else {
ZipInputStream zis = null;
try {
zis = new ZipInputStream(archive.open());
ze = zis.getNextEntry();
while (ze != null && !!!ze.getName().equals(name)) {
if (name.startsWith(ze.getName()))
entries.put(ze.getName(), ze);
ze = zis.getNextEntry();
}
} catch (IOException e) {
throw new IORuntimeException("IOException reading nested ZipFile", e);
} finally {
IOUtils.close(zis);
}
}
if (ze != null) {
NestedZipDirectory parent = buildParent(ze, entries);
if (ze.isDirectory())
return new NestedZipDirectory(archive, ze, parent, cache);
else
return new NestedZipFile(archive, ze, parent, cache);
} else {
return null;
}
}
use of org.apache.aries.util.IORuntimeException in project aries by apache.
the class NestedZipDirectory method getAllEntries.
private List<? extends ZipEntry> getAllEntries() {
if (cache != null && !!!cache.isClosed()) {
return Collections.list(cache.getZipFile().entries());
} else {
ZipInputStream zis = null;
try {
zis = new ZipInputStream(archive.open());
List<ZipEntry> result = new ArrayList<ZipEntry>();
ZipEntry entry = zis.getNextEntry();
while (entry != null) {
result.add(entry);
entry = zis.getNextEntry();
}
return result;
} catch (IOException e) {
throw new IORuntimeException("IOException reading nested ZipFile", e);
} finally {
IOUtils.close(zis);
}
}
}
use of org.apache.aries.util.IORuntimeException in project aries by apache.
the class FileSystemTest method testInvalidFSRoot.
@Test
public void testInvalidFSRoot() throws IOException {
File baseDir = new File(getTestResourceDir(), "/app1");
File manifest = new File(baseDir, "META-INF/APPLICATION.MF");
try {
FileSystem.getFSRoot(manifest);
fail("Should have thrown an IORuntimeException");
} catch (IORuntimeException e) {
// good!
}
}
Aggregations