Package com.ice.tar

Examples of com.ice.tar.TarInputStream$EntryAdapter


    File dest = new File(destination);
    dest.mkdir();

    //create tar input stream from a .tar.gz file

    TarInputStream tin = new TarInputStream( new GZIPInputStream(new FileInputStream(new File(tarFileName))));

    //get the first entry in the archive

    TarEntry tarEntry = tin.getNextEntry();

    while (tarEntry != null)
    { 
      //create a file with the same name as the tarEntry

      File destPath = new File(destination + File.separatorChar + tarEntry.getName());

      if (tarEntry.isDirectory())
      {
        destPath.mkdir();
      }
      else
      {

        FileOutputStream fout = new FileOutputStream(destPath);

        tin.copyEntryContents(fout);

        fout.close();
      }
      tarEntry = tin.getNextEntry();
    }
    tin.close();
  }
View Full Code Here


    // now extract the tar files
    StringBuilder sb = new StringBuilder();
    FileInputStream fileStream = new FileInputStream( file );
    try {
      // create a zip input stream from the tmp file that was uploaded
      TarInputStream zipStream = new TarInputStream( new BufferedInputStream( fileStream ) );
      try {
        TarEntry entry = zipStream.getNextEntry();
        // iterate thru the entries in the zip file
        while ( entry != null ) {
          // ignore hidden directories and files, extract the rest
          if ( !entry.isDirectory() && !entry.getName().startsWith( "." ) && !entry.getName().startsWith( "__MACOSX/" ) ) { //$NON-NLS-1$ //$NON-NLS-2$
            File entryFile = null;
            if ( isTemporary() ) {
              String extension = ".tmp"; //$NON-NLS-1$
              int idx = entry.getName().lastIndexOf( '.' );
              if ( idx != -1 ) {
                extension = entry.getName().substring( idx ) + extension;
              }
              entryFile = PentahoSystem.getApplicationContext().createTempFile( session, "", extension, true ); //$NON-NLS-1$
            } else {
              entryFile = new File( getPath() + File.separatorChar + entry.getName() );
            }

            if ( sb.length() > 0 ) {
              sb.append( "\n" ); //$NON-NLS-1$
            }
            sb.append( entryFile.getName() );
            FileOutputStream entryOutputStream = new FileOutputStream( entryFile );
            try {
              IOUtils.copy( zipStream, entryOutputStream );
            } finally {
              IOUtils.closeQuietly( entryOutputStream );
            }
          }
          // go on to the next entry
          entry = zipStream.getNextEntry();
        }
      } finally {
        IOUtils.closeQuietly( zipStream );
      }
View Full Code Here

      }
    }
    protected void extractAndIndexTarFile(InputStream is, Document doc, TempFiles tempFiles, Charset charset ) {
      logger.debug("extractAndIndexTarFile()");
      try {
        TarInputStream gis = new TarInputStream(is);
        TarEntry entry;
        while((entry = gis.getNextEntry()) != null) {
                 String name = entry.getName();
                 int dot = name.lastIndexOf('.');
                 if (dot==-1) continue;
                 String extention = name.substring(dot+1,name.length());
                 Reader textReader = Extractor.getText(gis,extention,tempFiles,charset);
View Full Code Here

     * @return The number of entries extracted.
     */
    private int unZapTarFile(File fileToUnzap, String fileToUnzapLowerCase) {

        InputStream is  = null;
        TarInputStream tis = null;
        TarEntry tarEntry = null;
        boolean entryFound = false;
        boolean nonDirectoryEntryFound = false;
        int numberEntriesExtracted = 0;
        try {
            is  = new FileInputStream(fileToUnzap);

            // If the tar file ends with a Gzip extension, use the GZIP filter.
            if ( fileToUnzapLowerCase.endsWith(this.tarGzipExtension) ||
                 fileToUnzapLowerCase.endsWith(this.tarGzipExtensionAlt1) ||
                 fileToUnzapLowerCase.endsWith(this.tarGzipExtensionAlt2) ) {
                is = new GZIPInputStream(is);
            }

            tis = new TarInputStream(is);
            String fileName = null;

            // Loop through all the tar entries.
            tarEntry = tis.getNextEntry();
            while (tarEntry != null) {

                entryFound = true;

                // Skip over directories
                if (!tarEntry.isDirectory()) {

                    nonDirectoryEntryFound = true;

                    // Should this file be should extracted?
                    if (this.nameSelector.isIncluded(tarEntry.getName())) {

                        fileName = makeOutputFileName(tarEntry.getName(), fileToUnzap.getName());

                        writeNextTarEntry(tis,
                                new File(this.destLocationFile, fileName));

                        numberEntriesExtracted++;
                    }
                }
                tarEntry = tis.getNextEntry();
            }

            // If no entries extracted, log message.
            if (numberEntriesExtracted == 0) {
                msgEntry.setAppContext("unZapTarFile()");
View Full Code Here

      }
    }
    protected void extractAndIndexTarFile(InputStream is, Document doc, TempFiles tempFiles ) {
      logger.debug("extractAndIndexTarFile()");
      try {
        TarInputStream gis = new TarInputStream(is);
        TarEntry entry;
        while((entry = gis.getNextEntry()) != null) {
                 String name = entry.getName();
                 int dot = name.lastIndexOf('.');
                 if (dot==-1) continue;
                 String extention = name.substring(dot+1,name.length());
                 try {
View Full Code Here

   *             Signals that an I/O exception has occurred.
   */
  private static void untar( String filename, String outputDirectory ) throws IOException
  {
    System.out.println( "Reading TarInputStream... (using classes from http://www.trustice.com/java/tar/)" );
    TarInputStream tin = new TarInputStream( getInputStream( filename ) );
    TarEntry tarEntry = tin.getNextEntry();
//    if( new File( outputDirectory ).exists() )
//    {
      while( tarEntry != null )
      {
        File destPath = new File( outputDirectory + File.separator + tarEntry.getName() );
        System.out.println( "Processing " + destPath.getAbsoluteFile() );
        if( !tarEntry.isDirectory() )
        {
          FileOutputStream fout = new FileOutputStream( destPath );
          tin.copyEntryContents( fout );
          fout.close();
        }
        else
        {
          destPath.mkdirs();
        }
        tarEntry = tin.getNextEntry();
      }
      tin.close();
//    }
//    else
//    {
//      System.out.println( "That destination directory doesn't exist! " + outputDirectory );
//    }
View Full Code Here

TOP

Related Classes of com.ice.tar.TarInputStream$EntryAdapter

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.