Package com.ice.tar

Examples of com.ice.tar.TarArchive


  {
    File archiveLocation = new File(dir.getParentFile() + File.separator + dir.getName() + ".tar.gz");

    boolean unixArchiveFormat = true;

    TarArchive archive = null;

    OutputStream outStream = System.out;

    if (outStream != null)
    {

      try
      {
        outStream = new GZIPOutputStream(new FileOutputStream(archiveLocation));
      }
      catch (IOException ex)
      {
        outStream = null;
        ex.printStackTrace(System.err);
      }

      archive = new TarArchive(outStream, TarBuffer.DEFAULT_BLKSIZE);
    }

    // write

    File[] files = dir.listFiles();
    for (File file : files)
    {
      if (!file.isDirectory())
      {
        // make regular entry
        TarEntry entry = new TarEntry(file);
        if (unixArchiveFormat)
        {
          entry.setUnixTarFormat();
        }
        else
        {
          entry.setUSTarFormat();
        }
        // FIXME: index -1 wanneer verkeerde file sep!
        entry.setName(entry.getName().substring(entry.getName().lastIndexOf("/") + 1, entry.getName().length()));

        // add to tar. just a file, no need for recursion ('false')
        archive.writeEntry(entry, false);

      }
      else
      {
        // entry is a directory, so tar the content :)
        TarEntry entry = new TarEntry(TarGz.tarDir(file));

        if (unixArchiveFormat)
        {
          entry.setUnixTarFormat();
        }
        else
        {
          entry.setUSTarFormat();
        }
        // FIXME: index -1 wanneer verkeerde file sep!
        entry.setName(entry.getName().substring(entry.getName().lastIndexOf("/") + 1, entry.getName().length()));

        // write entry (now a tar) to tar
        archive.writeEntry(entry, false);
      }
    }

    // close
    if (archive != null) // CLOSE ARCHIVE
    {
      try
      {
        archive.closeArchive();
      }
      catch (IOException ex)
      {
        ex.printStackTrace(System.err);
      }
View Full Code Here


    else
    {
      FileUtils.cleanDirectory(extractDir);
    }

    TarArchive tarchive = null;

    if (inStream != null)
    {
      try
      {
        inStream = new GZIPInputStream(inStream);
      }
      catch (IOException ex)
      {
        inStream = null;
        ex.printStackTrace(System.err);
      }

      tarchive = new TarArchive(inStream, TarBuffer.DEFAULT_BLKSIZE);
    }

    tarchive.extractContents(extractDir);

    for (File tarGzFile : findTarGzFiles(extractDir))
    {
      File subDir = new File(extractDir.getAbsolutePath() + File.separator
          + tarGzFile.getName().replace(".tar.gz", ""));
View Full Code Here

TOP

Related Classes of com.ice.tar.TarArchive

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.