Examples of ZipFile


Examples of java.util.zip.ZipFile

    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

Examples of java.util.zip.ZipFile

      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

Examples of java.util.zip.ZipFile

      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

Examples of java.util.zip.ZipFile

    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

Examples of java.util.zip.ZipFile

        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

Examples of java.util.zip.ZipFile

        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

Examples of java.util.zip.ZipFile

        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

Examples of java.util.zip.ZipFile

                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

Examples of java.util.zip.ZipFile

        FileObject file = openFileObject(fileName, "r");
        return new FileObjectInputStream(file);
    }

    public FileObject openFileObject(String fileName, String mode) throws IOException {
        ZipFile file = openZipFile(translateFileName(fileName));
        ZipEntry entry = file.getEntry(getEntryName(fileName));
        if (entry == null) {
            throw new FileNotFoundException(fileName);
        }
        return new FileObjectZip(file, entry);
    }
View Full Code Here

Examples of java.util.zip.ZipFile

        return fileName;
    }

    private static ZipFile openZipFile(String fileName) throws IOException {
        fileName = translateFileName(fileName);
        return new ZipFile(fileName);
    }
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.