Package java.util.zip

Examples of java.util.zip.ZipInputStream


  UpdateChecker     checker,
  Update        update,
  ResourceDownloader  rd,
  InputStream     data )
  {
  ZipInputStream zip = null;
 
    try {
    data = update.verifyData( data, true );
    
    rd.reportActivity( "Data verified successfully" );
          
      UpdateInstaller installer = checker.createInstaller();
     
      zip = new ZipInputStream(data);
     
      ZipEntry entry = null;
     
      while((entry = zip.getNextEntry()) != null) {
       
        String name = entry.getName();
       
          // all jars
       
        if ( name.endsWith( ".jar" )){
         
          installer.addResource(name,zip,false);
         
          if ( Constants.isOSX ){
           
            installer.addMoveAction(name,installer.getInstallDir() + OSX_APP + "/Contents/Resources/Java/" + name);
           
          }else{
           
            installer.addMoveAction(name,installer.getInstallDir() + File.separator + name);
          }
        }else if ( name.endsWith(".jnilib") && Constants.isOSX ){
         
            //on OS X, any .jnilib
         
          installer.addResource(name,zip,false);
         
          installer.addMoveAction(name,installer.getInstallDir() + OSX_APP + "/Contents/Resources/Java/dll/" + name);
         
        }else if ( name.equals("java_swt")){
         
            //on OS X, java_swt (the launcher to start SWT applications)
            
          installer.addResource(name,zip,false);
         
          installer.addMoveAction(name,installer.getInstallDir() + OSX_APP + "/Contents/MacOS/" + name);
         
          installer.addChangeRightsAction("755",installer.getInstallDir() + OSX_APP + "/Contents/MacOS/" + name);
         
        }else if( name.endsWith( ".dll" ) || name.endsWith( ".so" ) || name.indexOf( ".so." ) != -1 ) {
         
             // native stuff for windows and linux
          
          installer.addResource(name,zip,false);
         
          installer.addMoveAction(name,installer.getInstallDir() + File.separator + name);
 
        }else if ( name.equals("javaw.exe.manifest") || name.equals( "azureus.sig" )){
         
          // silently ignore this one
        }else{
         
         Debug.outNoStack( "SWTUpdate: ignoring zip entry '" + name + "'" );
       }
      }    
     
      update.complete( true );
     
    } catch(Throwable e) {
     
      update.complete( false );
     
      Logger.log(new LogAlert(LogAlert.UNREPEATABLE,
        "SWT Update failed", e));
      return false;
    }finally{
      if ( zip != null ){
       
        try{
            zip.close();
           
        }catch( Throwable e ){
        }
      }
    }
View Full Code Here


        File outDir = new File(outputDirectory);
        if (!outDir.exists()) {
            outDir.mkdirs();
        }

        ZipInputStream in = new ZipInputStream(input);
        ZipEntry z;
        while ((z = in.getNextEntry()) != null) {
            if (z.isDirectory()) {
                String name = z.getName();
                name = name.substring(0, name.length() - 1);
                File f = new File(outputDirectory + File.separator + name);
                f.mkdirs();
                f.setLastModified(z.getTime());
            } else {
                File f = new File(outputDirectory + File.separator + z.getName());
                f.createNewFile();
                DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(f)));
                int b;
                while ((b = in.read()) != -1) out.write(b);
                out.close();
                f.setLastModified(z.getTime());
            }
        }
        in.close();
    }
View Full Code Here

            }
            else
            {
               // Assume this is a jar archive
               InputStream is = new FileInputStream(tmp);
               zis = new ZipInputStream(is);
            }
         }
         else
         {
            // Assume this points to a jar
            InputStream is = url.openStream();
            zis = new ZipInputStream(is);
         }
      }
View Full Code Here

        } catch (MissingResourceException e1) {
          zipName = Installer.resources.getString("packageZip"+i);
        }
        InputStream is = InstallerResources.class.getResourceAsStream(zipName);
        if (is==null) throw new IOException();
        ZipInputStream zip = new ZipInputStream(is);
        ZipEntry entry;
        while ((entry = zip.getNextEntry()) != null) {

          File f = new File(location, entry.getName());
          if (entry.isDirectory()) {
            f.mkdirs(); // TODO: handle installation failed
            continue;
          }
          if (f.exists() && (!overwriteAll)) {
            Object[] options = new Object[] {
              Installer.resources.getString("yes"),
              Installer.resources.getString("yesAll"),
              Installer.resources.getString("no"),
              Installer.resources.getString("cancel"),
            };
            int res = JOptionPane.showOptionDialog(
                installer,
                Installer.resources.getString("overwriteFile")+f.getAbsolutePath(),
                Installer.resources.getString("overwriteTitle"),
                JOptionPane.DEFAULT_OPTION,
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                options[0]);

            if (res==2) continue;
            if ((res==JOptionPane.CLOSED_OPTION) || (res == 3)) break; // TODO: handle installation failed
            if (res==1) overwriteAll = true;
          }
          long size = entry.getSize();
          if (size!=-1) {
            progress.setIndeterminate(false);
            progress.setMinimum(0);     
            progress.setMaximum((int)size);
            progress.setValue(0);
          }
          else progress.setIndeterminate(true);
          progress.setString(f.getAbsolutePath());
          progress.setStringPainted(true);

          FileOutputStream fos = new FileOutputStream(f);
          int nread;
          while ((nread = zip.read(data)) !=-1) {
            fos.write(data,0,nread);
            try {
              SwingUtilities.invokeAndWait(new BarUpdater(nread));
            } catch (InterruptedException e1) {
            } catch (InvocationTargetException e1) {
            }
          }
          fos.flush();
          fos.close();
        }
       
        cb.setBackground(Color.green);
      }
     
      // Extract JRE from installer's ZIP if present => gives feedback
      if (installer.zip!=null) {
        ZipFile zip = new ZipFile(installer.zip);
        ZipEntry entry = zip.getEntry("jre");
       
        // Overkill: entry exists and was checked by the installer main function
        if (entry==null) throw new IOException("Internal Error!");
       
        Enumeration enumEntries = zip.entries();
        while (enumEntries.hasMoreElements()) {
         
          entry = (ZipEntry)enumEntries.nextElement();
          if (!entry.getName().startsWith("jre")) continue;

          File f = new File(location, entry.getName());
          if (entry.isDirectory()) {
            f.mkdirs(); // TODO: handle installation failed
            continue;
          }
          if (f.exists() && (!overwriteAll)) {
            Object[] options = new Object[] {
              Installer.resources.getString("yes"),
              Installer.resources.getString("yesAll"),
              Installer.resources.getString("no"),
              Installer.resources.getString("cancel"),
            };
            int res = JOptionPane.showOptionDialog(
                installer,
                Installer.resources.getString("overwriteFile")+f.getAbsolutePath(),
                Installer.resources.getString("overwriteTitle"),
                JOptionPane.DEFAULT_OPTION,
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                options[0]);

            if (res==2) continue;
            if ((res==JOptionPane.CLOSED_OPTION) || (res == 3)) break; // TODO: handle installation failed
            if (res==1) overwriteAll = true;
          }
          long size = entry.getSize();
          if (size!=-1) {
            progress.setIndeterminate(false);
            progress.setMinimum(0);     
            progress.setMaximum((int)size);
            progress.setValue(0);
          }
          else progress.setIndeterminate(true);
          progress.setString(Installer.resources.getString("installingJRE")+" : "+f.getAbsolutePath());
          progress.setStringPainted(true);

          FileOutputStream fos = new FileOutputStream(f);
          InputStream zipStream = zip.getInputStream(entry);
          int nread;
          while ((nread = zipStream.read(data)) !=-1) {
            fos.write(data,0,nread);
            try {
              SwingUtilities.invokeAndWait(new BarUpdater(nread));
            } catch (InterruptedException e1) {
            } catch (InvocationTargetException e1) {
            }
          }
          fos.flush();
          fos.close();
        }
        zip.close();
      }
     
      // Else copy file by file the JRE directory
      else if (installer.jre!=null) {
        progress.setMinimum(0);     
View Full Code Here

  /**
   * Clear and load all MEMORY tables from latest storage.
   */
  public void load () {
    Connection connection = null;
    ZipInputStream is = null;
    try {
      connection = dataSource.getConnection();
      for (int i=1; i<=20; i++) {
        try {
          IVirtualFile storage = this.storageDirectory.getFile(BackupUtil.getRotatedFileName("backup", "dat", 1));
          if (storage == null) return;
         
          storage.setIOHandler( new EncryptionIOHandler(provider) );
          is = new ZipInputStream(storage.getInputStream());
         
          ZipEntry entry = null;
          BufferedReader reader = new BufferedReader(new InputStreamReader(is));
          while ( (entry = is.getNextEntry()) != null ) {
            EncryptedTable found = null;
            for (EncryptedTable table : getEncryptedTables(connection)) {
              if (entry.getName().equals(table.tableName + ".dat")) { found = table; break; }
            }
            if (found == null) log.warn("Could not find table for entry: " + entry.getName());
            else {
              found.load(connection, reader);
              is.closeEntry();
            }
          }
          is.close();
          return;
        } catch (Exception e) {
          if (is != null) try { is.close(); } catch (IOException ee) {
            ThrowableManagerRegistry.caught(ee);
          }
          log.warn("Backup " + i + " failed.", e);
          BackupUtil.reverseRotation(this.storageDirectory, "backup", "dat", 20);
        }
      }
      throw new RuntimeException("Could not restore encrypted memory tables");
    } catch (SQLException e) {
      throw ThrowableManagerRegistry.caught(e);
    } finally {
      if (connection != null) try { connection.close(); } catch (SQLException e) { ThrowableManagerRegistry.caught(e); }
      if (is != null) try { is.close(); } catch (IOException e) {
        ThrowableManagerRegistry.caught(e);
      }
    }
  }
View Full Code Here

      // Add the zip in a single transaction
      begin();
    }

    try {
      ZipInputStream zipIn = new ZipInputStream(in);

      try {
        for (ZipEntry entry = zipIn.getNextEntry(); entry != null; entry = zipIn.getNextEntry()) {
          if (entry.isDirectory()) {
            continue;
          }

          RDFFormat format = Rio.getParserFormatForFileName(entry.getName(), dataFormat);

          try {
            // Prevent parser (Xerces) from closing the input stream
            FilterInputStream wrapper = new FilterInputStream(zipIn) {

              @Override
              public void close() {
              }
            };
            add(wrapper, baseURI, format, contexts);
          }
          catch (RDFParseException e) {
            String msg = e.getMessage() + " in " + entry.getName();
            RDFParseException pe = new RDFParseException(msg, e.getLineNumber(), e.getColumnNumber());
            pe.initCause(e);
            throw pe;
          }
          finally {
            zipIn.closeEntry();
          }
        }
      }
      finally {
        zipIn.close();
      }

      if (autoCommit) {
        commit();
      }
View Full Code Here

        in = new UncompressInputStream(new FileInputStream(filename));
        copy(in, fout, 100000);
        if (debugCompress) System.out.println("uncompressed " + filename + " to " + uncompressedFile);

      } else if (suffix.equalsIgnoreCase("zip")) {
        in = new ZipInputStream(new FileInputStream(filename));
        copy(in, fout, 100000);
        if (debugCompress) System.out.println("unzipped " + filename + " to " + uncompressedFile);

      } else if (suffix.equalsIgnoreCase("bz2")) {
        in = new CBZip2InputStream(new FileInputStream(filename), true);
View Full Code Here

      s_log.error("Output directory specified (" + outputDirectory.getAbsolutePath()
        + ") doesn't appear to be a directory");
      return;
    }
    FileInputStream fis = null;
    ZipInputStream zis = null;
    FileOutputStream fos = null;
    try
    {
      fis = new FileInputStream(zipFile.getAbsolutePath());
      zis = new ZipInputStream(fis);
      ZipEntry zipEntry = zis.getNextEntry();
      while (zipEntry != null)
      {
        String name = zipEntry.getName();
        if (zipEntry.isDirectory())
        {
          checkDir(outputDirectory, name);
        }
        else
        {
          FileWrapper newFile = _fileWrapperFactory.create(outputDirectory, name);
          if (newFile.exists())
          {
            if (s_log.isInfoEnabled())
            {
              s_log.info("Deleting extraction file that already exists:" + newFile.getAbsolutePath());
            }
            newFile.delete();
          }
          fos = new FileOutputStream(newFile.getAbsolutePath());
          byte[] buffer = new byte[ZIP_EXTRACTION_BUFFER_SIZE];
          int n = 0;
          while ((n = zis.read(buffer, 0, ZIP_EXTRACTION_BUFFER_SIZE)) > -1)
          {
            fos.write(buffer, 0, n);
          }
          fos.close();
        }
        zipEntry = zis.getNextEntry();
      }
    }
    finally
    {
      _iou.closeOutputStream(fos);
View Full Code Here

      }
    };

    File zipFile = corpusFolder.listFiles(filter)[0];
    FileInputStream fis = new FileInputStream(zipFile);
    ZipInputStream zin = new ZipInputStream(new BufferedInputStream(fis));
    ZipEntry entry;
    while ((entry = zin.getNextEntry()) != null) {
      File outputFile = new File(feedFolder, entry.getName());
      outputFile.deleteOnExit();

      FileOutputStream outS = new FileOutputStream(outputFile);
      copy(zin, outS);
View Full Code Here

          }
        }
    }

    private void addLocationsFromJarFile(String path) throws Exception {
        ZipInputStream zin = new ZipInputStream(ctx.getResourceAsStream(path));
        // Make stream uncloseable by XML parsers
        InputStream uin = new FilterInputStream(zin) {
            public void close() {
            }
        };
        try {
            for(;;) {
                ZipEntry ze = zin.getNextEntry();
                if(ze == null) {
                    break;
                }
                String zname = ze.getName();
                if(zname.startsWith("META-INF/") && zname.endsWith(".tld")) {
                    String url = "jar:" +
                        ctx.getResource(path).toExternalForm() +
                        "!" + zname;
                    addLocationFromTldResource(uin, path, zname, url);
                }
            }
        }
        finally {
            zin.close();
        }
    }
View Full Code Here

TOP

Related Classes of java.util.zip.ZipInputStream

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.