Beispiel #1
0
  private static void writeEntry(JarOutputStream jos, JarEntry entry, InputStream data)
      throws IOException {
    jos.putNextEntry(entry);

    // Read the entry
    int size = data.read(newBytes);

    while (size != -1) {
      jos.write(newBytes, 0, size);
      size = data.read(newBytes);
    }
    data.close();
  }
 /** Create a jar file containing one or more entries. */
 File createJar(File jar, String... entries) throws IOException {
   OutputStream out = new FileOutputStream(jar);
   try {
     JarOutputStream jos = new JarOutputStream(out);
     for (String e : entries) {
       jos.putNextEntry(new JarEntry(getPathForZipEntry(e)));
       jos.write(getBodyForEntry(e).getBytes());
     }
     jos.close();
   } finally {
     out.close();
   }
   return jar;
 }
Beispiel #3
0
  /**
   * Writes the index file out to <code>jos</code>. <code>oldEntries</code> gives the names of the
   * files that were removed, <code>movedMap</code> maps from the new name to the old name.
   */
  private static void createIndex(JarOutputStream jos, List oldEntries, Map movedMap)
      throws IOException {
    StringWriter writer = new StringWriter();

    writer.write(VERSION_HEADER);
    writer.write("\r\n");

    // Write out entries that have been removed
    for (int counter = 0; counter < oldEntries.size(); counter++) {
      String name = (String) oldEntries.get(counter);

      writer.write(REMOVE_COMMAND);
      writer.write(" ");
      writeEscapedString(writer, name);
      writer.write("\r\n");
    }

    // And those that have moved
    Iterator names = movedMap.keySet().iterator();

    if (names != null) {
      while (names.hasNext()) {
        String newName = (String) names.next();
        String oldName = (String) movedMap.get(newName);

        writer.write(MOVE_COMMAND);
        writer.write(" ");
        writeEscapedString(writer, oldName);
        writer.write(" ");
        writeEscapedString(writer, newName);
        writer.write("\r\n");
      }
    }

    JarEntry je = new JarEntry(INDEX_NAME);
    byte[] bytes = writer.toString().getBytes("UTF-8");

    writer.close();
    jos.putNextEntry(je);
    jos.write(bytes, 0, bytes.length);
  }
Beispiel #4
0
  private static void writeEntry(JarOutputStream jos, JarEntry entry, InputStream data)
      throws IOException {
    jos.putNextEntry(entry);

    try {
      // Read the entry
      int size = data.read(newBytes);

      while (size != -1) {
        jos.write(newBytes, 0, size);
        size = data.read(newBytes);
      }
    } catch (IOException ioE) {
      throw ioE;
    } finally {
      try {
        data.close();
      } catch (IOException e) {
        // Ignore
      }
    }
  }