use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project jib by google.
the class TarStreamBuilderTest method testToBlob.
@Test
public void testToBlob() throws IOException {
Blob blob = testTarStreamBuilder.toBlob();
// Writes the BLOB and captures the output.
ByteArrayOutputStream tarByteOutputStream = new ByteArrayOutputStream();
blob.writeTo(tarByteOutputStream);
// Rearrange the output into input for verification.
ByteArrayInputStream tarByteInputStream = new ByteArrayInputStream(tarByteOutputStream.toByteArray());
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(tarByteInputStream);
verifyTarArchive(tarArchiveInputStream);
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project onebusaway-application-modules by camsys.
the class FileUtility method unTar.
/**
* Untar an input file into an output file.
*
* The output file is created in the output folder, having the same name as
* the input file, minus the '.tar' extension.
*
* @param inputFile the input .tar file
* @param outputDir the output directory file.
* @throws IOException
* @throws FileNotFoundException
*
* @return The {@link List} of {@link File}s with the untared content.
* @throws ArchiveException
*/
public List<File> unTar(final File inputFile, final File outputDir) throws FileNotFoundException, IOException, ArchiveException {
_log.info(String.format("Untaring %s to dir %s.", inputFile.getAbsolutePath(), outputDir.getAbsolutePath()));
final List<File> untaredFiles = new LinkedList<File>();
final InputStream is = new FileInputStream(inputFile);
final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
TarArchiveEntry entry = null;
while ((entry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) {
final File outputFile = new File(outputDir, entry.getName());
if (entry.isDirectory()) {
_log.info(String.format("Attempting to write output directory %s.", outputFile.getAbsolutePath()));
if (!outputFile.exists()) {
_log.info(String.format("Attempting to create output directory %s.", outputFile.getAbsolutePath()));
if (!outputFile.mkdirs()) {
throw new IllegalStateException(String.format("CHUNouldn't create directory %s.", outputFile.getAbsolutePath()));
}
}
} else {
_log.info(String.format("Creating output file %s.", outputFile.getAbsolutePath()));
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.tar.TarArchiveInputStream in project tycho by eclipse.
the class TarGzArchiverTest method getTarEntry.
private byte[] getTarEntry(String name) throws IOException {
TarArchiveInputStream tarStream = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(tarGzArchive)));
try {
TarArchiveEntry tarEntry = null;
while ((tarEntry = tarStream.getNextTarEntry()) != null) {
if (name.equals(tarEntry.getName())) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(tarStream, baos);
return baos.toByteArray();
}
}
} finally {
tarStream.close();
}
throw new IOException(name + " not found in " + tarGzArchive);
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project tycho by eclipse.
the class TarGzArchiverTest method getTarEntries.
private Map<String, TarArchiveEntry> getTarEntries() throws IOException, FileNotFoundException {
TarArchiveInputStream tarStream = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(tarGzArchive)));
Map<String, TarArchiveEntry> entries = new HashMap<>();
try {
TarArchiveEntry tarEntry = null;
while ((tarEntry = tarStream.getNextTarEntry()) != null) {
entries.put(tarEntry.getName(), tarEntry);
}
} finally {
tarStream.close();
}
return entries;
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project docker-client by spotify.
the class DefaultDockerClientTest method testExportContainer.
@Test
public void testExportContainer() throws Exception {
// Pull image
sut.pull(BUSYBOX_LATEST);
// Create container
final ContainerConfig config = ContainerConfig.builder().image(BUSYBOX_LATEST).build();
final String name = randomName();
final ContainerCreation creation = sut.createContainer(config, name);
final String id = creation.id();
final ImmutableSet.Builder<String> files = ImmutableSet.builder();
try (TarArchiveInputStream tarStream = new TarArchiveInputStream(sut.exportContainer(id))) {
TarArchiveEntry entry;
while ((entry = tarStream.getNextTarEntry()) != null) {
files.add(entry.getName());
}
}
// Check that some common files exist
assertThat(files.build(), both(hasItem("bin/")).and(hasItem("bin/sh")));
}
Aggregations