List of usage examples for java.util.zip ZipEntry getName
public String getName()
From source file:com.l2jfree.gameserver.script.ScriptPackage.java
/** * @param scriptFiles The scriptFiles to set. *///w w w . j a va 2 s.c om private void addFiles(ZipFile pack) { for (Enumeration<? extends ZipEntry> e = pack.entries(); e.hasMoreElements();) { ZipEntry entry = e.nextElement(); if (entry.getName().endsWith(".xml")) { try { ScriptDocument newScript = new ScriptDocument(entry.getName(), pack.getInputStream(entry)); _scriptFiles.add(newScript); } catch (IOException e1) { _log.error(e1.getMessage(), e1); } } else if (!entry.isDirectory()) { // ignore it } } }
From source file:com.github.ukase.toolkit.CompoundTemplateLoader.java
private void registerResource(ZipEntry entry) { resources.put(entry.getName(), entry); }
From source file:com.taobao.android.builder.tools.zip.ZipUtils.java
public static void rezip(File output, File srcDir, Map<String, ZipEntry> zipEntryMethodMap) throws Exception { if (output.isDirectory()) { throw new IOException("This is a directory!"); }/*w ww .j a v a2 s . c o m*/ if (!output.getParentFile().exists()) { output.getParentFile().mkdirs(); } if (!output.exists()) { output.createNewFile(); } List fileList = getSubFiles(srcDir); ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(output)); ZipEntry ze = null; byte[] buf = new byte[1024]; int readLen = 0; for (int i = 0; i < fileList.size(); i++) { File f = (File) fileList.get(i); ze = new ZipEntry(getAbsFileName(srcDir.getPath(), f)); ze.setSize(f.length()); ze.setTime(f.lastModified()); if (zipEntryMethodMap != null) { ZipEntry originEntry = zipEntryMethodMap.get(ze.getName()); if (originEntry != null) { if (originEntry.getMethod() == STORED) { ze.setCompressedSize(f.length()); InputStream in = new BufferedInputStream(new FileInputStream(f)); try { CRC32 crc = new CRC32(); int c; while ((c = in.read()) != -1) { crc.update(c); } ze.setCrc(crc.getValue()); } finally { in.close(); } } ze.setMethod(originEntry.getMethod()); } } zos.putNextEntry(ze); InputStream is = new BufferedInputStream(new FileInputStream(f)); while ((readLen = is.read(buf, 0, 1024)) != -1) { zos.write(buf, 0, readLen); } is.close(); } zos.close(); }
From source file:dk.deck.resolver.util.ZipUtils.java
public List<String> listArchive(File archive) { List<String> paths = new ArrayList<String>(); try {//from ww w . j a va2 s . co m ZipFile zipfile = new ZipFile(archive); for (Enumeration e = zipfile.entries(); e.hasMoreElements();) { ZipEntry entry = (ZipEntry) e.nextElement(); paths.add(entry.getName()); } zipfile.close(); } catch (Exception e) { log.error("Error while extracting file " + archive, e); } return paths; }
From source file:com.alibaba.jstorm.yarn.utils.JStormUtils.java
/** * Extra dir from the jar to destdir//from w w w. j a v a2 s . co m * * @param jarpath * @param dir * @param destdir */ public static void extractDirFromJar(String jarpath, String dir, String destdir) { ZipFile zipFile = null; try { zipFile = new ZipFile(jarpath); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries != null && entries.hasMoreElements()) { ZipEntry ze = entries.nextElement(); if (!ze.isDirectory() && ze.getName().startsWith(dir)) { InputStream in = zipFile.getInputStream(ze); try { File file = new File(destdir, ze.getName()); if (!file.getParentFile().mkdirs()) { if (!file.getParentFile().isDirectory()) { throw new IOException("Mkdirs failed to create " + file.getParentFile().toString()); } } OutputStream out = new FileOutputStream(file); try { byte[] buffer = new byte[8192]; int i; while ((i = in.read(buffer)) != -1) { out.write(buffer, 0, i); } } finally { out.close(); } } finally { if (in != null) in.close(); } } } } catch (Exception e) { LOG.warn("No " + dir + " from " + jarpath + "!\n" + e.getMessage()); } finally { if (zipFile != null) try { zipFile.close(); } catch (Exception e) { LOG.warn(e.getMessage()); } } }
From source file:ZipFileViewer.java
public Object getValueAt(int row, int col) { ZipEntry zipEntry = (ZipEntry) (m_zipEntries.get(row)); switch (col) { case NAME:/* ww w . j ava2 s. co m*/ return zipEntry.getName(); case SIZE: if (zipEntry.isDirectory()) { return ""; } else { return String.valueOf(zipEntry.getSize() / 1000) + " KB"; } case COMP_SIZE: if (zipEntry.isDirectory()) { return ""; } else { return String.valueOf(zipEntry.getCompressedSize() / 1000) + " KB"; } case TYPE: if (zipEntry.isDirectory()) { return "Directory"; } else { return "File"; } case LAST_MODI: return String.valueOf(new Date(zipEntry.getTime())); } return new String(); }
From source file:eu.europa.ec.markt.dss.validation.SignedDocumentValidator.java
private static SignedDocumentValidator getInstanceForAsics(Document document) throws IOException { ZipInputStream asics = new ZipInputStream(document.openStream()); try {/*w w w. j a va 2s . c om*/ ByteArrayOutputStream datafile = null; ByteArrayOutputStream signatures = null; ZipEntry entry; boolean cadesSigned = false; boolean xadesSigned = false; while ((entry = asics.getNextEntry()) != null) { if (entry.getName().equalsIgnoreCase(SIGNATURES_P7S)) { if (xadesSigned) { throw new NotETSICompliantException(MSG.MORE_THAN_ONE_SIGNATURE); } signatures = new ByteArrayOutputStream(); IOUtils.copy(asics, signatures); signatures.close(); cadesSigned = true; } else if (entry.getName().equalsIgnoreCase(SIGNATURES_XML)) { if (cadesSigned) { throw new NotETSICompliantException(MSG.MORE_THAN_ONE_SIGNATURE); } signatures = new ByteArrayOutputStream(); IOUtils.copy(asics, signatures); signatures.close(); xadesSigned = true; } else if (entry.getName().equalsIgnoreCase(MIMETYPE)) { ByteArrayOutputStream mimetype = new ByteArrayOutputStream(); IOUtils.copy(asics, mimetype); mimetype.close(); if (!Arrays.equals(mimetype.toByteArray(), MIMETYPE_ASIC_S.getBytes())) { throw new NotETSICompliantException(MSG.UNRECOGNIZED_TAG); } } else if (entry.getName().indexOf("/") == -1) { if (datafile == null) { datafile = new ByteArrayOutputStream(); IOUtils.copy(asics, datafile); datafile.close(); } else { throw new ProfileException("ASiC-S profile support only one data file"); } } } if (xadesSigned) { ASiCXMLDocumentValidator xmlValidator = new ASiCXMLDocumentValidator( new InMemoryDocument(signatures.toByteArray()), datafile.toByteArray()); return xmlValidator; } else if (cadesSigned) { CMSDocumentValidator pdfValidator = new CMSDocumentValidator( new InMemoryDocument(signatures.toByteArray())); pdfValidator.setExternalContent(new InMemoryDocument(datafile.toByteArray())); return pdfValidator; } else { throw new RuntimeException("Is not xades nor cades signed"); } } catch (Exception ex) { throw new RuntimeException(ex); } finally { try { asics.close(); } catch (IOException e) { } } }
From source file:com.fluidops.iwb.cms.fs.ArchiveFile.java
@Override public File[] listFiles() { List<File> res = new ArrayList<File>(); Enumeration<? extends ZipEntry> e = zip.entries(); while (e.hasMoreElements()) { ZipEntry entry = e.nextElement(); if (entry.getName().startsWith(path)) { String rest = entry.getName().substring(path.length()); if (rest.startsWith("/")) rest = rest.substring(1); if (rest.endsWith("/")) rest = rest.substring(0, rest.length() - 1); if (!rest.isEmpty() && !rest.contains("/")) res.add(new ArchiveFile(zip, entry.getName())); }//from w ww . java 2s.c o m } return res.toArray(new File[0]); }
From source file:com.s2g.pst.resume.importer.UnZipHelper.java
/** * Unzip it/* ww w . j av a2 s. c o m*/ * * @param fileName * @param outputFolder * * @throws java.io.FileNotFoundException */ public void unZipFolder(String fileName, String outputFolder) throws IOException { ZipFile zipFile = new ZipFile(fileName); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File entryDestination = new File(outputFolder, entry.getName()); entryDestination.getParentFile().mkdirs(); if (entry.isDirectory()) { //FileHelper fileHelper = new FileHelper(); //String filename = fileHelper.getUniqueFileName(outputFolder, FilenameUtils.removeExtension(entry.getName())); //System.out.println("zip :" + filename); //new File(filename).mkdirs(); entryDestination.mkdirs(); } else { InputStream in = zipFile.getInputStream(entry); OutputStream out = new FileOutputStream(entryDestination); IOUtils.copy(in, out); IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } } zipFile.close(); this.deleteZipFile(fileName); System.out.println("Done"); }
From source file:com.jivesoftware.os.routing.bird.endpoints.base.LocateStringResource.java
String getStringResource() { Map<String, Long> htSizes = new HashMap<>(); try {/*from ww w . j a v a2s.c om*/ try (final ZipFile zf = new ZipFile(jarFileName)) { Enumeration<? extends ZipEntry> e = zf.entries(); while (e.hasMoreElements()) { ZipEntry ze = e.nextElement(); if (!ze.getName().equals(resourceName)) { continue; } htSizes.put(ze.getName(), ze.getSize()); } } // extract resources and put them into the hashtable. FileInputStream fis = new FileInputStream(jarFileName); BufferedInputStream bis = new BufferedInputStream(fis); try (final ZipInputStream zis = new ZipInputStream(bis)) { ZipEntry ze; while ((ze = zis.getNextEntry()) != null) { if (!ze.getName().equals(resourceName)) { continue; } if (ze.isDirectory()) { continue; } int size = (int) ze.getSize(); // -1 means unknown size. if (size == -1) { size = htSizes.get(ze.getName()).intValue(); } byte[] b = new byte[size]; int rb = 0; int chunk = 0; while ((size - rb) > 0) { chunk = zis.read(b, rb, size - rb); if (chunk == -1) { break; } rb += chunk; } InputStream inputStream = new ByteArrayInputStream(b); StringWriter writer = new StringWriter(); IOUtils.copy(inputStream, writer, "UTF-8"); return writer.toString(); } } } catch (Exception e) { LOG.warn("Failed to locate " + resourceName, e); } return null; }