Package java.util.zip

Examples of java.util.zip.ZipInputStream


      BufferedOutputStream bos =
        new BufferedOutputStream(new FileOutputStream(tempF));
      bos.write(zip);
      bos.close();*/
     
      ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(zip));
      ZipEntry ze;
      final byte[] buff = new byte[1024];
      while ((ze = zis.getNextEntry()) != null) {
//        System.out.println("Cache: inflating " + ze.getName());
        if (ze.isDirectory()) {
          new File(cacheDir, ze.getName()).mkdir();
          continue;
        }
        BufferedOutputStream bo =
          new BufferedOutputStream(new FileOutputStream(new File(cacheDir, ze.getName())));
        while (true) {
          int amountRead = zis.read(buff);
          if (amountRead == -1) {
            break;
          }
          // write the data here
          bo.write(buff, 0, amountRead);
View Full Code Here


      } catch (IOException ex2) {
        return null;
      }
     
      // If content couldn't be loaded, try to load model as a zipped file
      ZipInputStream zipIn = null;
      try {
        URLContent urlContent = (URLContent)modelContent;
        // Open zipped stream
        zipIn = new ZipInputStream(urlContent.openStream());
        // Parse entries to see if a obj file is readable
        for (ZipEntry entry; (entry = zipIn.getNextEntry()) != null; ) {
          try {
            String entryName = entry.getName();
            // Ignore directory entries and entries starting by a dot
            if (!entryName.endsWith("/")) {
              int slashIndex = entryName.lastIndexOf('/');
              String entryFileName = entryName.substring(slashIndex + 1);
              if (!entryFileName.startsWith(".")) {
                int dotIndex = entryFileName.lastIndexOf(".");
                if (dotIndex != -1) {
                  modelName = entryFileName.substring(0, dotIndex);
                } else {
                  modelName = entryFileName;
                }
                URL entryUrl = new URL("jar:" + urlContent.getURL() + "!/"
                    + URLEncoder.encode(entryName, "UTF-8").replace("+", "%20").replace("%2F", "/"));
                modelContent = new TemporaryURLContent(entryUrl);
                model = ModelManager.getInstance().loadModel(modelContent);
                if (!entryFileName.toLowerCase().endsWith(".obj")
                    && (this.preferences.isModelContentAlwaysConvertedToOBJFormat()
                        || slashIndex > 0)) {
                  // Convert models in subdirectories at format different from OBJ
                  modelContent = copyToTemporaryOBJContent(model, modelContent);
                }
                break;
              }
            }
          } catch (IOException ex2) {
            // Ignore exception and try next entry
          }
        }
        if (model == null) {
          return null;
        }
      } catch (IOException ex2) {
        return null;
      } finally {
        try {
          if (zipIn != null) {
            zipIn.close();
          }
        } catch (IOException ex2) {
          // Ignore close exception
        }
      }
View Full Code Here

    UpdateChecker    checker,
    InputStream      data )
 
    throws Exception
  {
    ZipInputStream zip = null;
   
    Properties  update_properties = new Properties();
   
    File    temp_dir = AETemporaryFileHandler.createTempDir();
   
    File    update_file = null;
   
    try{
      zip = new ZipInputStream(data);

      ZipEntry entry = null;

      while((entry = zip.getNextEntry()) != null) {

        String name = entry.getName().trim();

        if ( name.equals( "azureus.sig" ) || name.endsWith( "/" ) || name.length() == 0 ){
         
          continue;
        }

        if ( name.equals( "update.properties" )){
         
          update_properties.load( zip );
         
        }else{
         
          if ( update_file != null ){
           
            throw( new Exception( "Multiple update files are not supported" ));
          }
         
          update_file = new File( temp_dir, name );
         
          FileUtil.copyFile( zip, update_file, false );
        }
      }
    }finally{
     
      if ( zip != null ){
       
        try{
          zip.close();
         
        }catch( Throwable e ){
         
        }
      }
View Full Code Here

      }else{
          // osx, need to unzip .app and launch
       
        File  dir = file.getParentFile();
       
           ZipInputStream  zis = new ZipInputStream( new BufferedInputStream( new FileInputStream( file )));
           
           Throwable unzip_error = null;
          
           String chmod_command = findCommand( "chmod" );
          
          try{
          while( true ){
                       
            ZipEntry  entry = zis.getNextEntry();
             
            if ( entry == null ){
             
              break;
            }
           
            if ( entry.isDirectory()){
             
              continue;
            }
           
            String  name = entry.getName();
           
            FileOutputStream  entry_os   = null;
            File        entry_file   = null;
           
            if ( !name.endsWith("/")){
                           
              entry_file = new File( dir, name.replace('/', File.separatorChar ));
                           
              entry_file.getParentFile().mkdirs();
             
              entry_os  = new FileOutputStream( entry_file );
            }
           
            try{
              byte[]  buffer = new byte[65536];
             
              while( true ){
             
                int  len = zis.read( buffer );
               
                if ( len <= 0 ){
                 
                  break;
                }
                                                 
                if ( entry_os != null ){
                 
                  entry_os.write( buffer, 0, len );
                }
              }
            }finally{
             
              if ( entry_os != null ){
               
                entry_os.close();
                                 
                if ( name.endsWith( ".jnilib" ) || name.endsWith( "JavaApplicationStub" )){
                   
                  try{
                    String[] to_run = { chmod_command, "a+x", entry_file.getAbsolutePath() };
                     
                    runCommand( to_run, true );
                       
                  }catch( Throwable e ){
                   
                    unzip_error = e;
                  }
                }
              }
            }
          }
          }finally{
           
            zis.close();
          }
       
          if ( unzip_error != null ){
           
            throw( unzip_error );
View Full Code Here

   * Returns the ZIP entries in <code>zipUrl</code>.
   */
  private List<ZipEntry> getZipEntries(URL zipUrl) throws IOException {
    List<ZipEntry> entries;
    // Get zipped stream entries
    ZipInputStream zipIn = null;
    try {
      entries = new ArrayList<ZipEntry>();
      zipIn = new ZipInputStream(zipUrl.openStream());
      for (ZipEntry entry; (entry = zipIn.getNextEntry()) != null; ) {
        entries.add(entry);
      }
      return entries;
    } finally {
      if (zipIn != null) {
        zipIn.close();
      }
    }
  }
View Full Code Here

    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();

        if (name.toLowerCase().startsWith("windows/")) {

          // win32 only files

          name = name.substring(8);

          // skip the directory entry

          if (name.length() > 0) {

            rd.reportActivity("Adding update action for '" + name + "'");

            if (Logger.isEnabled())
              Logger.log(new LogEvent(LOGID,
                  "PlatformManager:Win32 adding action for '" + name + "'"));

            installer.addResource(name, zip, false);

            installer.addMoveAction(name, installer.getInstallDir()
                + File.separator + name);
          }
        }
      }
     
      update.complete( true );
     
    } catch (Throwable e) {

      update.complete( false );
     
      rd.reportActivity("Update install failed:" + e.getMessage());
     
    }finally{
     
      if ( zip != null ){
       
        try{
          zip.close();
         
        }catch( Throwable e ){
        }
      }
    }
View Full Code Here

          // See if we can get at the plugin.properties in the file
       
        Properties  properties  = null;
       
        ZipInputStream  zis = null;
       
        try{
          zis =
            new ZipInputStream(
                new BufferedInputStream( new FileInputStream( file ) ));
         
         
            while( properties == null ){
             
              ZipEntry  entry = zis.getNextEntry();
               
              if ( entry == null ){
               
                break;
              }
           
              String  zip_name = entry.getName().toLowerCase( MessageText.LOCALE_ENGLISH );
           
              // System.out.println( "zis1:" + zip_name );
             
              if ( zip_name.equals( "plugin.properties" ) || zip_name.endsWith( "/plugin.properties")){
               
                properties  = new Properties();
               
                properties.load( zis );
                               
              }else if ( zip_name.endsWith( ".jar" )){
               
                ZipInputStream  zis2 = new ZipInputStream( zis );
               
                while( properties == null ){
                 
                  ZipEntry  entry2 = zis2.getNextEntry();
                   
                  if ( entry2 == null ){
                   
                    break;
                  }
View Full Code Here

    File      file,
    RSAPublicKey  key )
 
    throws AEVerifierException, Exception
  {
    ZipInputStream  zis = null;
   
    try{
      zis = new ZipInputStream(
          new BufferedInputStream( new FileInputStream( file ) ));
       
      byte[]    signature  = null;
     
      Signature  sig = Signature.getInstance("MD5withRSA" );

      sig.initVerify( key );
     
      while( true ){
       
        ZipEntry  entry = zis.getNextEntry();
         
        if ( entry == null ){
         
          break;
        }
     
        if ( entry.isDirectory()){
         
          continue;
        }
       
        String  name = entry.getName();
     
        ByteArrayOutputStream  output = null;
       
        if ( name.equalsIgnoreCase("azureus.sig")){
         
          output  = new ByteArrayOutputStream();
        }
                       
        byte[]  buffer = new byte[65536];
       
        while( true ){
       
          int  len = zis.read( buffer );
         
          if ( len <= 0 ){
           
            break;
          }
         
          if ( output == null ){
           
            sig.update( buffer, 0, len );
           
          }else{
           
            output.write( buffer, 0, len );
          }
        }
       
        if ( output != null ){
         
          signature = output.toByteArray();
        }
      }
           
      if ( signature == null ){
               
        throw( new AEVerifierException( AEVerifierException.FT_SIGNATURE_MISSING, "Signature missing from file" ));
      }
     
      if ( !sig.verify( signature )){
       
        throw( new AEVerifierException( AEVerifierException.FT_SIGNATURE_BAD, "Signature doesn't match data" ));
      }
    }finally{
     
      if ( zis != null ){
       
        zis.close();
      }
    }
  }
View Full Code Here

          filtersFile = FileUtil.getUserFile("ipfilter.ext");
          FileUtil.copyFile(gzip, filtersFile);
          fin = new FileInputStream(filtersFile);
          bin = new BufferedInputStream(fin, 16384);
        } else if (headerBytes[0] == 0x50 && headerBytes[1] == 0x4b) {
          ZipInputStream zip = new ZipInputStream(bin);

          ZipEntry zipEntry = zip.getNextEntry();
          // Skip small files
          while (zipEntry != null && zipEntry.getSize() < 1024 * 1024) {
            zipEntry = zip.getNextEntry();
          }

          if (zipEntry == null) {
            return;
          }
View Full Code Here

    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();

        if (name.toLowerCase().startsWith("osx/")) {

          // OSX only files

          name = name.substring(4);

          // skip the directory entry

          if ( name.length() > 0 ){

            rd.reportActivity("Adding update action for '" + name + "'");

            if (Logger.isEnabled())
              Logger.log(new LogEvent(LOGID,
                  "PlatformManager:OSX adding action for '" + name + "'"));

              // handle sub-dirs
           
            String  resource_name = name.replaceAll( "/", "-" );
           
            installer.addResource( resource_name, zip, false );

            String target =
              installer.getInstallDir() +
              File.separator + SystemProperties.getApplicationName() + ".app" +
              File.separator + name;

            installer.addMoveAction( resource_name, target );
           
            if ( name.endsWith( ".jnilib" ) || name.endsWith( "JavaApplicationStub" )){
             
              installer.addChangeRightsAction( "755", target );
            }
          }
        }
      }
     
      update.complete( true );
     
    } catch (Throwable e) {

      update.complete( false );
     
      rd.reportActivity("Update install failed:" + e.getMessage());
     
    }finally{
     
      if ( zip != null ){
       
        try{
          zip.close();
         
        }catch( Throwable e ){
        }
      }
    }
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.