コード例 #1
0
  public void close() throws IOException {

    // Update the manifest
    Manifest updated = m_manifestBuilder.build(m_manifest);

    // Create a new Jar file
    FileOutputStream fos = new FileOutputStream(m_target);
    JarOutputStream jos = new JarOutputStream(fos, updated);

    try {
      // Copy classes and resources
      List<JarEntry> entries = Collections.list(m_source.entries());
      for (JarEntry entry : entries) {

        // Ignore some entries (MANIFEST, ...)
        if (isIgnored(entry)) {
          continue;
        }

        if (isUpdated(entry)) {
          // Write newer/updated resource (manipulated classes, ...)

          JarEntry je = new JarEntry(entry.getName());
          byte[] data = m_content.get(getInternalPath(entry.getName()));
          jos.putNextEntry(je);
          jos.write(data);
          jos.closeEntry();
        } else {
          // Copy the resource as-is

          jos.putNextEntry(entry);
          InputStream is = m_source.getInputStream(entry);
          try {
            Streams.transfer(is, jos);
          } finally {
            Streams.close(is);
          }

          jos.closeEntry();
        }
      }
    } finally {
      try {
        m_source.close();
      } catch (IOException e) {
        // Ignored
      }
      Streams.close(jos, fos);
    }
  }
コード例 #2
0
 public byte[] read(String path) throws IOException {
   ZipEntry entry = m_source.getEntry(getInternalPath(path));
   if (entry == null) {
     throw new IOException("Jar Entry is not found for class " + path + ".");
   }
   return Streams.readBytes(m_source.getInputStream(entry));
 }