Examples of TarInputStream


Examples of org.apache.tools.tar.TarInputStream

  private static File uncompress(File compressedFile, File targetDirectory) {
    File targetDir = null;
    if( compressedFile.getName().endsWith(".tar.gz") ) {
      try {
        TarInputStream in = new TarInputStream(new GZIPInputStream(new FileInputStream(compressedFile)));
        TarEntry e;
        while( (e = in.getNextEntry()) != null ) {
          if( e.isDirectory() ) {
            File f = new File(targetDirectory,e.getName());
            f.mkdirs();
            if( targetDir == null ) {
              targetDir = f;
            }
          } else {
            File f = new File(targetDirectory,e.getName());
            if( ! f.getParentFile().exists() ) {
              f.getParentFile().mkdirs();
            }
            in.copyEntryContents(new FileOutputStream(f));
           
            int m = e.getMode();
            if( (m & OWNER_EXEC) == OWNER_EXEC
                || (m & GROUP_EXEC) == GROUP_EXEC
                || (m & OTHER_EXEC) == OTHER_EXEC ) {
              f.setExecutable(true, false);
            } else if( e.getLinkName() != null && e.getLinkName().trim().length() > 0 ) {
              //TODO Handle symlinks
//              System.err.println("A LINK: " + e.getLinkName());
            }
          }
        }
        in.close();
       
        if( targetDir == null ) {
          targetDir = new File(targetDirectory,"eclipse");
        }
      } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
    } else if( compressedFile.getName().endsWith(".zip") ) {
      try {
        ZipInputStream in = new ZipInputStream(new FileInputStream(compressedFile));
        ZipEntry e;
        while( (e = in.getNextEntry()) != null ) {
          if( e.isDirectory() ) {
            File f = new File(targetDirectory,e.getName());
            f.mkdirs();
            if( targetDir == null ) {
              targetDir = f;
            }
          } else {
            File f = new File(targetDirectory,e.getName());
            if( ! f.getParentFile().exists() ) {
              f.getParentFile().mkdirs();
            }
            FileOutputStream out = new FileOutputStream(f);
            byte[] buf = new byte[1024];
            int l;
            while( (l = in.read(buf, 0, 1024)) != -1 ) {
              out.write(buf,0,l);
            }
            out.close();
          }
          in.closeEntry();
        }
        in.close();
       
        if( targetDir == null ) {
          targetDir = new File(targetDirectory,"eclipse");
        }
      } catch (FileNotFoundException e) {
View Full Code Here

Examples of org.apache.tools.tar.TarInputStream

    public void setCompression(UntarCompressionMethod method) {
        compression = method;
    }

    protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
        TarInputStream tis = null;
        try {
            log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO);
            tis = new TarInputStream(
                compression.decompress(srcF,
                    new BufferedInputStream(
                        new FileInputStream(srcF))));
            TarEntry te = null;

            while ((te = tis.getNextEntry()) != null) {
                extractFile(fileUtils, srcF, dir, tis,
                            te.getName(), te.getModTime(), te.isDirectory());
            }
            log("expand complete", Project.MSG_VERBOSE);

        } catch (IOException ioe) {
            throw new BuildException("Error while expanding " + srcF.getPath(),
                                     ioe, location);
        } finally {
            if (tis != null) {
                try {
                    tis.close();
                } catch (IOException e) {}
            }
        }
    }
View Full Code Here

Examples of org.apache.tools.tar.TarInputStream

                                 + " task doesn't support the encoding"
                                 + " attribute", getLocation());
    }

    protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
        TarInputStream tis = null;
        try {
            log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO);
            tis = new TarInputStream(
                compression.decompress(srcF,
                    new BufferedInputStream(
                        new FileInputStream(srcF))));
            TarEntry te = null;

            while ((te = tis.getNextEntry()) != null) {
                extractFile(fileUtils, srcF, dir, tis,
                            te.getName(), te.getModTime(), te.isDirectory());
            }
            log("expand complete", Project.MSG_VERBOSE);

        } catch (IOException ioe) {
            throw new BuildException("Error while expanding " + srcF.getPath(),
                                     ioe, getLocation());
        } finally {
            if (tis != null) {
                try {
                    tis.close();
                } catch (IOException e) {
                    // ignore
                }
            }
        }
View Full Code Here

Examples of org.apache.tools.tar.TarInputStream

   * @throws Exception (IOException or FileNotFoundException)
   */
  public static void unTar(final InputStream in, final String untarDir) throws Exception{
    Log.logInfo("UNTAR", "starting");
    if(new File(untarDir).exists()){
      final TarInputStream tin = new TarInputStream(in);
      TarEntry tarEntry = tin.getNextEntry();
      while(tarEntry != null){
        final File destPath = new File(untarDir + File.separator + tarEntry.getName());
        if (!tarEntry.isDirectory()) {
          new File(destPath.getParent()).mkdirs(); // create missing subdirectories
          final FileOutputStream fout = new FileOutputStream(destPath);
          tin.copyEntryContents(fout);
          fout.close();
        } else {
          destPath.mkdir();
        }
        tarEntry = tin.getNextEntry();
      }
      tin.close();
    } else { // untarDir doesn't exist
      Log.logWarning("UNTAR", "destination " + untarDir + " doesn't exist.");
    }
    Log.logInfo("UNTAR", "finished");
  }
View Full Code Here

Examples of org.apache.tools.tar.TarInputStream

            } catch (final IOException e) {
                throw new Parser.Failure("tar parser: " + e.getMessage(), url);
            }
        }
        TarEntry entry;
        final TarInputStream tis = new TarInputStream(source);
        File tmp = null;

        // loop through the elements in the tar file and parse every single file inside
        while (true) {
            try {
                if (tis.available() <= 0) break;
                entry = tis.getNextEntry();
                if (entry == null) break;
                if (entry.isDirectory() || entry.getSize() <= 0) continue;
                final String name = entry.getName();
                final int idx = name.lastIndexOf('.');
                final String mime = TextParser.mimeOf((idx > -1) ? name.substring(idx+1) : "");
View Full Code Here

Examples of org.apache.tools.tar.TarInputStream

     * @param path
     * @param fileName
     */
    private void untar ( InputStream bundle, String path, String fileName ) {
        TarEntry entry;
        TarInputStream inputStream = null;
        FileOutputStream outputStream = null;

        try {
          //Clean the bundler folder if exist to clean dirty data
          String previousFolderPath = path.replace(fileName, "");
          File previousFolder = new File(previousFolderPath);
          if(previousFolder.exists()){
            FileUtils.cleanDirectory(previousFolder);
          }
            // get a stream to tar file
            InputStream gstream = new GZIPInputStream( bundle );
            inputStream = new TarInputStream( gstream );

            // For each entry in the tar, extract and save the entry to the file
            // system
            while ( null != (entry = inputStream.getNextEntry()) ) {
                // for each entry to be extracted
                int bytesRead;

                String pathWithoutName = path.substring( 0,
                        path.indexOf( fileName ) );

                // if the entry is a directory, create the directory
                if ( entry.isDirectory() ) {
                    File fileOrDir = new File( pathWithoutName + entry.getName() );
                    fileOrDir.mkdir();
                    continue;
                }

                // write to file
                byte[] buf = new byte[1024];
                outputStream = new FileOutputStream( pathWithoutName
                        + entry.getName() );
                while ( (bytesRead = inputStream.read( buf, 0, 1024 )) > -1 )
                    outputStream.write( buf, 0, bytesRead );
                try {
                    if ( null != outputStream ) {
                        outputStream.close();
                    }
                } catch ( Exception e ) {
                    Logger.warn( this.getClass(), "Error Closing Stream.", e );
                }
            }// while

        } catch ( Exception e ) {
            e.printStackTrace();
        } finally { // close your streams
            if ( inputStream != null ) {
                try {
                    inputStream.close();
                } catch ( IOException e ) {
                    Logger.warn( this.getClass(), "Error Closing Stream.", e );
                }
            }
            if ( outputStream != null ) {
View Full Code Here

Examples of org.apache.tools.tar.TarInputStream

    @Override
    public void analyze(Document doc, InputStream in) throws IOException {
        content.setLength(0);

        TarInputStream zis = new TarInputStream(in);
        TarEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            content.append(entry.getName()).append('\n');
        }
        content.trimToSize();
        doc.add(new Field("full", dummy));
    }
View Full Code Here

Examples of org.apache.tools.tar.TarInputStream

                    found.set(true);

                    assertEquals("header 0", (byte) 'B', content[0]);
                    assertEquals("header 1", (byte) 'Z', content[1]);

                    TarInputStream tar = new TarInputStream(new BZip2CompressorInputStream(new ByteArrayInputStream(content)));
                    while ((tar.getNextEntry()) != null) ;
                    tar.close();
                }
            }
        });
       
        assertTrue("bz2 file not found", found.get());
View Full Code Here

Examples of org.codehaus.plexus.archiver.tar.TarInputStream

    private TarUtil() {
    }

    public static void untar(File source, File target, Log logger) {
        TarInputStream tarInput = null;
        TarEntry entry;
        OutputStream output = null;

        try {
            tarInput = new TarInputStream(new FileInputStream(source));

            entry = tarInput.getNextEntry();
            while (entry != null) {
                File outputFile = new File(target.getCanonicalPath() + File.separator + entry.getName());
                if (entry.isDirectory()) {
                    logger.debug("creating dir at: " + outputFile.getCanonicalPath());
                    outputFile.mkdirs();
                } else {
                    logger.debug("creating file at: " + outputFile.getCanonicalPath());
                    output = new FileOutputStream(outputFile);
                    IOUtils.copy(tarInput, output);
                    output.flush();
                    output.close();
                }

                entry = tarInput.getNextEntry();
            }
        } catch (IOException exception) {
            throw new IllegalStateException(exception);
        } finally {
            IOUtils.closeQuietly(tarInput);
View Full Code Here

Examples of org.eclipse.equinox.internal.p2.core.helpers.TarInputStream

    int fileCnt = getFileCount();
    SubMonitor progress = SubMonitor.convert(monitor, (fileCnt > 0) ? fileCnt : 500);
    String archivePath = getArchivePath();
    BufferedInputStream bin = new BufferedInputStream(in);
    try {
      TarInputStream zin = new TarInputStream(bin);
      TarEntry entry = zin.getNextEntry();
      while (entry != null) {
        String name = entry.getName();
        progress.subTask(NLS.bind(Messages.InstallableRuntime2_TaskUncompressing, name));
        if (archivePath != null && name.startsWith(archivePath)) {
          name = name.substring(archivePath.length());
          if (name.length() > 1)
            name = name.substring(1);
        }
       
        if (name != null && name.length() > 0) {
          if (entry.getFileType() == TarEntry.DIRECTORY)
            path.append(name).toFile().mkdirs();
          else {
            File dir = path.append(name).removeLastSegments(1).toFile();
            if (!dir.exists())
              dir.mkdirs();
           
            FileOutputStream fout = new FileOutputStream(path.append(name).toFile());
            copyWithSize(zin, fout, progress.newChild(1), (int)entry.getSize());
            fout.close();
            if (fileCnt <= 0)
              progress.setWorkRemaining(500);
          }
        }
        entry = zin.getNextEntry();
      }
      zin.close();
    } catch (TarException ex) {
      throw new IOException(ex);
    }
  }
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.