Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4941162

File and Stream versions of Pack API produce different pack files

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 5.0
    • 5.0
    • deploy

      Two pack APIs are available to the user:

      pack(java.util.jar.JarFile in , java.io.OutputStream out)
      pack(java.util.jar.JarInputStream in, java.io.OutputStream out)

      They do not produce the same output as the following code and output shows:

      public static void main(String[] args){

              Pack200 p200 = new Pack200();
              Map p = p200.getProperties();
      // p.put(Pack200.PACK_EFFORT,"3");
              p.put("pack.modification.time","latest");
              System.out.println(p200);

      // perform a pack cycle using Streams
              try {
                      // Call the packer
                      JarInputStream jistream = new JarInputStream(new FileInputStream("test.jar"));
                      FileOutputStream fostream = new FileOutputStream("test.pack");
                      p200.pack(jistream, fostream);
                      fostream.close();
                      // Call the unpacker
                      FileInputStream fistream = new FileInputStream("test.pack");
                      JarOutputStream jostream = new JarOutputStream(new FileOutputStream("test_unpacked.jar"));
                      p200.unpack(fistream, jostream);
                      jostream.close();
                  } catch (IOException ioe) {
                      ioe.printStackTrace();
                  } catch (Exception e) {
                      e.printStackTrace();
                  }

      // perform a pack cycle using File
              try {
                      // Call the packer
                      JarFile jarFile = new JarFile("test.jar");
                      FileOutputStream fostream2 = new FileOutputStream("test2.pack");
                      p200.pack(jarFile, fostream2);
                      fostream2.close();
                      // Call the unpacker
                      File file = new File("test2.pack");
                      JarOutputStream jostream2 = new JarOutputStream(new FileOutputStream("test2_unpacked.jar"));
                      p200.unpack(file, jostream2);
                      jostream2.close();
                  } catch (IOException ioe) {
                      ioe.printStackTrace();
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }

      which produces:
      -rwxrwxrwx 1 kb144018 green 1602590 Oct 11 17:22 test.jar*
      -rw-rw-rw- 1 kb144018 green 1486955 Oct 12 02:13 test.pack
      -rw-rw-rw- 1 kb144018 green 1587169 Oct 12 02:14 test2.pack
      -rw-rw-rw- 1 kb144018 green 1602397 Oct 12 02:14 test2_unpacked.jar
      -rw-rw-rw- 1 kb144018 green 1602276 Oct 12 00:54 test_unpacked.jar

      test.pack (result of the stream pack method) is different from test2.pack (result of the File pack method).

      Even if the unpacked jars are different, a separate experiment showed that
      the file and stream unpack method produce the same output given the same
      input pack file.

            ksrini Kumar Srinivasan
            kbouyoucsunw Karim Bouyoucef (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: