Refine search
/** * Peek into the JAR data and make sure that it is valid JAR content. * * @param jarFile Jar containing data to be validated. * @return True if the data has JAR content, false otherwise */ public static boolean hasValidJarContent(File jarFile) { JarInputStream jarInputStream = null; boolean valid = false; try { jarInputStream = new JarInputStream(new FileInputStream(jarFile)); valid = jarInputStream.getNextJarEntry() != null; } catch (IOException ignore) { // Ignore this exception and just return false } finally { try { jarInputStream.close(); } catch (IOException ignored) { // Ignore this exception and just return result } } return valid; }
JarInputStream inputStream = new JarInputStream(new FileInputStream(sourceJar)); try { if (!targetJar.isFile() && !targetJar.createNewFile()) { inputStream.close();
private static void recurseURL(URL url, List<URL> files, String templateDirectory) throws URISyntaxException, IOException { if ("file".equals(url.getProtocol())) { recurse(new File(url.toURI()), new File(url.toURI()), files, templateDirectory); } else { if (url.getPath().endsWith(".jar")) { JarInputStream stream = new JarInputStream(url.openStream()); processJar(stream, files, templateDirectory); stream.close(); } } }
public void addPackage(String packageName, boolean recursive) throws IOException, ClassNotFoundException, NoClassDefFoundError { String[] paths = loader.getPaths(); final String packagePath = packageName == null ? null : (packageName.replace('.', '/') + "/"); int prevSize = classes.size(); for (String p : paths) { File file = new File(p); if (file.isDirectory()) { addMatchingDir(null, file, packagePath, recursive); } else { JarInputStream jis = new JarInputStream(new FileInputStream(file)); ZipEntry e = jis.getNextEntry(); while (e != null) { addMatchingFile(e.getName(), packagePath, recursive); jis.closeEntry(); e = jis.getNextEntry(); } jis.close(); } } if (classes.size() == 0 && packageName == null) { logger.warn("No classes found in the unnamed package"); Builder.printHelp(); } else if (prevSize == classes.size() && packageName != null) { logger.warn("No classes found in package " + packageName); } }
private static void recurseURL(URL url, List<URL> files, String templateDirectory) throws URISyntaxException, IOException { if ("file".equals(url.getProtocol())) { recurse(new File(url.toURI()), new File(url.toURI()), files, templateDirectory); } else { if (url.getPath().endsWith(".jar")) { JarInputStream stream = new JarInputStream(url.openStream()); processJar(stream, files, templateDirectory); stream.close(); } } }
@Override public InputStream openResource(String name) { try { JarInputStream input = new JarInputStream(new FileInputStream(file)); while (true) { ZipEntry entry = input.getNextEntry(); if (entry == null) { input.close(); throw new IllegalArgumentException("Resource not found: " + name); } if (entry.getName().equals(name)) { return input; } if (name.startsWith("/") && entry.getName().equals(name.substring(1))) { return input; } } } catch (FileNotFoundException e) { throw new IllegalStateException("The underlying file does not exist"); } catch (IOException e) { throw new IllegalStateException("Error reading jar file"); } } }
JarInputStream jis = new JarInputStream(in); JarEntry entry; while ((entry = jis.getNextJarEntry()) != null) { jis.close();
if (file.getName().endsWith(".jar")) JarInputStream stream = new JarInputStream(new FileInputStream(file)); processJar(stream, files, templateDirectory); stream.close();
JarInputStream stream = new JarInputStream(new FileInputStream(file)); processJar(stream, files, templateDirectory); stream.close();
throws IOException, ClassNotFoundException { final Set<Class<?>> classes = new HashSet<Class<?>>(); final JarInputStream jarFile = new JarInputStream(new FileInputStream(jar)); try { JarEntry jarEntry; jarFile.close();
Collection<String> functionClasses = findFunctionsInThisJar(); jarInputStream = new JarInputStream(bufferedInputStream); JarEntry jarEntry = jarInputStream.getNextJarEntry(); if (jarInputStream != null) { try { jarInputStream.close(); } catch (IOException ioex) { logger.error("Exception attempting to close JAR input stream", ioex);
@Override public void matched (URI uri) throws Exception { LOG.debug("Search of {}",uri); if (uri.toString().toLowerCase(Locale.ENGLISH).endsWith(".jar")) { InputStream in = Resource.newResource(uri).getInputStream(); if (in==null) return; JarInputStream jar_in = new JarInputStream(in); try { JarEntry entry = jar_in.getNextJarEntry(); while (entry!=null) { processEntry(uri, entry); entry = jar_in.getNextJarEntry(); } } finally { jar_in.close(); } } } }
jarInputStream = new JarInputStream(inputStream); } catch (final IOException ex) { LOGGER.log(Level.CONFIG, LocalizationMessages.OSGI_REGISTRY_ERROR_PROCESSING_RESOURCE_STREAM(jar), ex); } finally { try { jarInputStream.close(); } catch (final IOException e) {
jarInputStream = new JarInputStream(inputStream); } catch (final IOException ex) { LOGGER.log(Level.CONFIG, LocalizationMessages.OSGI_REGISTRY_ERROR_PROCESSING_RESOURCE_STREAM(jar), ex); } finally { try { jarInputStream.close(); } catch (final IOException e) {
@Test public void testNoManifest() throws Exception { File dir = new File(System.getProperty("test.build.dir", "target/test-dir"), TestJarFinder.class.getName() + "-testNoManifest"); delete(dir); dir.mkdirs(); File propsFile = new File(dir, "props.properties"); Writer writer = new FileWriter(propsFile); new Properties().store(writer, ""); writer.close(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); JarOutputStream zos = new JarOutputStream(baos); JarFinder.jarDir(dir, "", zos); JarInputStream jis = new JarInputStream(new ByteArrayInputStream(baos.toByteArray())); Assert.assertNotNull(jis.getManifest()); jis.close(); } }
@Test public void testExistingManifest() throws Exception { File dir = new File(System.getProperty("test.build.dir", "target/test-dir"), TestJarFinder.class.getName() + "-testExistingManifest"); delete(dir); dir.mkdirs(); File metaInfDir = new File(dir, "META-INF"); metaInfDir.mkdirs(); File manifestFile = new File(metaInfDir, "MANIFEST.MF"); Manifest manifest = new Manifest(); OutputStream os = new FileOutputStream(manifestFile); manifest.write(os); os.close(); File propsFile = new File(dir, "props.properties"); Writer writer = new FileWriter(propsFile); new Properties().store(writer, ""); writer.close(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); JarOutputStream zos = new JarOutputStream(baos); JarFinder.jarDir(dir, "", zos); JarInputStream jis = new JarInputStream(new ByteArrayInputStream(baos.toByteArray())); Assert.assertNotNull(jis.getManifest()); jis.close(); }
JarInputStream jarFile = null; try { jarFile = new JarInputStream(new FileInputStream(jarFileName)); } catch (IOException ioEx) { LOG.warn("Failed to look for classes in " + jarFileName + ": " + ioEx); jarFile.close();
final JarInputStream jarInputStream; try { jarInputStream = new JarInputStream( getArchiveUrl().openStream() ); final JarInputStream subJarInputStream = new JarInputStream( jarInputStream ); try { ZipEntry subZipEntry = jarInputStream.getNextEntry(); subJarInputStream.close(); jarInputStream.close();
private void loadSubJars(byte[] byteArray) { try { JarInputStream jarInputStream = new JarInputStream(new ByteArrayInputStream(byteArray)); JarEntry entry = jarInputStream.getNextJarEntry(); while (entry != null) { addDataToMap(jarInputStream, entry); entry = jarInputStream.getNextJarEntry(); } jarInputStream.close(); } catch (IOException e) { LOGGER.error("", e); } }
private List<String> readFromJarFile(String jarPath, String splashedPackageName) throws IOException { JarInputStream jarIn = new JarInputStream(new FileInputStream(jarPath)); JarEntry entry = jarIn.getNextJarEntry(); List<String> nameList = new ArrayList<String>(); while (null != entry) { String name = entry.getName(); if (name.startsWith(splashedPackageName) && isClassFile(name)) { nameList.add(name); } entry = jarIn.getNextJarEntry(); } jarIn.close(); return nameList; }