use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project gradle by gradle.
the class TarTaskOutputPacker method unpack.
private UnpackResult unpack(SortedSet<ResolvedTaskOutputFilePropertySpec> propertySpecs, TarArchiveInputStream tarInput, TaskOutputOriginReader readOriginAction) throws IOException {
Map<String, ResolvedTaskOutputFilePropertySpec> propertySpecsMap = Maps.uniqueIndex(propertySpecs, new Function<TaskFilePropertySpec, String>() {
@Override
public String apply(TaskFilePropertySpec propertySpec) {
return propertySpec.getPropertyName();
}
});
TarArchiveEntry tarEntry;
OriginTaskExecutionMetadata originMetadata = null;
ImmutableListMultimap.Builder<String, FileSnapshot> propertyFileSnapshots = ImmutableListMultimap.builder();
long entries = 0;
while ((tarEntry = tarInput.getNextTarEntry()) != null) {
++entries;
String path = tarEntry.getName();
if (path.equals(METADATA_PATH)) {
// handle origin metadata
originMetadata = readOriginAction.execute(new CloseShieldInputStream(tarInput));
} else {
// handle output property
Matcher matcher = PROPERTY_PATH.matcher(path);
if (!matcher.matches()) {
throw new IllegalStateException("Cached result format error, invalid contents: " + path);
}
String propertyName = unescape(matcher.group(2));
ResolvedTaskOutputFilePropertySpec propertySpec = propertySpecsMap.get(propertyName);
if (propertySpec == null) {
throw new IllegalStateException(String.format("No output property '%s' registered", propertyName));
}
boolean outputMissing = matcher.group(1) != null;
String childPath = matcher.group(3);
unpackPropertyEntry(propertySpec, tarInput, tarEntry, childPath, outputMissing, propertyFileSnapshots);
}
}
if (originMetadata == null) {
throw new IllegalStateException("Cached result format error, no origin metadata was found.");
}
return new UnpackResult(originMetadata, entries, propertyFileSnapshots.build());
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project gradle by gradle.
the class CommonsTarPacker method unpack.
@Override
public void unpack(DataSource input, DataTargetFactory targetFactory) throws IOException {
TarArchiveInputStream tarInput = new TarArchiveInputStream(input.openInput());
while (true) {
TarArchiveEntry entry = tarInput.getNextTarEntry();
if (entry == null) {
break;
}
PackerUtils.unpackEntry(entry.getName(), tarInput, buffer, targetFactory);
}
tarInput.close();
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project meecrowave by apache.
the class MeecrowaveBundleMojo method tarGz.
private void tarGz(final TarArchiveOutputStream tarGz, final File f, final Path prefix) throws IOException {
final String path = prefix.relativize(f.toPath()).toString().replace(File.separator, "/");
final TarArchiveEntry archiveEntry = new TarArchiveEntry(f, path);
if (isSh(path)) {
archiveEntry.setMode(0755);
}
tarGz.putArchiveEntry(archiveEntry);
if (f.isDirectory()) {
tarGz.closeArchiveEntry();
final File[] files = f.listFiles();
if (files != null) {
for (final File child : files) {
tarGz(tarGz, child, prefix);
}
}
} else {
Files.copy(f.toPath(), tarGz);
tarGz.closeArchiveEntry();
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project Lucee by lucee.
the class CompressUtil method extractTar.
private static void extractTar(Resource tarFile, Resource targetDir) throws IOException {
if (!targetDir.exists() || !targetDir.isDirectory())
throw new IOException(targetDir + " is not a existing directory");
if (!tarFile.exists())
throw new IOException(tarFile + " is not a existing file");
if (tarFile.isDirectory()) {
Resource[] files = tarFile.listResources(new ExtensionResourceFilter("tar"));
if (files == null)
throw new IOException("directory " + tarFile + " is empty");
extract(FORMAT_TAR, files, targetDir);
return;
}
// read the zip file and build a query from its contents
TarArchiveInputStream tis = null;
try {
tis = new TarArchiveInputStream(IOUtil.toBufferedInputStream(tarFile.getInputStream()));
TarArchiveEntry entry;
int mode;
while ((entry = tis.getNextTarEntry()) != null) {
// print.ln(entry);
Resource target = targetDir.getRealResource(entry.getName());
if (entry.isDirectory()) {
target.mkdirs();
} else {
Resource parent = target.getParentResource();
if (!parent.exists())
parent.mkdirs();
IOUtil.copy(tis, target, false);
}
target.setLastModified(entry.getModTime().getTime());
mode = entry.getMode();
if (mode > 0)
target.setMode(mode);
// tis.closeEntry() ;
}
} finally {
IOUtil.closeEL(tis);
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project linuxtools by eclipse.
the class CopyFromContainerCommandHandler method performCopyFromContainer.
private void performCopyFromContainer(final IDockerConnection connection, final IDockerContainer container, final String target, final List<ContainerFileProxy> files) {
final Job copyFromContainerJob = new Job(CommandMessages.getFormattedString(COPY_FROM_CONTAINER_JOB_TITLE, container.name())) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
monitor.beginTask(CommandMessages.getString(COPY_FROM_CONTAINER_JOB_TASK), files.size());
try (Closeable token = ((DockerConnection) connection).getOperationToken()) {
for (ContainerFileProxy proxy : files) {
if (monitor.isCanceled()) {
monitor.done();
return Status.CANCEL_STATUS;
}
try {
monitor.setTaskName(CommandMessages.getFormattedString(COPY_FROM_CONTAINER_JOB_SUBTASK, proxy.getFullPath()));
monitor.worked(1);
InputStream in = ((DockerConnection) connection).copyContainer(token, container.id(), proxy.getLink());
/*
* The input stream from copyContainer might be
* incomplete or non-blocking so we should wrap it
* in a stream that is guaranteed to block until
* data is available.
*/
TarArchiveInputStream k = new TarArchiveInputStream(new BlockingInputStream(in));
TarArchiveEntry te = null;
while ((te = k.getNextTarEntry()) != null) {
long size = te.getSize();
IPath path = new Path(target);
path = path.append(te.getName());
File f = new File(path.toOSString());
if (te.isDirectory()) {
f.mkdir();
continue;
} else {
f.createNewFile();
}
FileOutputStream os = new FileOutputStream(f);
int bufferSize = ((int) size > 4096 ? 4096 : (int) size);
byte[] barray = new byte[bufferSize];
int result = -1;
while ((result = k.read(barray, 0, bufferSize)) > -1) {
if (monitor.isCanceled()) {
monitor.done();
k.close();
os.close();
return Status.CANCEL_STATUS;
}
os.write(barray, 0, result);
}
os.close();
}
k.close();
} catch (final DockerException e) {
Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), CommandMessages.getFormattedString(ERROR_COPYING_FROM_CONTAINER, proxy.getLink(), container.name()), e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
}
}
} catch (InterruptedException e) {
// do nothing
} catch (IOException e) {
Activator.log(e);
} catch (DockerException e1) {
Activator.log(e1);
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
copyFromContainerJob.schedule();
}
Aggregations