Search in sources :

Example 36 with TarArchiveInputStream

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);
}
Also used : TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 37 with TarArchiveInputStream

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);
}
Also used : TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) File(java.io.File) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) ArchiveOutputStream(org.apache.commons.compress.archivers.ArchiveOutputStream) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 38 with TarArchiveInputStream

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()));
}
Also used : TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 39 with TarArchiveInputStream

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))));
}
Also used : TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 40 with TarArchiveInputStream

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());
}
Also used : TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) FileWriter(java.io.FileWriter) ArchiveEntry(org.apache.commons.compress.archivers.ArchiveEntry) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)131 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)98 File (java.io.File)51 IOException (java.io.IOException)49 FileInputStream (java.io.FileInputStream)45 GzipCompressorInputStream (org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream)45 InputStream (java.io.InputStream)34 FileOutputStream (java.io.FileOutputStream)33 BufferedInputStream (java.io.BufferedInputStream)30 ByteArrayInputStream (java.io.ByteArrayInputStream)27 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)20 GZIPInputStream (java.util.zip.GZIPInputStream)20 ByteArrayOutputStream (java.io.ByteArrayOutputStream)19 ArchiveEntry (org.apache.commons.compress.archivers.ArchiveEntry)17 Path (java.nio.file.Path)16 OutputStream (java.io.OutputStream)15 BufferedOutputStream (java.io.BufferedOutputStream)12 ArchiveStreamFactory (org.apache.commons.compress.archivers.ArchiveStreamFactory)12 ArchiveInputStream (org.apache.commons.compress.archivers.ArchiveInputStream)7