List of usage examples for org.apache.commons.compress.archivers.jar JarArchiveEntry getSize
public long getSize()
From source file:divconq.mod.JarLibLoader.java
public JarLibLoader(String name) { super(name);//from w w w. java2s. 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:es.jamisoft.comun.utils.compression.Jar.java
public void descomprimir(String lsDirDestino) { try {/*from ww w. java 2s . c o 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(); } }