use of org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream in project docker-client by spotify.
the class CompressedDirectoryTest method testFileWithIgnore.
@Test
public void testFileWithIgnore() throws Exception {
// note: Paths.get(someURL.toUri()) is the platform-neutral way to convert a URL to a Path
final URL dockerDirectory = Resources.getResource("dockerDirectoryWithIgnore");
try (CompressedDirectory dir = CompressedDirectory.create(Paths.get(dockerDirectory.toURI()));
BufferedInputStream fileIn = new BufferedInputStream(Files.newInputStream(dir.file()));
GzipCompressorInputStream gzipIn = new GzipCompressorInputStream(fileIn);
TarArchiveInputStream tarIn = new TarArchiveInputStream(gzipIn)) {
final List<String> names = new ArrayList<>();
TarArchiveEntry entry;
while ((entry = tarIn.getNextTarEntry()) != null) {
final String name = entry.getName();
names.add(name);
}
assertThat(names, containsInAnyOrder("Dockerfile", "bin/", "bin/date.sh", "subdir2/", "subdir2/keep.me", "subdir2/do-not.ignore", "subdir3/do.keep", ".dockerignore"));
}
}
use of org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream in project docker-client by spotify.
the class CompressedDirectoryTest method testFileWithEmptyDirectory.
@Test
public void testFileWithEmptyDirectory() throws Exception {
Path tempDir = Files.createTempDirectory("dockerDirectoryEmptySubdirectory");
tempDir.toFile().deleteOnExit();
assertThat(new File(tempDir.toFile(), "emptySubDir").mkdir(), is(true));
try (CompressedDirectory dir = CompressedDirectory.create(tempDir);
BufferedInputStream fileIn = new BufferedInputStream(Files.newInputStream(dir.file()));
GzipCompressorInputStream gzipIn = new GzipCompressorInputStream(fileIn);
TarArchiveInputStream tarIn = new TarArchiveInputStream(gzipIn)) {
final List<String> names = new ArrayList<>();
TarArchiveEntry entry;
while ((entry = tarIn.getNextTarEntry()) != null) {
final String name = entry.getName();
names.add(name);
}
assertThat(names, contains("emptySubDir/"));
}
}
use of org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream in project docker-client by spotify.
the class CompressedDirectoryTest method testFile.
@Test
public void testFile() throws Exception {
// note: Paths.get(someURL.toUri()) is the platform-neutral way to convert a URL to a Path
final URL dockerDirectory = Resources.getResource("dockerDirectory");
try (CompressedDirectory dir = CompressedDirectory.create(Paths.get(dockerDirectory.toURI()));
BufferedInputStream fileIn = new BufferedInputStream(Files.newInputStream(dir.file()));
GzipCompressorInputStream gzipIn = new GzipCompressorInputStream(fileIn);
TarArchiveInputStream tarIn = new TarArchiveInputStream(gzipIn)) {
final List<String> names = new ArrayList<>();
TarArchiveEntry entry;
while ((entry = tarIn.getNextTarEntry()) != null) {
final String name = entry.getName();
names.add(name);
}
assertThat(names, containsInAnyOrder("Dockerfile", "bin/", "bin/date.sh", "innerDir/", "innerDir/innerDockerfile"));
}
}
use of org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream in project RecordManager2 by moravianlibrary.
the class TarGzUtils method extract.
public static void extract(File tarFile, File destFile) throws IOException {
logger.info("Extracting file: " + tarFile.getName());
if (destFile.exists())
throw new FileAlreadyExistsException(destFile.getAbsolutePath());
if (!destFile.mkdir())
throw new IOException("Can't make directory for " + destFile.getAbsolutePath());
TarArchiveInputStream tarIn = new TarArchiveInputStream(new GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(tarFile))));
TarArchiveEntry tarEntry = tarIn.getNextTarEntry();
while (tarEntry != null) {
// create a file with the same name as the tarEntry
File destPath = new File(destFile, tarEntry.getName());
if (tarEntry.isDirectory()) {
if (!destPath.mkdirs())
logger.info("Can't make directory for " + destPath.getAbsolutePath());
} else {
if (!destPath.createNewFile())
logger.info("Name of file already exists " + destPath.getAbsolutePath());
BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(destPath));
byte[] btoRead = new byte[1024];
int len;
while ((len = tarIn.read(btoRead)) != -1) {
bout.write(btoRead, 0, len);
}
bout.close();
}
tarEntry = tarIn.getNextTarEntry();
}
tarIn.close();
}
use of org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream 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);
}
Aggregations