List of usage examples for org.apache.commons.compress.archivers.jar JarArchiveEntry getName
public String getName()
From source file:com.offbynull.coroutines.instrumenter.asm.FileSystemClassInformationRepository.java
private void addJar(File file) throws IOException { Validate.notNull(file);//from w w w .j a va 2 s. co m Validate.isTrue(file.isFile()); try (FileInputStream fis = new FileInputStream(file); JarArchiveInputStream jais = new JarArchiveInputStream(fis)) { JarArchiveEntry entry; while ((entry = jais.getNextJarEntry()) != null) { if (!entry.getName().endsWith(".class") || entry.isDirectory()) { continue; } populateSuperClassMapping(jais); } } }
From source file:es.jamisoft.comun.utils.compression.Jar.java
public void descomprimir(String lsDirDestino) { try {/*w w w. ja va2 s .c om*/ JarFile lzfFichero = new JarFile(isFicheroJar); Enumeration lenum = lzfFichero.entries(); JarArchiveEntry entrada = null; InputStream linput; for (; lenum.hasMoreElements(); linput.close()) { entrada = (JarArchiveEntry) lenum.nextElement(); linput = lzfFichero.getInputStream(entrada); byte labBytes[] = new byte[2048]; int liLeido = -1; String lsRutaDestino = lsDirDestino + File.separator + entrada.getName(); lsRutaDestino = lsRutaDestino.replace('\\', File.separatorChar); File lfRutaCompleta = new File(lsRutaDestino); String lsRuta = lfRutaCompleta.getAbsolutePath(); int liPosSeparator = lsRuta.lastIndexOf(File.separatorChar); lsRuta = lsRuta.substring(0, liPosSeparator); File ldDir = new File(lsRuta); boolean lbCreado = ldDir.mkdirs(); if (entrada.isDirectory()) { continue; } FileOutputStream loutput = new FileOutputStream(lfRutaCompleta); if (entrada.getSize() > 0L) { while ((liLeido = linput.read(labBytes, 0, 2048)) != -1) { loutput.write(labBytes, 0, liLeido); } } loutput.flush(); loutput.close(); } lzfFichero.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:es.jamisoft.comun.utils.compression.Jar.java
private void unjar(InputStream is, String outputDirectory) throws IOException { JarArchiveInputStream jis = new JarArchiveInputStream(is); JarArchiveEntry jarEntry = null; byte buffer[] = new byte[1024]; int readCount = 0; if (!outputDirectory.endsWith(File.separator)) { outputDirectory = outputDirectory + File.separator; }// w w w . j ava2 s. co m do { if ((jarEntry = jis.getNextJarEntry()) == null) { break; } if (jarEntry.isDirectory()) { File file = new File(outputDirectory + jarEntry.getName()); if (!file.exists()) { file.mkdir(); } } else { FileOutputStream fos = new FileOutputStream(outputDirectory + jarEntry.getName()); while ((readCount = jis.read(buffer)) != -1) { fos.write(buffer, 0, readCount); } fos.close(); } } while (true); jis.close(); }
From source file:divconq.mod.JarLibLoader.java
public JarLibLoader(String name) { super(name);/* w w w. j ava2s. com*/ JarArchiveInputStream stream = null; try { InputStream theFile = new FileInputStream(this.name); stream = new JarArchiveInputStream(theFile); JarArchiveEntry entry = stream.getNextJarEntry(); while (entry != null) { if (!entry.isDirectory()) { //if (entry.getName().endsWith("Container.class")) // System.out.println("at cont"); int esize = (int) entry.getSize(); if (esize > 0) { int eleft = esize; byte[] buff = new byte[esize]; int offset = 0; while (offset < esize) { int d = stream.read(buff, offset, eleft); offset += d; eleft -= d; } this.entries.put("/" + entry.getName(), buff); } } entry = stream.getNextJarEntry(); } } catch (Exception x) { // TODO logging System.out.println(x); } finally { try { if (stream != null) stream.close(); } catch (Exception x) { } } }
From source file:org.apache.openejb.maven.plugin.customizer.monkey.jar.JarPatcher.java
private int unjar(final File exploded, final File from) { int method = -1; JarArchiveInputStream stream = null; try {//from w w w .j a va2s . c o m stream = new JarArchiveInputStream(new FileInputStream(from)); JarArchiveEntry entry; while ((entry = stream.getNextJarEntry()) != null) { final File archiveEntry = new File(exploded, entry.getName()); archiveEntry.getParentFile().mkdirs(); if (entry.isDirectory()) { archiveEntry.mkdir(); continue; } final OutputStream out = new FileOutputStream(archiveEntry); IOUtils.copy(stream, out); out.close(); if (method < 0) { method = entry.getMethod(); } } } catch (final IOException e) { throw new IllegalArgumentException(e); } finally { IO.close(stream); } return method; }
From source file:org.apache.sysml.utils.lite.BuildLite.java
/** * Obtain a list of all classes in a jar file corresponding to a referenced * class.//from w w w .j a va 2 s . c om * * @param classInJarFile * @return list of all the commons-math3 classes in the referenced * commons-math3 jar file * @throws IOException * if an IOException occurs * @throws ClassNotFoundException * if a ClassNotFoundException occurs */ private static List<String> getAllClassesInJar(Class<?> classInJarFile) throws IOException, ClassNotFoundException { List<String> classPathNames = new ArrayList<>(); String jarLocation = classInJarFile.getProtectionDomain().getCodeSource().getLocation().getPath(); File f = new File(jarLocation); try (FileInputStream fis = new FileInputStream(f); JarArchiveInputStream jais = new JarArchiveInputStream(fis)) { while (true) { JarArchiveEntry jae = jais.getNextJarEntry(); if (jae == null) { break; } String name = jae.getName(); if (name.endsWith(".class")) { classPathNames.add(name); } } } String jarName = jarLocation.substring(jarLocation.lastIndexOf("/") + 1); addClassPathNamesToJarsAndClasses(jarName, classPathNames); return classPathNames; }
From source file:org.springframework.boot.loader.tools.JarWriter.java
/** * Perform the actual write of a {@link JarEntry}. All other write methods delegate to * this one.//w ww . j av a 2s . c om * @param entry the entry to write * @param entryWriter the entry writer or {@code null} if there is no content * @param unpackHandler handles possible unpacking for the entry * @throws IOException in case of I/O errors */ private void writeEntry(JarArchiveEntry entry, EntryWriter entryWriter, UnpackHandler unpackHandler) throws IOException { String parent = entry.getName(); if (parent.endsWith("/")) { parent = parent.substring(0, parent.length() - 1); entry.setUnixMode(UnixStat.DIR_FLAG | UnixStat.DEFAULT_DIR_PERM); } else { entry.setUnixMode(UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM); } if (parent.lastIndexOf('/') != -1) { parent = parent.substring(0, parent.lastIndexOf('/') + 1); if (!parent.isEmpty()) { writeEntry(new JarArchiveEntry(parent), null, unpackHandler); } } if (this.writtenEntries.add(entry.getName())) { entryWriter = addUnpackCommentIfNecessary(entry, entryWriter, unpackHandler); this.jarOutput.putArchiveEntry(entry); if (entryWriter != null) { entryWriter.write(this.jarOutput); } this.jarOutput.closeArchiveEntry(); } }
From source file:org.springframework.boot.loader.tools.JarWriter.java
private EntryWriter addUnpackCommentIfNecessary(JarArchiveEntry entry, EntryWriter entryWriter, UnpackHandler unpackHandler) throws IOException { if (entryWriter == null || !unpackHandler.requiresUnpack(entry.getName())) { return entryWriter; }/* w w w.j a v a 2 s . co m*/ ByteArrayOutputStream output = new ByteArrayOutputStream(); entryWriter.write(output); entry.setComment("UNPACK:" + unpackHandler.sha1Hash(entry.getName())); return new InputStreamEntryWriter(new ByteArrayInputStream(output.toByteArray()), true); }