/*
     * Creates the resource and if the check flag is set to true, checks if
     * is its okay to return the resource.
     */
    Resource checkResource(final String name, boolean check, final JarEntry entry) {

      final URL url;
      try {
        url = new URL(getBaseURL(), name);
        if (check) {
          URLClassPath.check(url);
        }
      } catch (MalformedURLException e) {
        return null;
        // throw new IllegalArgumentException("name");
      } catch (IOException e) {
        return null;
      } catch (AccessControlException e) {
        return null;
      }

      return new Resource() {
        public String getName() {
          return name;
        }

        public URL getURL() {
          return url;
        }

        public URL getCodeSourceURL() {
          return csu;
        }

        public InputStream getInputStream() throws IOException {
          return jar.getInputStream(entry);
        }

        public int getContentLength() {
          return (int) entry.getSize();
        }

        public Manifest getManifest() throws IOException {
          return jar.getManifest();
        };

        public Certificate[] getCertificates() {
          return entry.getCertificates();
        };
      };
    }
    Resource getResource(final String name, boolean check) {
      final URL url;
      try {
        URL normalizedBase = new URL(getBaseURL(), ".");
        url = new URL(getBaseURL(), name);

        if (url.getFile().startsWith(normalizedBase.getFile()) == false) {
          // requested resource had ../..'s in path
          return null;
        }

        if (check) URLClassPath.check(url);
        final File file = new File(dir, name.replace('/', File.separatorChar));
        if (file.exists()) {
          return new Resource() {
            public String getName() {
              return name;
            };

            public URL getURL() {
              return url;
            };

            public URL getCodeSourceURL() {
              return getBaseURL();
            };

            public InputStream getInputStream() throws IOException {
              return new FileInputStream(file);
            };

            public int getContentLength() throws IOException {
              return (int) file.length();
            };
          };
        }
      } catch (Exception e) {
        return null;
      }
      return null;
    }
    Resource getResource(final String name, boolean check) {
      final URL url;
      try {
        url = new URL(base, name);
      } catch (MalformedURLException e) {
        throw new IllegalArgumentException("name");
      }
      final URLConnection uc;
      try {
        if (check) {
          URLClassPath.check(url);
        }
        uc = url.openConnection();
        InputStream in = uc.getInputStream();
      } catch (Exception e) {
        return null;
      }
      return new Resource() {
        public String getName() {
          return name;
        }

        public URL getURL() {
          return url;
        }

        public URL getCodeSourceURL() {
          return base;
        }

        public InputStream getInputStream() throws IOException {
          return uc.getInputStream();
        }

        public int getContentLength() throws IOException {
          return uc.getContentLength();
        }
      };
    }
    URL findResource(final String name, boolean check) {
      URL url;
      try {
        url = new URL(base, name);
      } catch (MalformedURLException e) {
        throw new IllegalArgumentException("name");
      }

      try {
        if (check) {
          URLClassPath.check(url);
        }

        // our best guess for the other cases
        InputStream is = url.openStream();
        is.close();

        return url;
      } catch (Exception e) {
        return null;
      }
    }