use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project vespa by vespa-engine.
the class CompressedApplicationInputStreamTest method require_that_valid_tar_application_can_be_unpacked.
@Test
public void require_that_valid_tar_application_can_be_unpacked() throws IOException {
File outFile = createTarFile();
CompressedApplicationInputStream unpacked = CompressedApplicationInputStream.createFromCompressedStream(new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(outFile))));
File outApp = unpacked.decompress();
assertTestApp(outApp);
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project vespa by vespa-engine.
the class CompressedApplicationInputStreamTest method require_that_valid_tar_application_in_subdir_can_be_unpacked.
@Test
public void require_that_valid_tar_application_in_subdir_can_be_unpacked() throws IOException {
File outFile = File.createTempFile("testapp", ".tar.gz");
ArchiveOutputStream archiveOutputStream = new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(outFile)));
File app = new File("src/test/resources/deploy/validapp");
File file = new File(app, "services.xml");
archiveOutputStream.putArchiveEntry(archiveOutputStream.createArchiveEntry(file, "application/" + file.getName()));
ByteStreams.copy(new FileInputStream(file), archiveOutputStream);
archiveOutputStream.closeArchiveEntry();
file = new File(app, "hosts.xml");
archiveOutputStream.putArchiveEntry(archiveOutputStream.createArchiveEntry(file, "application/" + file.getName()));
ByteStreams.copy(new FileInputStream(file), archiveOutputStream);
archiveOutputStream.closeArchiveEntry();
file = new File(app, "deployment.xml");
archiveOutputStream.putArchiveEntry(archiveOutputStream.createArchiveEntry(file, "application/" + file.getName()));
ByteStreams.copy(new FileInputStream(file), archiveOutputStream);
archiveOutputStream.closeArchiveEntry();
archiveOutputStream.close();
CompressedApplicationInputStream unpacked = CompressedApplicationInputStream.createFromCompressedStream(new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(outFile))));
File outApp = unpacked.decompress();
// gets the name of the subdir
assertThat(outApp.getName(), is("application"));
assertTestApp(outApp);
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project vespa by vespa-engine.
the class CompressedApplicationInputStreamTest method require_that_nested_app_can_be_unpacked.
@Test
public void require_that_nested_app_can_be_unpacked() throws IOException, InterruptedException {
File tmpTar = File.createTempFile("myapp", ".tar");
Process p = new ProcessBuilder("tar", "-C", "src/test/resources/deploy/advancedapp", "--exclude=.svn", "-cvf", tmpTar.getAbsolutePath(), ".").start();
p.waitFor();
p = new ProcessBuilder("gzip", tmpTar.getAbsolutePath()).start();
p.waitFor();
File gzFile = new File(tmpTar.getAbsolutePath() + ".gz");
assertTrue(gzFile.exists());
CompressedApplicationInputStream unpacked = CompressedApplicationInputStream.createFromCompressedStream(new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(gzFile))));
File outApp = unpacked.decompress();
List<File> files = Arrays.asList(outApp.listFiles());
assertThat(files.size(), is(5));
assertTrue(files.contains(new File(outApp, "services.xml")));
assertTrue(files.contains(new File(outApp, "hosts.xml")));
assertTrue(files.contains(new File(outApp, "deployment.xml")));
assertTrue(files.contains(new File(outApp, "searchdefinitions")));
assertTrue(files.contains(new File(outApp, "external")));
File sd = files.get(files.indexOf(new File(outApp, "searchdefinitions")));
assertTrue(sd.isDirectory());
assertThat(sd.listFiles().length, is(1));
assertThat(sd.listFiles()[0].getAbsolutePath(), is(new File(sd, "keyvalue.sd").getAbsolutePath()));
File ext = files.get(files.indexOf(new File(outApp, "external")));
assertTrue(ext.isDirectory());
assertThat(ext.listFiles().length, is(1));
assertThat(ext.listFiles()[0].getAbsolutePath(), is(new File(ext, "foo").getAbsolutePath()));
files = Arrays.asList(ext.listFiles());
File foo = files.get(files.indexOf(new File(ext, "foo")));
assertTrue(foo.isDirectory());
assertThat(foo.listFiles().length, is(1));
assertThat(foo.listFiles()[0].getAbsolutePath(), is(new File(foo, "bar").getAbsolutePath()));
files = Arrays.asList(foo.listFiles());
File bar = files.get(files.indexOf(new File(foo, "bar")));
assertTrue(bar.isDirectory());
assertThat(bar.listFiles().length, is(1));
assertTrue(bar.listFiles()[0].isFile());
assertThat(bar.listFiles()[0].getAbsolutePath(), is(new File(bar, "lol").getAbsolutePath()));
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project vespa by vespa-engine.
the class CompressedApplicationInputStreamTest method require_that_invalid_application_returns_error_when_unpacked.
@Test(expected = IOException.class)
public void require_that_invalid_application_returns_error_when_unpacked() throws IOException {
File app = new File("src/test/resources/deploy/validapp/services.xml");
CompressedApplicationInputStream.createFromCompressedStream(new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(app))));
}
use of org.apache.commons.compress.archivers.tar.TarArchiveInputStream in project xodus by JetBrains.
the class CompressBackupUtilTest method testFileArchived.
@Test
public void testFileArchived() throws Exception {
File src = new File(randName + ".txt");
FileWriter fw = new FileWriter(src);
fw.write("12345");
fw.close();
CompressBackupUtil.tar(src, dest);
Assert.assertTrue("No destination archive created", dest.exists());
TarArchiveInputStream tai = new TarArchiveInputStream(new GZIPInputStream(new BufferedInputStream(new FileInputStream(dest))));
ArchiveEntry entry = tai.getNextEntry();
Assert.assertNotNull("No entry found in destination archive", entry);
Assert.assertEquals("Entry has wrong size", 5, entry.getSize());
}
Aggregations