use of org.apache.commons.compress.archivers.ArchiveException in project Xponents by OpenSextant.
the class ArchiveNavigator method untar.
/*
* Un-TAR Once items are saved off to temp folder, they'll be converted by
* the file converter. The converter can choose to do something else with
* them.
*/
public File untar(File tarFile) throws IOException, ConfigException {
String _working = FilenameUtils.concat(getWorkingDir(), FilenameUtils.getBaseName(tarFile.getPath()));
if (_working == null) {
throw new IOException("Invalid archive path for " + tarFile.getPath());
}
File workingDir = new File(_working);
workingDir.mkdir();
InputStream input = new BufferedInputStream(new FileInputStream(tarFile));
TarArchiveInputStream in = null;
try {
in = (TarArchiveInputStream) (new ArchiveStreamFactory().createArchiveInputStream("tar", input));
TarArchiveEntry tarEntry;
while ((tarEntry = (TarArchiveEntry) in.getNextEntry()) != null) {
if (filterEntry(tarEntry)) {
continue;
}
try {
File tmpFile = saveArchiveEntry(tarEntry, in, _working);
converter.convert(tmpFile);
} catch (IOException err) {
log.error("Unable to save item, FILE=" + tarFile.getName() + "!" + tarEntry.getName(), err);
}
}
} catch (ArchiveException ae) {
throw new IOException(ae);
} finally {
in.close();
}
return workingDir;
}
use of org.apache.commons.compress.archivers.ArchiveException in project caffeine by ben-manes.
the class AbstractTraceReader method readFile.
/** Returns the input stream, decompressing if required. */
private InputStream readFile(String filePath) throws IOException {
BufferedInputStream input = new BufferedInputStream(openFile(filePath), BUFFER_SIZE);
input.mark(100);
try {
return new XZInputStream(input);
} catch (IOException e) {
input.reset();
}
try {
return new CompressorStreamFactory().createCompressorInputStream(input);
} catch (CompressorException e) {
input.reset();
}
try {
return new ArchiveStreamFactory().createArchiveInputStream(input);
} catch (ArchiveException e) {
input.reset();
}
return input;
}
use of org.apache.commons.compress.archivers.ArchiveException in project halyard by spinnaker.
the class BackupService method untarHalconfig.
private void untarHalconfig(String halconfigDir, String halconfigTar) {
FileInputStream tarInput = null;
TarArchiveInputStream tarArchiveInputStream = null;
try {
tarInput = new FileInputStream(new File(halconfigTar));
tarArchiveInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", tarInput);
} catch (IOException | ArchiveException e) {
throw new HalException(Problem.Severity.FATAL, "Failed to open backup: " + e.getMessage(), e);
}
try {
ArchiveEntry archiveEntry = tarArchiveInputStream.getNextEntry();
while (archiveEntry != null) {
String entryName = archiveEntry.getName();
Path outputPath = Paths.get(halconfigDir, entryName);
File outputFile = outputPath.toFile();
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}
if (archiveEntry.isDirectory()) {
outputFile.mkdir();
} else {
Files.copy(tarArchiveInputStream, outputPath, REPLACE_EXISTING);
}
archiveEntry = tarArchiveInputStream.getNextEntry();
}
} catch (IOException e) {
throw new HalException(Problem.Severity.FATAL, "Failed to read archive entry: " + e.getMessage(), e);
}
}
use of org.apache.commons.compress.archivers.ArchiveException in project halyard by spinnaker.
the class RegistryBackedArchiveProfileBuilder method build.
public List<Profile> build(DeploymentConfiguration deploymentConfiguration, String baseOutputPath, SpinnakerArtifact artifact, String archiveName) {
String version = artifactService.getArtifactVersion(deploymentConfiguration.getName(), artifact);
InputStream is;
try {
is = profileRegistry.readArchiveProfile(artifact.getName(), version, archiveName);
} catch (IOException e) {
throw new HalException(Problem.Severity.FATAL, "Error retrieving contents of archive " + archiveName + ".tar.gz", e);
}
TarArchiveInputStream tis;
try {
tis = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
} catch (ArchiveException e) {
throw new HalException(Problem.Severity.FATAL, "Failed to unpack tar archive", e);
}
try {
List<Profile> result = new ArrayList<>();
ArchiveEntry profileEntry = tis.getNextEntry();
while (profileEntry != null) {
if (profileEntry.isDirectory()) {
profileEntry = tis.getNextEntry();
continue;
}
String entryName = profileEntry.getName();
String profileName = String.join("/", artifact.getName(), archiveName, entryName);
String outputPath = Paths.get(baseOutputPath, archiveName, entryName).toString();
String contents = IOUtils.toString(tis);
result.add((new ProfileFactory() {
@Override
protected void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) {
profile.setContents(profile.getBaseContents());
}
@Override
protected Profile getBaseProfile(String name, String version, String outputFile) {
return new Profile(name, version, outputFile, contents);
}
@Override
protected boolean showEditWarning() {
return false;
}
@Override
protected ArtifactService getArtifactService() {
return artifactService;
}
@Override
public SpinnakerArtifact getArtifact() {
return artifact;
}
@Override
protected String commentPrefix() {
return null;
}
}).getProfile(profileName, outputPath, deploymentConfiguration, null));
profileEntry = tis.getNextEntry();
}
return result;
} catch (IOException e) {
throw new HalException(Problem.Severity.FATAL, "Failed to read profile entry", e);
}
}
use of org.apache.commons.compress.archivers.ArchiveException in project onebusaway-application-modules by camsys.
the class SyncBundleAction method unzipBundle.
private void unzipBundle(String tmpDir, String bundleFileName) throws IOException {
byte[] buffer = new byte[1024];
GZIPInputStream zipIn = new GZIPInputStream(new FileInputStream(tmpDir + File.separator + bundleFileName));
FileOutputStream out = new FileOutputStream(tmpDir + File.separator + "unzippedBundle");
int len;
while ((len = zipIn.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
zipIn.close();
out.close();
// Now to untar the unzipped file
File tarFile = new File(tmpDir + File.separator + "unzippedBundle");
File untarredFile = new File(tmpDir + File.separator + "untarredBundle");
// File untarredFile = new File(tmpDir);
try {
List<File> fileList = (new FileUtility()).unTar(tarFile, untarredFile);
} catch (ArchiveException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}
Aggregations