List of usage examples for java.util.jar JarEntry getName
public String getName()
From source file:org.nuxeo.osgi.application.FrameworkBootstrap.java
protected void extractNestedJars(File file, File tmpDir) throws IOException { JarFile jarFile = new JarFile(file); String fileName = file.getName(); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); String path = entry.getName(); if (entry.getName().endsWith(".jar")) { String name = path.replace('/', '_'); File dest = new File(tmpDir, fileName + '-' + name); extractNestedJar(jarFile, entry, dest); loader.addURL(dest.toURI().toURL()); }//from w ww .j a v a 2 s .co m } }
From source file:org.apache.hadoop.hbase.util.CoprocessorClassLoader.java
private void init(Path path, String pathPrefix, Configuration conf) throws IOException { // Copy the jar to the local filesystem String parentDirStr = conf.get(LOCAL_DIR_KEY, DEFAULT_LOCAL_DIR) + TMP_JARS_DIR; synchronized (parentDirLockSet) { if (!parentDirLockSet.contains(parentDirStr)) { Path parentDir = new Path(parentDirStr); FileSystem fs = FileSystem.getLocal(conf); fs.delete(parentDir, true); // it's ok if the dir doesn't exist now parentDirLockSet.add(parentDirStr); if (!fs.mkdirs(parentDir) && !fs.getFileStatus(parentDir).isDirectory()) { throw new RuntimeException("Failed to create local dir " + parentDirStr + ", CoprocessorClassLoader failed to init"); }//from w ww. j a v a2s . c om } } FileSystem fs = path.getFileSystem(conf); File dst = new File(parentDirStr, "." + pathPrefix + "." + path.getName() + "." + System.currentTimeMillis() + ".jar"); fs.copyToLocalFile(path, new Path(dst.toString())); dst.deleteOnExit(); addURL(dst.getCanonicalFile().toURI().toURL()); JarFile jarFile = new JarFile(dst.toString()); try { Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); Matcher m = libJarPattern.matcher(entry.getName()); if (m.matches()) { File file = new File(parentDirStr, "." + pathPrefix + "." + path.getName() + "." + System.currentTimeMillis() + "." + m.group(1)); IOUtils.copyBytes(jarFile.getInputStream(entry), new FileOutputStream(file), conf, true); file.deleteOnExit(); addURL(file.toURI().toURL()); } } } finally { jarFile.close(); } }
From source file:org.bimserver.plugins.JarClassLoader.java
public JarClassLoader(ClassLoader parentClassLoader, File jarFile) { super(parentClassLoader); this.jarFile = jarFile; try {/*from w w w . ja v a 2s . com*/ JarInputStream jarInputStream = new JarInputStream(new FileInputStream(jarFile)); JarEntry entry = jarInputStream.getNextJarEntry(); map = new HashMap<String, byte[]>(); while (entry != null) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); IOUtils.copy(jarInputStream, byteArrayOutputStream); map.put(entry.getName(), byteArrayOutputStream.toByteArray()); if (entry.getName().endsWith(".jar")) { loadSubJars(byteArrayOutputStream.toByteArray()); } entry = jarInputStream.getNextJarEntry(); } jarInputStream.close(); } catch (FileNotFoundException e) { } catch (IOException e) { } }
From source file:org.romaframework.core.resource.ResourceResolver.java
/** * Examine a jar file searching for entities. * /*from ww w.ja v a 2s . c o m*/ * @param f * @throws IOException */ protected void examineJarFile(File f, String iStartingPackage) { FileInputStream fis = null; try { fis = new FileInputStream(f); final JarInputStream jis = new JarInputStream(new BufferedInputStream(fis)); JarEntry entry; String fullName, packagePrefix, name; String pathStartingPackage = Utility.getResourcePath(iStartingPackage); int i; while ((entry = jis.getNextJarEntry()) != null) { fullName = entry.getName(); if (fullName.startsWith(pathStartingPackage) && acceptResorce(fullName)) { i = fullName.lastIndexOf(JAR_PATH_SEPARATOR) + 1; packagePrefix = fullName.substring(0, i).replace(JAR_PATH_SEPARATOR, PACKAGE_SEPARATOR); name = fullName.substring(i, fullName.length()); addResource(f, name, packagePrefix, iStartingPackage); } } } catch (Exception e) { } finally { try { if (fis != null) fis.close(); } catch (IOException e) { } } }
From source file:org.apache.hyracks.maven.license.GenerateFileMojo.java
private SortedMap<String, JarEntry> gatherMatchingEntries(JarFile jarFile, Predicate<JarEntry> filter) { SortedMap<String, JarEntry> matches = new TreeMap<>(); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (filter.test(entry)) { matches.put(entry.getName(), entry); }// w w w .ja v a2 s. co m } return matches; }
From source file:com.cloudera.cdk.data.hbase.tool.SchemaTool.java
/** * Gets the list of HBase Common Avro schema strings from a directory in the * Jar. It recursively searches the directory in the jar to find files that * end in .avsc to locate thos strings.//from ww w . j a va2 s. c om * * @param jarPath * The path to the jar to search * @param directoryPath * The directory in the jar to find avro schema strings * @return The list of schema strings. */ private List<String> getSchemaStringsFromJar(String jarPath, String directoryPath) { LOG.info("Getting schema strings in: " + directoryPath + ", from jar: " + jarPath); JarFile jar; try { jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8")); } catch (UnsupportedEncodingException e) { throw new HBaseCommonException(e); } catch (IOException e) { throw new HBaseCommonException(e); } Enumeration<JarEntry> entries = jar.entries(); List<String> schemaStrings = new ArrayList<String>(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); if (jarEntry.getName().startsWith(directoryPath) && jarEntry.getName().endsWith(".avsc")) { LOG.info("Found schema: " + jarEntry.getName()); InputStream inputStream; try { inputStream = jar.getInputStream(jarEntry); } catch (IOException e) { throw new HBaseCommonException(e); } String schemaString = AvroUtils.inputStreamToString(inputStream); schemaStrings.add(schemaString); } } return schemaStrings; }
From source file:org.openmrs.module.ModuleUtil.java
/** * This loops over all FILES in this jar to get the package names. If there is an empty * directory in this jar it is not returned as a providedPackage. * * @param file jar file to look into/*from www .jav a 2 s. com*/ * @return list of strings of package names in this jar */ public static Collection<String> getPackagesFromFile(File file) { // End early if we're given a non jar file if (!file.getName().endsWith(".jar")) { return Collections.<String>emptySet(); } Set<String> packagesProvided = new HashSet<String>(); JarFile jar = null; try { jar = new JarFile(file); Enumeration<JarEntry> jarEntries = jar.entries(); while (jarEntries.hasMoreElements()) { JarEntry jarEntry = jarEntries.nextElement(); if (jarEntry.isDirectory()) { // skip over directory entries, we only care about files continue; } String name = jarEntry.getName(); // Skip over some folders in the jar/omod if (name.startsWith("lib") || name.startsWith("META-INF") || name.startsWith("web/module")) { continue; } Integer indexOfLastSlash = name.lastIndexOf("/"); if (indexOfLastSlash <= 0) { continue; } String packageName = name.substring(0, indexOfLastSlash); packageName = packageName.replaceAll("/", "."); if (packagesProvided.add(packageName)) { if (log.isTraceEnabled()) { log.trace("Adding module's jarentry with package: " + packageName); } } } jar.close(); } catch (IOException e) { log.error("Error while reading file: " + file.getAbsolutePath(), e); } finally { if (jar != null) { try { jar.close(); } catch (IOException e) { // Ignore quietly } } } return packagesProvided; }
From source file:org.bimserver.plugins.classloaders.JarClassLoader.java
private void addDataToMap(JarInputStream jarInputStream, JarEntry entry) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream); IOUtils.copy(jarInputStream, deflaterOutputStream); deflaterOutputStream.finish();/*from w ww .j a va2s.c o m*/ map.put(entry.getName(), byteArrayOutputStream.toByteArray()); }
From source file:com.qcadoo.plugin.internal.descriptorparser.DefaultPluginDescriptorParser.java
private JarEntry findDescriptorEntry(final Enumeration<JarEntry> jarEntries, final String fileName) { while (jarEntries.hasMoreElements()) { JarEntry jarEntry = jarEntries.nextElement(); if (matcher.match(descriptor, jarEntry.getName())) { return jarEntry; }// w w w . j a v a2 s.c om } throw new PluginException("Plugin descriptor " + descriptor + " not found in " + fileName); }
From source file:org.devproof.portal.core.module.theme.service.ThemeServiceImpl.java
private File createDefaultTheme(String[] themePaths, String[] filterPaths) { try {//from www . jav a 2 s. c o m @SuppressWarnings("unchecked") Set<String> libs = servletContext.getResourcePaths("/WEB-INF/lib"); Set<String> zipResources = new HashSet<String>(); File back = File.createTempFile("devproof-defaulttheme-", ".zip"); FileOutputStream fos = new FileOutputStream(back); ZipOutputStream zos = new ZipOutputStream(fos); if (libs.isEmpty()) { // development variant Resource root[] = applicationContext.getResources("classpath*:/"); for (String ext : ThemeConstants.ALLOWED_THEME_EXT) { for (String themePath : themePaths) { final Resource resources[]; if (themePath.endsWith("/")) { resources = applicationContext.getResources("classpath*:" + themePath + "**/*" + ext); } else { resources = applicationContext.getResources("classpath*:" + themePath + ext); } for (Resource r : resources) { String zipPath = getZipPath(root, r); if (zipPath != null && !isFiltered(null, filterPaths, zipPath) && !zipResources.contains(zipPath)) { zipResources.add(zipPath); ZipEntry ze = new ZipEntry(zipPath); zos.putNextEntry(ze); InputStream is = r.getInputStream(); byte[] file = new byte[is.available()]; is.read(file); is.close(); zos.write(file); zos.closeEntry(); } } } } } else { // prod variant for (String lib : libs) { URL url = servletContext.getResource(lib); JarFile file = new JarFile(url.getFile()); Enumeration<JarEntry> entries = file.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); if (!isFiltered(themePaths, filterPaths, jarEntry.getName()) && !zipResources.contains(jarEntry.getName())) { zipResources.add(jarEntry.getName()); ZipEntry ze = new ZipEntry(jarEntry.getName()); InputStream is = file.getInputStream(jarEntry); byte[] content = new byte[is.available()]; is.read(content); is.close(); zos.putNextEntry(ze); zos.write(content); zos.closeEntry(); } } } } zos.finish(); zos.close(); fos.close(); return back; } catch (FileNotFoundException e) { logger.error("Unknown: ", e); } catch (IOException e) { logger.error("Unknown: ", e); } return null; }