Beispiel #1
0
  public void connect() throws IOException {
    if (!connected) {
      String path = url.getPath();
      Matcher matcher = urlPattern.matcher(path);
      if (matcher.matches()) {
        path = matcher.group(1);
        String subPath = matcher.group(2);
        JarURLConnection jarURLConnection =
            (JarURLConnection) new URL("jar:" + path).openConnection();
        inputStream = jarURLConnection.getInputStream();
        if (subPath.isEmpty() == false) {
          JarFile jar = retrieve(new URL(path), inputStream);
          String[] nodes = nestingSeparatorPattern.split(subPath);
          int i;
          for (i = 0; i < nodes.length - 1; i++) {
            path += "!/" + nodes[i];
            jar = retrieve(new URL(path), inputStream);
          }
          ZipEntry entry = jar.getEntry(nodes[i]);
          entrySize = entry.getSize();
          inputStream = jar.getInputStream(entry);
        }
      } else {
        throw new MalformedURLException("Invalid JAP URL path: " + path);
      }

      connected = true;
    }
  }
  /**
   * Returns a stream to a pack, depending on the installation kind.
   *
   * @param n The pack number.
   * @return The stream.
   * @exception Exception Description of the Exception
   */
  private InputStream getPackAsStream(int n) throws Exception {
    InputStream in = null;

    if (idata.kind.equalsIgnoreCase("standard")
        || idata.kind.equalsIgnoreCase("standard-kunststoff"))
      in = getClass().getResourceAsStream("/packs/pack" + n);
    else if (idata.kind.equalsIgnoreCase("web") || idata.kind.equalsIgnoreCase("web-kunststoff")) {
      URL url = new URL("jar:" + jarLocation + "!/packs/pack" + n);
      JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
      in = jarConnection.getInputStream();
    }
    return in;
  }