/** * Returns a file from which the specified resource can be loaded. This method will unpack the * resource into a temporary directory and return a reference to that file. * * @param path the path to the resource in this jar file. * @return a file from which the resource can be loaded or null if no such resource exists. */ public File getResourceFile(String path) throws IOException { if (resolveJarFile()) { return null; } // if we have been unpacked, return our unpacked file if (_cache != null) { File cfile = new File(_cache, path); if (cfile.exists()) { return cfile; } else { return null; } } // otherwise, we unpack resources as needed into a temp directory String tpath = StringUtil.md5hex(_source.getPath() + "%" + path); File tfile = new File(getCacheDir(), tpath); if (tfile.exists() && (tfile.lastModified() > _sourceLastMod)) { return tfile; } JarEntry entry = _jarSource.getJarEntry(path); if (entry == null) { // log.info("Couldn't locate path in jar", "path", path, "jar", _jarSource); return null; } // copy the resource into the temporary file BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream(tfile)); InputStream jin = _jarSource.getInputStream(entry); StreamUtil.copy(jin, fout); jin.close(); fout.close(); return tfile; }