use of org.apache.commons.compress.archivers.ArchiveEntry in project uPortal by Jasig.
the class JaxbPortalDataHandlerService method importDataArchive.
/**
* Extracts the archive resource and then runs the batch-import process on it.
*/
private void importDataArchive(final Resource resource, final ArchiveInputStream resourceStream, BatchImportOptions options) {
final File tempDir = Files.createTempDir();
try {
ArchiveEntry archiveEntry;
while ((archiveEntry = resourceStream.getNextEntry()) != null) {
final File entryFile = new File(tempDir, archiveEntry.getName());
if (!archiveEntry.isDirectory()) {
entryFile.getParentFile().mkdirs();
IOUtils.copy(new CloseShieldInputStream(resourceStream), new FileOutputStream(entryFile));
}
}
importDataDirectory(tempDir, null, options);
} catch (IOException e) {
throw new RuntimeException("Failed to extract data from '" + resource + "' to '" + tempDir + "' for batch import.", e);
} finally {
FileUtils.deleteQuietly(tempDir);
}
}
use of org.apache.commons.compress.archivers.ArchiveEntry in project winery by eclipse.
the class Generator method addFilesRecursively.
/**
* Recursive Helper function for packageProject()
*
* @param folderOrFile to add into the archive
* @param baseDir the base directory, which is to be stripped from the file name
* @param zos ArchiveOutputStream to add the files to
*/
private void addFilesRecursively(File folderOrFile, String baseDir, ArchiveOutputStream zos) {
if (folderOrFile.isFile()) {
String nameOfFileInZip = folderOrFile.getAbsolutePath().replace(baseDir, "");
Generator.LOGGER.trace("Adding " + folderOrFile + " as " + nameOfFileInZip);
ArchiveEntry archiveEntry = new ZipArchiveEntry(nameOfFileInZip);
try (InputStream is = new FileInputStream(folderOrFile)) {
zos.putArchiveEntry(archiveEntry);
IOUtils.copy(is, zos);
zos.closeArchiveEntry();
} catch (Exception e) {
e.printStackTrace();
}
} else {
Generator.LOGGER.trace("Adding folder " + folderOrFile);
for (File childFile : folderOrFile.listFiles()) {
this.addFilesRecursively(childFile, baseDir, zos);
}
}
}
Aggregations