use of org.apache.commons.compress.archivers.ArchiveStreamFactory in project kontraktor by RuedigerMoeller.
the class JNPM method unTar.
private static List<File> unTar(final InputStream is, final File outputDir) throws FileNotFoundException, IOException, ArchiveException {
final List<File> untaredFiles = new LinkedList<File>();
final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
TarArchiveEntry entry = null;
while ((entry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) {
String name = entry.getName();
if (name.startsWith("package/"))
name = name.substring("package/".length());
final File outputFile = new File(outputDir, name);
if (entry.isDirectory()) {
if (!outputFile.mkdirs()) {
throw new IllegalStateException(String.format("Couldn't create directory %s.", outputFile.getAbsolutePath()));
}
} else {
outputFile.getParentFile().mkdirs();
final OutputStream outputFileStream = new FileOutputStream(outputFile);
IOUtils.copy(debInputStream, outputFileStream);
outputFileStream.close();
}
untaredFiles.add(outputFile);
}
debInputStream.close();
return untaredFiles;
}
use of org.apache.commons.compress.archivers.ArchiveStreamFactory in project incubator-gobblin by apache.
the class AzkabanJobHelper method addFilesToZip.
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "OBL_UNSATISFIED_OBLIGATION", justification = "Lombok construct of @Cleanup is handing this, but not detected by FindBugs")
private static void addFilesToZip(File zipFile, List<File> filesToAdd) throws IOException {
try {
@Cleanup OutputStream archiveStream = new FileOutputStream(zipFile);
@Cleanup ArchiveOutputStream archive = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream);
for (File fileToAdd : filesToAdd) {
ZipArchiveEntry entry = new ZipArchiveEntry(fileToAdd.getName());
archive.putArchiveEntry(entry);
@Cleanup BufferedInputStream input = new BufferedInputStream(new FileInputStream(fileToAdd));
IOUtils.copy(input, archive);
archive.closeArchiveEntry();
}
archive.finish();
} catch (ArchiveException e) {
throw new IOException("Issue with creating archive", e);
}
}
use of org.apache.commons.compress.archivers.ArchiveStreamFactory in project packr by libgdx.
the class ArchiveUtils method extractGenericArchive.
/**
* Extracts an archive using {@link ArchiveStreamFactory#createArchiveInputStream(InputStream)} with no special handling of symbolic links or file
* permissions.
*
* @param inputStream the archive input stream
* @param extractToDirectory the directory to extract the archive into
* @throws ArchiveException if an archive error occurs
* @throws IOException if an IO error occurs
*/
private static void extractGenericArchive(InputStream inputStream, Path extractToDirectory) throws ArchiveException, IOException {
final ArchiveInputStream archiveInputStream = new ArchiveStreamFactory().createArchiveInputStream(inputStream);
ArchiveEntry entry;
while ((entry = archiveInputStream.getNextEntry()) != null) {
if (!archiveInputStream.canReadEntryData(entry)) {
LOG.error("Failed to read archive entry " + entry);
continue;
}
Path entryExtractPath = extractToDirectory.resolve(getEntryAsPath(entry));
if (entry.isDirectory()) {
Files.createDirectories(entryExtractPath);
} else {
Files.createDirectories(entryExtractPath.getParent());
Files.copy(archiveInputStream, entryExtractPath, StandardCopyOption.REPLACE_EXISTING);
}
Files.setLastModifiedTime(entryExtractPath, FileTime.fromMillis(entry.getLastModifiedDate().getTime()));
}
}
use of org.apache.commons.compress.archivers.ArchiveStreamFactory in project tomee by apache.
the class ExecMojo method createExecutableJar.
private void createExecutableJar() throws Exception {
mkdirs(execFile.getParentFile());
final Properties config = new Properties();
config.put("distribution", distributionName);
config.put("workingDir", runtimeWorkingDir);
config.put("command", DEFAULT_SCRIPT.equals(script) ? (skipArchiveRootFolder ? "" : catalinaBase.getName() + "/") + DEFAULT_SCRIPT : script);
final List<String> jvmArgs = generateJVMArgs();
final String catalinaOpts = toString(jvmArgs, " ");
config.put("catalinaOpts", catalinaOpts);
config.put("timestamp", Long.toString(System.currentTimeMillis()));
// java only
final String cp = getAdditionalClasspath();
if (cp != null) {
config.put("additionalClasspath", cp);
}
config.put("shutdownCommand", tomeeShutdownCommand);
int i = 0;
boolean encodingSet = catalinaOpts.contains("-Dfile.encoding");
for (final String jvmArg : jvmArgs) {
config.put("jvmArg." + i++, jvmArg);
encodingSet = encodingSet || jvmArg.contains("-Dfile.encoding");
}
if (!encodingSet) {
// forcing encoding for launched process to be able to read conf files
config.put("jvmArg." + i, "-Dfile.encoding=UTF-8");
}
if (preTasks != null) {
config.put("preTasks", toString(preTasks, ","));
}
if (postTasks != null) {
config.put("postTasks", toString(postTasks, ","));
}
config.put("waitFor", Boolean.toString(waitFor));
// create an executable jar with main runner and zipFile
final FileOutputStream fileOutputStream = new FileOutputStream(execFile);
final ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.JAR, fileOutputStream);
{
// distrib
os.putArchiveEntry(new JarArchiveEntry(distributionName));
final FileInputStream in = new FileInputStream(zipFile);
try {
IOUtils.copy(in, os);
os.closeArchiveEntry();
} finally {
IOUtil.close(in);
}
}
{
// config
os.putArchiveEntry(new JarArchiveEntry("configuration.properties"));
final StringWriter writer = new StringWriter();
config.store(writer, "");
IOUtils.copy(new ByteArrayInputStream(writer.toString().getBytes("UTF-8")), os);
os.closeArchiveEntry();
}
{
// Manifest
final Manifest manifest = new Manifest();
final Manifest.Attribute mainClassAtt = new Manifest.Attribute();
mainClassAtt.setName("Main-Class");
mainClassAtt.setValue(runnerClass);
manifest.addConfiguredAttribute(mainClassAtt);
final ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
manifest.write(baos);
os.putArchiveEntry(new JarArchiveEntry("META-INF/MANIFEST.MF"));
IOUtils.copy(new ByteArrayInputStream(baos.toByteArray()), os);
os.closeArchiveEntry();
}
{
// Main + utility
for (final Class<?> clazz : asList(ExecRunner.class, Files.class, Files.PatternFileFilter.class, Files.DeleteThread.class, Files.FileRuntimeException.class, Files.FileDoesNotExistException.class, Files.NoopOutputStream.class, LoaderRuntimeException.class, Pipe.class, IO.class, Zips.class, JarLocation.class, RemoteServer.class, RemoteServer.CleanUpThread.class, OpenEJBRuntimeException.class, Join.class, QuickServerXmlParser.class, Options.class, Options.NullLog.class, Options.TomEEPropertyAdapter.class, Options.NullOptions.class, Options.Log.class, JavaSecurityManagers.class)) {
addToJar(os, clazz);
}
}
addClasses(additionalClasses, os);
addClasses(preTasks, os);
addClasses(postTasks, os);
IOUtil.close(os);
IOUtil.close(fileOutputStream);
}
use of org.apache.commons.compress.archivers.ArchiveStreamFactory in project winery by eclipse.
the class Generator method packageProject.
/**
* Packages the generated project into a ZIP file which is stored in outDir and has the name of the Project.
*
* @param projectDir the dir where the generated files reside in
* @return ZIP file
*/
private File packageProject(Path projectDir) {
try {
File packagedProject = new File(this.outDir.getAbsoluteFile() + File.separator + this.name + ".zip");
FileOutputStream fileOutputStream = new FileOutputStream(packagedProject);
final ArchiveOutputStream zos = new ArchiveStreamFactory().createArchiveOutputStream("zip", fileOutputStream);
this.addFilesRecursively(projectDir.toAbsolutePath().toFile(), projectDir.toAbsolutePath() + File.separator, zos);
zos.finish();
zos.close();
return packagedProject;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Aggregations