Package java.util.zip

Examples of java.util.zip.ZipFile$MyEnumeration


  protected ZipFile archive()
    throws Exception
  {
    if ( this.getZipFile() == null )
    {
      this.setZipFile( new ZipFile( this.fileRef() ) ) ;
    }
    return this.getZipFile() ;
  } // archive()
View Full Code Here


 
  @SuppressWarnings("unchecked")
  public static final void unzip(File file, File targetDir) throws ZipException, IOException {
      Enumeration entries = null;
      ZipFile zipFile = null;
      try {
        zipFile = new ZipFile(file);
       
        entries = zipFile.entries();

        while(entries.hasMoreElements()) {
          ZipEntry entry = (ZipEntry)entries.nextElement();
          if(entry.isDirectory()) {
            (new File(targetDir, entry.getName())).mkdir();
            continue;
          }
          InputStream in = zipFile.getInputStream(entry);
          OutputStream out = new FileOutputStream(new File(targetDir, entry.getName()));   
          try {
            WGUtils.inToOut(in, out, 2048);
          } finally {
            out.close();
            in.close();
          }
        }
        zipFile.close();
    } finally {
        if (zipFile != null) {
          try {
            zipFile.close();
          } catch (IOException e) {           
          }
        }
      }
    }
View Full Code Here

    else if (verbose)
      System.out.println("create ra.properties " + rarName);

    File file = new File(rarName);
    if (file.exists()) {
      ZipFile zipFile = new ZipFile(file.getAbsolutePath());
      for (Enumeration zippedFiles = zipFile.entries(); zippedFiles.hasMoreElements(); ) {
        //Retrieve entry of existing files
        ZipEntry currEntry = (ZipEntry) zippedFiles.nextElement();
        if (debug)
          System.out.println("RAConfig.createRaProperties : currEntry = " + currEntry);
        if (currEntry.getName().equalsIgnoreCase(RA_XML)) {
          InputStream reader = zipFile.getInputStream(currEntry);
          StringBuffer buff = new StringBuffer();
          buff.append("RAR_NAME  ");
          buff.append(file.getAbsolutePath());
          buff.append("\n");
          //parse ra.xml file
          buff.append(parse(reader));
          // create ra.properties file
          createFile(RA_PROPERTIES,buff.toString());
          break;
        }
      }
      zipFile.close();
    }
  }
View Full Code Here

      System.out.println("extract \"" + fileName + "\" from \"" + rarName + "\"");

    InputStream res = null;
    File file = new File(rarName);
    if (file.exists()) {
      ZipFile zipFile = new ZipFile(file.getAbsolutePath());
      for (Enumeration zippedFiles = zipFile.entries(); zippedFiles.hasMoreElements(); ) {
        //Retrieve entry of existing files
        ZipEntry currEntry = (ZipEntry) zippedFiles.nextElement();
        if (debug)
          System.out.println("RAConfig.extractFromRAR : currEntry = " + currEntry);
        if (currEntry.getName().equalsIgnoreCase(fileName)
            || currEntry.getName().equalsIgnoreCase("META-INF/"+fileName)) {
          // the fileName is found.
          res =  zipFile.getInputStream(currEntry);
          break;
        } else if (currEntry.getName().endsWith(".jar")) {
          // search fileName in jar file.
          InputStream reader = zipFile.getInputStream(currEntry);
          res = extractFromJAR(fileName,reader);
          if (res == null) continue;
         
          // the fileName found in jar file.
          reader.close();
          break;
        }
      }
      // extract the fileName from InputStream
      // in the tmp directory.
      if (res != null)
        createFile(fileName,res);
      zipFile.close();
    }
  }
View Full Code Here

      System.out.println("RAConfig.updateRAR : map = " + map);

    // create ra.xml file with new values
    File rarFile = new File(rarName);
    if (rarFile.exists()) {
      ZipFile zipFile = new ZipFile(rarFile.getAbsolutePath());
      for (Enumeration zippedFiles = zipFile.entries(); zippedFiles.hasMoreElements(); ) {
        // Retrieve entry of existing files
        ZipEntry currEntry = (ZipEntry) zippedFiles.nextElement();
        if (debug)
          System.out.println("RAConfig.updateRAR : currEntry = " + currEntry);
        if (currEntry.getName().equalsIgnoreCase(RA_XML)) {
          InputStream reader = zipFile.getInputStream(currEntry);
          createFile("ra.xml",update(reader,map));
          reader.close();
          break;
        }
      }
      zipFile.close();
    }

    // update rar
    updateZIP(rarName,RA_XML, tmpDir + "ra.xml",RA_XML);
View Full Code Here

    ZipEntry entry = null;

    File file = new File(zipName);
    if (file.exists()) {
      ZipFile zipFile = new ZipFile(file.getAbsolutePath());
      Enumeration zipEntries = zipFile.entries();
      // create your output zip file
      ZipOutputStream newZip = new ZipOutputStream(
        new FileOutputStream(new File(file.getAbsolutePath() + "_TMP")));

      // Get all data (except the oldFileName) from zip file and
      // write it to the tmp zip file
      while (zipEntries.hasMoreElements()) {
        entry = (ZipEntry) zipEntries.nextElement();
        if (entry.getName().equalsIgnoreCase(oldFileName))
          continue;
        newZip.putNextEntry(new ZipEntry(entry.getName()));
        InputStream is = zipFile.getInputStream(entry);
        try {
          dump(is,newZip);
        } finally {
          newZip.closeEntry();
          is.close();
        }
      }
      zipFile.close();

      // Write the new fileName to the zip
      entry = new ZipEntry(path);
      newZip.putNextEntry(entry);
      try {
View Full Code Here

        try {
            String entryName = getEntryName(fileName);
            if (entryName.length() == 0) {
                return true;
            }
            ZipFile file = openZipFile(fileName);
            return file.getEntry(entryName) != null;
        } catch (IOException e) {
            return false;
        }
    }
View Full Code Here

        try {
            String entryName = getEntryName(fileName);
            if (entryName.length() == 0) {
                return true;
            }
            ZipFile file = openZipFile(fileName);
            Enumeration<? extends ZipEntry> en = file.entries();
            while (en.hasMoreElements()) {
                ZipEntry entry = en.nextElement();
                String n = entry.getName();
                if (n.equals(entryName)) {
                    return entry.isDirectory();
View Full Code Here

        return true;
    }

    public long length(String fileName) {
        try {
            ZipFile file = openZipFile(fileName);
            ZipEntry entry = file.getEntry(getEntryName(fileName));
            return entry == null ? 0 : entry.getSize();
        } catch (IOException e) {
            return 0;
        }
    }
View Full Code Here

                path += "!";
            }
            if (!path.endsWith("/")) {
                path += "/";
            }
            ZipFile file = openZipFile(path);
            String dirName = getEntryName(path);
            String prefix = path.substring(0, path.length() - dirName.length());
            Enumeration<? extends ZipEntry> en = file.entries();
            ArrayList<String> list = New.arrayList();
            while (en.hasMoreElements()) {
                ZipEntry entry = en.nextElement();
                String name = entry.getName();
                if (!name.startsWith(dirName)) {
View Full Code Here

TOP

Related Classes of java.util.zip.ZipFile$MyEnumeration

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.