Examples of TarInputStream


Examples of com.ice.tar.TarInputStream

    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

Examples of com.ice.tar.TarInputStream

    // 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

Examples of com.ice.tar.TarInputStream

      }
    }
    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

Examples of com.ice.tar.TarInputStream

     * @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

Examples of com.ice.tar.TarInputStream

      }
    }
    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

Examples of com.ice.tar.TarInputStream

   *             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

Examples of hudson.org.apache.tools.tar.TarInputStream

    /**
     * Reads from a tar stream and stores obtained files to the base dir.
     */
    private static void readFromTar(String name, File baseDir, InputStream in) throws IOException {
        TarInputStream t = new TarInputStream(in);
        try {
            TarEntry te;
            while ((te = t.getNextEntry()) != null) {
                File f = new File(baseDir,te.getName());
                if(te.isDirectory()) {
                    f.mkdirs();
                } else {
                    File parent = f.getParentFile();
                    if (parent != null) parent.mkdirs();

                    byte linkFlag = (Byte) LINKFLAG_FIELD.get(te);
                    if (linkFlag==TarEntry.LF_SYMLINK) {
                        new FilePath(f).symlinkTo(te.getLinkName(), TaskListener.NULL);
                    } else {
                        IOUtils.copy(t,f);

                        f.setLastModified(te.getModTime().getTime());
                        int mode = te.getMode()&0777;
                        if(mode!=0 && !Functions.isWindows()) // be defensive
                            _chmod(f,mode);
                    }
                }
            }
        } catch(IOException e) {
            throw new IOException2("Failed to extract "+name,e);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt(); // process this later
            throw new IOException2("Failed to extract "+name,e);
        } catch (IllegalAccessException e) {
            throw new IOException2("Failed to extract "+name,e);
        } finally {
            t.close();
        }
    }
View Full Code Here

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

            {
                throw new FileSystemException("vfs.provider.tar/close-tar-file.error", file, e);
            }
            tarFile = null;
        }
        TarInputStream tarFile = createTarFile(this.file);
        this.tarFile = tarFile;
    }
View Full Code Here

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

    {
        try
        {
            if ("tgz".equalsIgnoreCase(getRootName().getScheme()))
            {
                return new TarInputStream(new GZIPInputStream(new FileInputStream(file)));
            }
            else if ("tbz2".equalsIgnoreCase(getRootName().getScheme()))
            {
                return new TarInputStream(Bzip2FileObject.wrapInputStream(file.getAbsolutePath(), new FileInputStream(file)));
            }
            return new TarInputStream(new FileInputStream(file));
        }
        catch (IOException ioe)
        {
            throw new FileSystemException("vfs.provider.tar/open-tar-file.error", file, ioe);
        }
View Full Code Here

Examples of org.apache.tika.parser.pkg.tar.TarInputStream

        XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
        xhtml.startDocument();

        // At the end we want to close the tar stream to release any associated
        // resources, but the underlying document stream should not be closed
        TarInputStream tar =
            new TarInputStream(new CloseShieldInputStream(stream));
        try {
            TarEntry entry = tar.getNextEntry();
            while (entry != null) {
                if (!entry.isDirectory()) {
                    Metadata entrydata = new Metadata();
                    entrydata.set(Metadata.RESOURCE_NAME_KEY, entry.getName());
                    parseEntry(tar, xhtml, entrydata);
                }
                entry = tar.getNextEntry();
            }
        } finally {
            tar.close();
        }

        xhtml.endDocument();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.