Example usage for org.apache.commons.compress.archivers.ar ArArchiveInputStream read

List of usage examples for org.apache.commons.compress.archivers.ar ArArchiveInputStream read

Introduction

In this page you can find the example usage for org.apache.commons.compress.archivers.ar ArArchiveInputStream read.

Prototype

public int read() throws IOException 

Source Link

Document

Reads a byte of data.

Usage

From source file:org.vafer.jdeb.ar.ArInputStreamTestCase.java

public void testRead() throws Exception {
    final File archive = new File(getClass().getResource("data.ar").toURI());

    final ArArchiveInputStream ar = new ArArchiveInputStream(new FileInputStream(archive));
    final ArArchiveEntry entry1 = ar.getNextArEntry();

    assertEquals("data.tgz", entry1.getName());
    assertEquals(148, entry1.getLength());

    for (int i = 0; i < entry1.getLength(); i++) {
        ar.read();
    }/* ww w. j  av a  2s  . co m*/

    final ArArchiveEntry entry2 = ar.getNextArEntry();

    assertNull(entry2);

    ar.close();
}

From source file:org.vafer.jdeb.DataProducerTestCase.java

public void testCreation() throws Exception {

    final Processor processor = new Processor(new Console() {
        public void println(String s) {
        }/*from   w ww  .  jav  a2  s.c  o  m*/
    }, null);

    final File control = new File(getClass().getResource("deb/control/control").toURI());
    final File archive1 = new File(getClass().getResource("deb/data.tgz").toURI());
    final File archive2 = new File(getClass().getResource("deb/data.tar.bz2").toURI());
    final File directory = new File(getClass().getResource("deb/data").toURI());

    final DataProducer[] data = new DataProducer[] { new DataProducerArchive(archive1, null, null, null),
            new DataProducerArchive(archive2, null, null, null),
            new DataProducerDirectory(directory, null, new String[] { "**/.svn/**" }, null) };

    final File deb = File.createTempFile("jdeb", ".deb");

    final PackageDescriptor packageDescriptor = processor.createDeb(new File[] { control }, data, deb, "gzip");

    assertTrue(packageDescriptor.isValid());

    final Set filesInDeb = new HashSet();

    final ArArchiveInputStream ar = new ArArchiveInputStream(new FileInputStream(deb));
    while (true) {
        final ArArchiveEntry arEntry = ar.getNextArEntry();
        if (arEntry == null) {
            break;
        }

        if ("data.tar.gz".equals(arEntry.getName())) {

            final TarInputStream tar = new TarInputStream(new GZIPInputStream(new NonClosingInputStream(ar)));

            while (true) {
                final TarEntry tarEntry = tar.getNextEntry();
                if (tarEntry == null) {
                    break;
                }

                filesInDeb.add(tarEntry.getName());
            }

            tar.close();
            break;
        }
        for (int i = 0; i < arEntry.getLength(); i++) {
            ar.read();
        }
    }

    ar.close();

    assertTrue("testfile wasn't found in the package", filesInDeb.contains("./test/testfile"));
    assertTrue("testfile2 wasn't found in the package", filesInDeb.contains("./test/testfile2"));
    assertTrue("testfile3 wasn't found in the package", filesInDeb.contains("./test/testfile3"));

    assertTrue("Cannot delete the file " + deb, deb.delete());
}