Refine search
private void explodeNatives() throws IOException { URL urlOfJar = getJarURL(); LOGGER.info("[TFS SDK] Exploding natives from {} to folder {}", urlOfJar.toString(), tempFolder.getAbsolutePath()); JarInputStream jarStream = new JarInputStream(urlOfJar.openStream()); JarEntry entry; while ((entry = jarStream.getNextJarEntry()) != null) { if (!entry.isDirectory() && entry.getName().startsWith("tfssdk/native/")) { File newFile = new File(tempFolder, entry.getName()); newFile.getParentFile().mkdirs(); LOGGER.info("[TFS SDK] Extract {} -> {}", entry.getName(), newFile); try (OutputStream fos = new FileOutputStream(newFile)) { IOUtils.copy(jarStream, fos); } } } }
private static void processJar( JarInputStream stream, List<URL> files, String templateDirectory) throws IOException { JarEntry entry; while ((entry = stream.getNextJarEntry()) != null) { String entryName = entry.getName(); if (isTemplateFile(entryName) && entryName.startsWith(templateDirectory)) { files.add(FileUtils.class.getClassLoader().getResource(entryName)); } } }
/** * 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; }
private URL[] enumerateJar(URL urlOfJar) { LOGGER.debug("Enumerating jar: {}", urlOfJar); List<URL> urls = new ArrayList<>(); urls.add(urlOfJar); try { JarInputStream jarStream = new JarInputStream(urlOfJar.openStream()); JarEntry entry; while ((entry = jarStream.getNextJarEntry()) != null) { if (!entry.isDirectory() && entry.getName().endsWith(".jar")) { urls.add(expandJarAndReturnURL(jarStream, entry)); } } } catch (IOException e) { LOGGER.error("Failed to enumerate jar {}", urlOfJar, e); } return urls.toArray(new URL[0]); }
private static void processJar( JarInputStream stream, List<URL> files, String templateDirectory) throws IOException { JarEntry entry; while ((entry = stream.getNextJarEntry()) != null) { String entryName = entry.getName(); if (isTemplateFile(entryName) && entryName.startsWith(templateDirectory)) { files.add(FileUtils.class.getClassLoader().getResource(entryName)); } } }
@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 inputStream = new JarInputStream(new FileInputStream(sourceJar)); try { if (!targetJar.isFile() && !targetJar.createNewFile()) { while ((jarEntry = inputStream.getNextJarEntry()) != null) { byte[] replacement = files.remove(jarEntry.getName()); if (replacement == null) { outputStream.putNextEntry(jarEntry); outputStream.putNextEntry(new JarEntry(jarEntry.getName())); outputStream.write(replacement);
@Override public boolean hasNext() { if (next == null) { try { do { this.next = jarInputStream.getNextJarEntry(); if (next == null) { break; } if (!next.isDirectory() && next.getName().startsWith(parent)) { if (recursive || next.getName().substring(parent.length()).indexOf(JAR_FILE_SEPARATOR) == -1) { break; } } } while (true); } catch (final IOException | SecurityException e) { LOGGER.log(Level.CONFIG, LocalizationMessages.JAR_SCANNER_UNABLE_TO_READ_ENTRY(), e); return false; } } if (next == null) { close(); return false; } return true; }
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); } }
/** * @param file File. * @throws Exception In case of error. */ private void processFile(File file, int prefixLen) throws Exception { if (!file.exists()) throw new FileNotFoundException("File doesn't exist: " + file); if (file.isDirectory()) { for (File f : file.listFiles()) processFile(f, prefixLen); } else { assert file.isFile(); String path = file.getPath(); if (path.toLowerCase().endsWith(".jar")) { try (JarInputStream jin = new JarInputStream(new BufferedInputStream(new FileInputStream(path)))) { JarEntry entry; while ((entry = jin.getNextJarEntry()) != null) { if (!entry.isDirectory() && entry.getName().toLowerCase().endsWith(".class")) processClassFile(entry.getName(), 0); } } } else if (path.toLowerCase().endsWith(".class")) processClassFile(path, prefixLen); } }
@Override public boolean hasNext() { if (next == null) { try { do { this.next = jarInputStream.getNextJarEntry(); if (next == null) { break; } if (!next.isDirectory() && next.getName().startsWith(parent)) { if (recursive || next.getName().substring(parent.length()).indexOf(JAR_FILE_SEPARATOR) == -1) { break; } } } while (true); } catch (final IOException | SecurityException e) { LOGGER.log(Level.CONFIG, LocalizationMessages.JAR_SCANNER_UNABLE_TO_READ_ENTRY(), e); return false; } } if (next == null) { close(); return false; } return true; }
try(JarInputStream is=new JarInputStream(new ByteArrayInputStream(buffer))) { for(;;) { JarEntry nextEntry = is.getNextJarEntry(); if(nextEntry==null) break; System.out.println(nextEntry); } }
protected BytesMap load(byte[] bytes) { BytesMap bmap = new BytesMap(); JarInputStream jar = null; try { jar = new JarInputStream(new ByteArrayInputStream(bytes)); for (JarEntry ent = jar.getNextJarEntry(); ent != null; ent = jar.getNextJarEntry()) { byte[] buff = FileUtil.readAll(jar); if (buff != null) { bmap.put(ent.getName(), buff); } } } catch (Exception e) { } finally { FileUtil.close(jar); } return bmap; }
private InputStream getResourceAsStreamFromEmbeddedJars(final String resourceName) { for (final String embeddedJarPath : this.embeddedJarPathsInNestedJar) { final JarInputStream embeddedJarInputStream; try { embeddedJarInputStream = getEmbeddedJarInputStream(embeddedJarPath); } catch (IOException ex) { // TODO: Notify this to reporters as far as possible. System.err.println("Failed to load entry in embedded JAR: " + resourceName + " / " + embeddedJarPath); ex.printStackTrace(); continue; } JarEntry jarEntry; try { jarEntry = embeddedJarInputStream.getNextJarEntry(); } catch (IOException ex) { // TODO: Notify this to reporters as far as possible. System.err.println("Failed to load entry in embedded JAR: " + resourceName + " / " + embeddedJarPath); ex.printStackTrace(); continue; } while (jarEntry != null) { if (jarEntry.getName().equals(resourceName)) { return embeddedJarInputStream; // Pointing the specific "JAR entry" } } } return null; }
public List<File> getFilesInJar(String jarName){ List<File> result = new ArrayList<File>(); File jarFile = new File(jarName); JarInputStream jarFile = new JarInputStream(new FileInputStream(jarFile)); JarEntry jarEntry; while ((jarEntry = jarFile.getNextJarEntry()) != null) { result.add(inputStreamToFile(jarFile.getInputStream(jarEntry))); } return result; }
JarInputStream jis = new JarInputStream(in); JarEntry entry; while ((entry = jis.getNextJarEntry()) != null) { if (entry.isDirectory()) { File dir = new File(destDir, entry.getName()); dir.mkdir(); if (entry.getTime() != -1) { File destFile = new File(destDir, entry.getName()); if (mVerbose) { System.out.println("unjarring " + destFile + " from " + entry.getName());
private List<URL> findResourcesFromEmbeddedJars(final String resourceName) throws IOException { final ArrayList<URL> resourceUrls = new ArrayList<URL>(); for (final String embeddedJarPath : this.embeddedJarPathsInNestedJar) { final URL embeddedJarUrl = getEmbeddedJarUrl(embeddedJarPath); final JarURLConnection embeddedJarUrlConnection = getEmbeddedJarUrlConnection(embeddedJarUrl); final JarInputStream embeddedJarInputStream = getEmbeddedJarInputStream(embeddedJarUrlConnection); // Note that |JarInputStream.getNextJarEntry| may throw IOException. JarEntry jarEntry = embeddedJarInputStream.getNextJarEntry(); while (jarEntry != null) { if (jarEntry.getName().equals(resourceName)) { // For resources (not classes) in nested JARs, the schema and the URL should be like: // "embulk-plugin-jar:jar:file://.../plugin.jar!/classpath/library.jar!/org.library/resource.txt" // // The "embulk-plugin-jar" URL is processed with |PluginClassUrlStreamHandler|. // See also: https://www.ibm.com/developerworks/library/j-onejar/index.html // // The URL lives only in the JVM execution. // // Note that |new URL| may throw MalformedURLException (extending IOException). resourceUrls.add(new URL("embulk-plugin-jar", "", -1, embeddedJarUrl + "!!/" + resourceName, new PluginClassUrlStreamHandler("embulk-plugin-jar"))); } // Note that |JarInputStream.getNextJarEntry| may throw IOException. jarEntry = embeddedJarInputStream.getNextJarEntry(); } } return resourceUrls; }
for (String classpathEntry : System.getProperty("java.class.path").split(System.getProperty("path.separator"))) { if (classpathEntry.endsWith(".jar")) { File jar = new File(classpathEntry); JarInputStream is = new JarInputStream(new FileInputStream(jar)); JarEntry entry; while( (entry = is.getNextJarEntry()) != null) { if(entry.getName().endsWith(".class")) { // Class.forName(entry.getName()) and check // for implementation of the interface } } } }
protected BytesMap load(byte[] bytes) { BytesMap bmap = new BytesMap(); JarInputStream jar = null; try { jar = new JarInputStream(new ByteArrayInputStream(bytes)); for (JarEntry ent = jar.getNextJarEntry(); ent != null; ent = jar.getNextJarEntry()) { byte[] buff = FileUtil.readAll(jar); if (buff != null) { bmap.put(ent.getName(), buff); } } } catch (Exception e) { } finally { FileUtil.close(jar); } return bmap; }
jarEntry = embeddedJarInputStream.getNextJarEntry(); } catch (IOException ex) { if (jarEntry.getName().equals(resourceName)) { jarEntry = embeddedJarInputStream.getNextJarEntry(); } catch (IOException ex) {