@Override public long getSize() { return jarEntry.getSize(); } }
List<FileMeta> getResourceListing(URL dirURL, String path) throws IOException { List<FileMeta> listFiles = new ArrayList<>(); if (null == CACHE_JAR_FILE) { //strip out only the JAR file String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); CACHE_JAR_FILE = new JarFile(URLDecoder.decode(jarPath, "UTF-8")); } Enumeration<JarEntry> entries = CACHE_JAR_FILE.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); String name = jarEntry.getName(); if (!name.startsWith(path) || name.equals(path + "/")) { continue; } FileMeta fileMeta = new FileMeta(); fileMeta.name = name.substring(path.length() + 1); fileMeta.isDirectory = jarEntry.isDirectory(); if (!fileMeta.isDirectory) { fileMeta.length = jarEntry.getSize(); } listFiles.add(fileMeta); } return listFiles; }
List<FileMeta> getResourceListing(URL dirURL, String path) throws IOException { List<FileMeta> listFiles = new ArrayList<>(); if (null == CACHE_JAR_FILE) { //strip out only the JAR file String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); CACHE_JAR_FILE = new JarFile(URLDecoder.decode(jarPath, "UTF-8")); } Enumeration<JarEntry> entries = CACHE_JAR_FILE.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); String name = jarEntry.getName(); if (!name.startsWith(path) || name.equals(path + "/")) { continue; } FileMeta fileMeta = new FileMeta(); fileMeta.name = name.substring(path.length() + 1); fileMeta.isDirectory = jarEntry.isDirectory(); if (!fileMeta.isDirectory) { fileMeta.length = jarEntry.getSize(); } listFiles.add(fileMeta); } return listFiles; }
private byte[] loadWithSecurity(String path) throws IOException { URL scriptUrl = URLClassLoader.getSystemResource(path); if (scriptUrl.getProtocol().equals("jar")) { String jarPath = scriptUrl.getPath().substring(5, scriptUrl.getPath().indexOf("!")); JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8")); Enumeration<JarEntry> ens = jar.entries(); while (ens.hasMoreElements()) { JarEntry en = ens.nextElement(); if (!en.isDirectory()) { if (en.toString().equals(path)) { byte[] data = readAll(jar.getInputStream(en), en.getSize()); CodeSigner[] signers = en.getCodeSigners(); canLoadPack = signers != null && signers.length != 0; return data; } } } } return null; }
protected long size(String name) { long retVal = getEntry(name).getSize(); closeCurrentRoot(false); return (retVal == -1) ? 0 : retVal; }
protected Class<?> findClassInJarFile(String qualifiedClassName) throws ClassNotFoundException { URI classUri = URIUtil.buildUri(StandardLocation.CLASS_OUTPUT, qualifiedClassName); String internalClassName = classUri.getPath().substring(1); JarFile jarFile = null; try { for (int i = 0; i < jarFiles.size(); i++) { jarFile = jarFiles.get(i); JarEntry jarEntry = jarFile.getJarEntry(internalClassName); if (jarEntry != null) { InputStream inputStream = jarFile.getInputStream(jarEntry); try { byte[] byteCode = new byte[(int) jarEntry.getSize()]; ByteStreams.read(inputStream, byteCode, 0, byteCode.length); return defineClass(qualifiedClassName, byteCode, 0, byteCode.length); } finally { Closeables.closeQuietly(inputStream); } } } } catch (IOException e) { throw new IllegalStateException(String.format("Failed to lookup class %s in jar file %s", qualifiedClassName, jarFile), e); } return null; }
/** * Returns the content length of the resource. Test cases reveal that if the * URL is referring to a Jar file, this method answers a content-length * returned by URLConnection. For jar entry it should return it's size. * Otherwise, it will return -1. * * @return the content length */ @Override public int getContentLength() { try { connect(); if (jarEntry == null) { return jarFileURLConnection.getContentLength(); } return (int) getJarEntry().getSize(); } catch (IOException e) { // Ignored } return -1; }
if (je.getSize() < MEM_STREAM_SIZE) { is = getMemInputStream(j, je); } else {
File jarFileFile = new File(jarFile.getName()); File jarEntryFile = new File(jarEntry.getName()); size = jarEntry.getSize(); timestamp = jarEntry.getTime(); if (!noSubdir) {
final long classResourceSize = jarEntry.getSize(); final byte[] classResourceBytes; final long actualSize;
/** * Return the length of the resource */ @Override public long length() { if (isDirectory()) return -1; if (_entry!=null) return _entry.getSize(); return -1; }
/** * Return the length of the resource */ public long length() { if (isDirectory()) return -1; if (_entry!=null) return _entry.getSize(); return -1; }
targetFile.mkdirs(); } else { if (!targetFile.exists() || targetFile.length() != jarEntry.getSize()) { try (InputStream is = jarFile.getInputStream(jarEntry); OutputStream out = FileUtils.openOutputStream(targetFile)) {
private static byte[] getFromJar(JarInputStream jarIn) throws IOException { JarEntry entry; while((entry = jarIn.getNextJarEntry())!=null) { if(CLASS_FILENAME.equals(entry.getName())) { return getFromStream(jarIn, entry.getSize()); } } return null; }
@Override public long getContentLength() { if (isDirectory()) { return -1; } return resource.getSize(); }
/** * Return the length of the resource */ @Override public long length() { if (isDirectory()) return -1; if (_entry!=null) return _entry.getSize(); return -1; }
private Archive getUnpackedNestedArchive(JarEntry jarEntry) throws IOException { String name = jarEntry.getName(); if (name.lastIndexOf("/") != -1) { name = name.substring(name.lastIndexOf("/") + 1); } File file = new File(getTempUnpackFolder(), name); if (!file.exists() || file.length() != jarEntry.getSize()) { unpack(jarEntry, file); } return new JarFileArchive(file, file.toURI().toURL()); }