/** java.util.jar.JarFile#entries() */
 public void test_entries() throws Exception {
   /*
    * Note only (and all of) the following should be contained in the file
    * META-INF/ META-INF/MANIFEST.MF foo/ foo/bar/ foo/bar/A.class Blah.txt
    */
   Support_Resources.copyFile(resources, null, jarName);
   JarFile jarFile = new JarFile(new File(resources, jarName));
   Enumeration<JarEntry> e = jarFile.entries();
   int i;
   for (i = 0; e.hasMoreElements(); i++) {
     e.nextElement();
   }
   assertEquals(jarFile.size(), i);
   jarFile.close();
   assertEquals(6, i);
 }
Exemplo n.º 2
0
  public void unpack(String pluginName) throws IOException {
    JarFile jar = new JarFile(pluginName);
    Enumeration<JarEntry> enumEntries = jar.entries();
    int count = jar.size();
    int i = 0;
    while (enumEntries.hasMoreElements()) {
      java.util.jar.JarEntry file = (java.util.jar.JarEntry) enumEntries.nextElement();
      System.out.println("Unpack " + file.getName() + ": " + (++i) + " / " + count);

      if (file.getName().startsWith("Adapter\\")
          || file.getName().startsWith("Adapter/")
          || file.getName().startsWith("Drawer\\")
          || file.getName().startsWith("Drawer/")) {
        continue;
      }
      if (file.getName().startsWith("META-INF") || file.getName().startsWith("org")) {
        continue;
      }
      java.io.File f = new java.io.File(file.getName());
      if (file.isDirectory()) { // if its a directory, create it
        if (file.getName().startsWith("Adapter")) {
          continue;
        }
        if (file.getName().startsWith("Drawer")) {
          continue;
        }
        f.mkdir();
        continue;
      }
      if (f.exists()) {
        continue;
      }
      java.io.InputStream is = jar.getInputStream(file); // get the input stream
      java.io.FileOutputStream fos = new java.io.FileOutputStream(f);
      while (is.available() > 0) { // write contents of 'is' to 'fos'
        fos.write(is.read());
      }
      fos.close();
      is.close();
    }
    jar.close();
  }
 public void applyPatch(
     Patcher.PatchDelegate paramPatchDelegate,
     String paramString1,
     String paramString2,
     OutputStream paramOutputStream)
     throws IOException {
   File localFile1 = new File(paramString1);
   File localFile2 = new File(paramString2);
   JarOutputStream localJarOutputStream = new JarOutputStream(paramOutputStream);
   JarFile localJarFile1 = new JarFile(localFile1);
   JarFile localJarFile2 = new JarFile(localFile2);
   HashSet localHashSet1 = new HashSet();
   HashMap localHashMap = new HashMap();
   determineNameMapping(localJarFile2, localHashSet1, localHashMap);
   Object[] arrayOfObject = localHashMap.keySet().toArray();
   HashSet localHashSet2 = new HashSet();
   Enumeration localEnumeration1 = localJarFile1.entries();
   if (localEnumeration1 != null)
     while (localEnumeration1.hasMoreElements())
       localHashSet2.add(((JarEntry) localEnumeration1.nextElement()).getName());
   double d1 = localHashSet2.size() + arrayOfObject.length + localJarFile2.size();
   double d2 = 0.0D;
   localHashSet2.removeAll(localHashSet1);
   d1 -= localHashSet1.size();
   Enumeration localEnumeration2 = localJarFile2.entries();
   if (localEnumeration2 != null)
     while (localEnumeration2.hasMoreElements()) {
       JarEntry localJarEntry1 = (JarEntry) localEnumeration2.nextElement();
       if (!"META-INF/INDEX.JD".equals(localJarEntry1.getName())) {
         updateDelegate(paramPatchDelegate, d2, d1);
         d2 += 1.0D;
         writeEntry(localJarOutputStream, localJarEntry1, localJarFile2);
         boolean bool1 = localHashSet2.remove(localJarEntry1.getName());
         if (bool1) d1 -= 1.0D;
       } else {
         d1 -= 1.0D;
       }
     }
   String str;
   Object localObject1;
   for (int i = 0; i < arrayOfObject.length; i++) {
     str = (String) arrayOfObject[i];
     localObject1 = (String) localHashMap.get(str);
     JarEntry localJarEntry2 = localJarFile1.getJarEntry((String) localObject1);
     if (localJarEntry2 == null) {
       localObject2 = "move" + (String) localObject1 + " " + str;
       handleException("jardiff.error.badmove", (String) localObject2);
     }
     Object localObject2 = new JarEntry(str);
     ((JarEntry) localObject2).setTime(localJarEntry2.getTime());
     ((JarEntry) localObject2).setSize(localJarEntry2.getSize());
     ((JarEntry) localObject2).setCompressedSize(localJarEntry2.getCompressedSize());
     ((JarEntry) localObject2).setCrc(localJarEntry2.getCrc());
     ((JarEntry) localObject2).setMethod(localJarEntry2.getMethod());
     ((JarEntry) localObject2).setExtra(localJarEntry2.getExtra());
     ((JarEntry) localObject2).setComment(localJarEntry2.getComment());
     updateDelegate(paramPatchDelegate, d2, d1);
     d2 += 1.0D;
     writeEntry(
         localJarOutputStream,
         (JarEntry) localObject2,
         localJarFile1.getInputStream(localJarEntry2));
     boolean bool2 = localHashSet2.remove(localObject1);
     if (!bool2) continue;
     d1 -= 1.0D;
   }
   Iterator localIterator = localHashSet2.iterator();
   if (localIterator != null)
     while (localIterator.hasNext()) {
       str = (String) localIterator.next();
       localObject1 = localJarFile1.getJarEntry(str);
       updateDelegate(paramPatchDelegate, d2, d1);
       d2 += 1.0D;
       writeEntry(localJarOutputStream, (JarEntry) localObject1, localJarFile1);
     }
   updateDelegate(paramPatchDelegate, d2, d1);
   localJarOutputStream.finish();
   localJarOutputStream.close();
   localJarFile1.close();
   localJarFile2.close();
 }