Package org.apache.commons.compress.archivers.tar

Examples of org.apache.commons.compress.archivers.tar.TarArchiveEntry


   private List<File> unTar(final File inputFile, final File outputDir) throws Exception {
      final List<File> untarredFiles = Lists.newArrayList();
      final InputStream is = new FileInputStream(inputFile);
      final TarArchiveInputStream tarArchiveInputStream = (TarArchiveInputStream)
              new ArchiveStreamFactory().createArchiveInputStream("tar", is);
      TarArchiveEntry entry;
      while ((entry = (TarArchiveEntry) tarArchiveInputStream.getNextEntry()) != null) {
         final File outputFile = new File(outputDir, entry.getName());
         if (entry.isDirectory()) {
            if (!outputFile.exists()) {
               if (!outputFile.mkdirs()) {
                  throw new IllegalStateException(String.format("Couldn't create directory %s.", outputFile.getAbsolutePath()));
               }
            }
View Full Code Here


    public static void read() throws Throwable {
        FileInputStream fis = new FileInputStream("C:\\X2.tgz");
        TarArchiveInputStream tis = new TarArchiveInputStream(new GZIPInputStream(fis));
        while (true) {
            TarArchiveEntry entry = tis.getNextTarEntry();
            if (entry == null)
                break;
            System.out.println(entry.getName());
        }
    }
View Full Code Here

            ZipArchiveEntry ze = null;
            byte[] schemaFile = null;
            while ((ze = zis.getNextZipEntry()) != null) {
                if (SOLR_TEMPLATE_SCHEMA.equals(ze.getName())) {
                    schemaFile = createSchemaXML(getLDPathProgram(ldPathProgram), IOUtils.toByteArray(zis));
                    TarArchiveEntry te = new TarArchiveEntry(coreName + SOLR_SCHEMA);
                    te.setSize(schemaFile.length);
                    tarOutputStream.putArchiveEntry(te);
                    tarOutputStream.write(schemaFile);
                    tarOutputStream.closeArchiveEntry();
                } else {
                    TarArchiveEntry te = new TarArchiveEntry(ze.getName().replaceAll(SOLR_TEMPLATE_NAME,
                        coreName));
                    te.setSize(ze.getSize());
                    tarOutputStream.putArchiveEntry(te);
                    tarOutputStream.write(IOUtils.toByteArray(zis));
                    tarOutputStream.closeArchiveEntry();
                }
View Full Code Here

            ZipArchiveEntry ze = null;
            byte[] schemaFile = null;
            while ((ze = zis.getNextZipEntry()) != null) {
                if (SOLR_TEMPLATE_SCHEMA.equals(ze.getName())) {
                    schemaFile = createSchemaXML(getLDPathProgram(ldPathProgram), IOUtils.toByteArray(zis));
                    TarArchiveEntry te = new TarArchiveEntry(coreName + SOLR_SCHEMA);
                    te.setSize(schemaFile.length);
                    tarOutputStream.putArchiveEntry(te);
                    tarOutputStream.write(schemaFile);
                    tarOutputStream.closeArchiveEntry();
                } else {
                    TarArchiveEntry te = new TarArchiveEntry(ze.getName().replaceAll(SOLR_TEMPLATE_NAME,
                        coreName));
                    te.setSize(ze.getSize());
                    tarOutputStream.putArchiveEntry(te);
                    tarOutputStream.write(IOUtils.toByteArray(zis));
                    tarOutputStream.closeArchiveEntry();
                }
View Full Code Here

        TarArchiveOutputStream tos = new TarArchiveOutputStream(cos);
        tos.setAddPaxHeadersForNonAsciiNames(true);
        tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);

        // add the Python script
        TarArchiveEntry pyEntry = new TarArchiveEntry("pt");
        pyEntry.setMode(FileMode.EXECUTABLE_FILE.getBits());
        pyEntry.setModTime(lastModified);
        pyEntry.setSize(pyBytes.length);
        tos.putArchiveEntry(pyEntry);
        tos.write(pyBytes);
        tos.closeArchiveEntry();

        // add a brief readme
        byte [] txtBytes = readAll(getClass().getResourceAsStream("/pt.txt"));
        TarArchiveEntry txtEntry = new TarArchiveEntry("README");
        txtEntry.setMode(FileMode.REGULAR_FILE.getBits());
        txtEntry.setModTime(lastModified);
        txtEntry.setSize(txtBytes.length);
        tos.putArchiveEntry(txtEntry);
        tos.write(txtBytes);
        tos.closeArchiveEntry();

        // cleanup
View Full Code Here

        }
        tw.getObjectId(id, 0);

        ObjectLoader loader = repository.open(id);
        if (FileMode.SYMLINK == mode) {
          TarArchiveEntry entry = new TarArchiveEntry(tw.getPathString(),TarArchiveEntry.LF_SYMLINK);
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          loader.copyTo(bos);
          entry.setLinkName(bos.toString());
          entry.setModTime(modified);
          tos.putArchiveEntry(entry);
          tos.closeArchiveEntry();
        } else {
          TarArchiveEntry entry = new TarArchiveEntry(tw.getPathString());
          entry.setMode(mode.getBits());
          entry.setModTime(modified);
          entry.setSize(loader.getSize());
          tos.putArchiveEntry(entry);
          loader.copyTo(tos);
          tos.closeArchiveEntry();
        }
      }
View Full Code Here

    {
        TarArchiveInputStream tis = null;
        try
        {
            tis = new TarArchiveInputStream(compressedData.getInputStream());
            TarArchiveEntry entry = null;

            Sequence results = new ValueSequence();

            while((entry = tis.getNextTarEntry()) != null)
            {
                Sequence processCompressedEntryResults = processCompressedEntry(entry.getName(), entry.isDirectory(), tis, filterParam, storeParam);

                results.addAll(processCompressedEntryResults);
            }

            return results;
View Full Code Here

    }

    @Override
    protected Object newEntry(String name)
    {
            return new TarArchiveEntry(name);
    }
View Full Code Here

        final File packageDir = temporaryFolder.newFolder();
        ArchiveUtils.extractAr(debFile, packageDir);

        try (final TarArchiveInputStream in = new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(new File(packageDir, "data.tar.gz"))))) {
            final TarArchiveEntry entry = in.getNextTarEntry();
            assertEquals("./test.txt", entry.getName());
            assertEquals(USER, entry.getUserName());
            assertEquals(USER, entry.getGroupName());
            assertEquals(0764, entry.getMode());
        }
    }
View Full Code Here

    File archiveFile = new File(p.toUri().getPath() + ".tar");
    archiveFile.createNewFile();
    TarArchiveOutputStream out = new TarArchiveOutputStream(
        new FileOutputStream(archiveFile));
    TarArchiveEntry entry = new TarArchiveEntry(p.getName());
    entry.setSize(bytes.length);
    out.putArchiveEntry(entry);
    out.write(bytes);
    out.closeArchiveEntry();
    out.close();
View Full Code Here

TOP

Related Classes of org.apache.commons.compress.archivers.tar.TarArchiveEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.