List of usage examples for org.apache.commons.compress.archivers.jar JarArchiveEntry isDirectory
public boolean isDirectory()
From source file:divconq.mod.JarLibLoader.java
public JarLibLoader(String name) { super(name);//from w ww. j a v a2 s . 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:com.offbynull.coroutines.instrumenter.asm.FileSystemClassInformationRepository.java
private void addJar(File file) throws IOException { Validate.notNull(file);//from ww w . jav a2s . c o 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
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; }// ww w.j a v a2 s .c o 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:es.jamisoft.comun.utils.compression.Jar.java
public void descomprimir(String lsDirDestino) { try {/*w w w . jav a2 s .co m*/ 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: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 v a 2 s . 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; }