List of usage examples for java.util.zip ZipEntry getName
public String getName()
From source file:com.joliciel.lefff.LefffMemoryLoader.java
public LefffMemoryBase deserializeMemoryBase(ZipInputStream zis) { LefffMemoryBase memoryBase = null;/*from w w w . j av a 2 s . c o m*/ MONITOR.startTask("deserializeMemoryBase"); try { ZipEntry zipEntry; if ((zipEntry = zis.getNextEntry()) != null) { LOG.debug("Scanning zip entry " + zipEntry.getName()); ObjectInputStream in = new ObjectInputStream(zis); memoryBase = (LefffMemoryBase) in.readObject(); zis.closeEntry(); in.close(); } else { throw new RuntimeException("No zip entry in input stream"); } } catch (IOException ioe) { throw new RuntimeException(ioe); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } finally { MONITOR.endTask("deserializeMemoryBase"); } Map<PosTagSet, LefffPosTagMapper> posTagMappers = memoryBase.getPosTagMappers(); PosTagSet posTagSet = posTagMappers.keySet().iterator().next(); memoryBase.setPosTagSet(posTagSet); return memoryBase; }
From source file:org.openmrs.module.clinicalsummary.io.UploadSummariesTask.java
/** * Method that will be called to process the summary collection file. The upload process will unpack the zipped collection of summary files and then * decrypt them.//from ww w. j av a 2s .c om * * @throws Exception */ protected void processSummaries() throws Exception { String zipFilename = StringUtils.join(Arrays.asList(filename, TaskConstants.FILE_TYPE_ZIP), "."); String encryptedFilename = StringUtils.join(Arrays.asList(filename, TaskConstants.FILE_TYPE_ENCRYPTED), "."); File file = new File(TaskUtils.getZippedOutputPath(), zipFilename); OutputStream outStream = new BufferedOutputStream(new FileOutputStream(file)); ZipFile encryptedFile = new ZipFile(new File(TaskUtils.getEncryptedOutputPath(), encryptedFilename)); Enumeration<? extends ZipEntry> entries = encryptedFile.entries(); while (entries.hasMoreElements()) { ZipEntry zipEntry = entries.nextElement(); String zipEntryName = zipEntry.getName(); if (!zipEntryName.endsWith(TaskConstants.FILE_TYPE_SAMPLE) && !zipEntryName.endsWith(TaskConstants.FILE_TYPE_SECRET)) { int count; byte[] data = new byte[TaskConstants.BUFFER_SIZE]; CipherInputStream zipCipherInputStream = new CipherInputStream( encryptedFile.getInputStream(zipEntry), cipher); while ((count = zipCipherInputStream.read(data, 0, TaskConstants.BUFFER_SIZE)) != -1) { outStream.write(data, 0, count); } zipCipherInputStream.close(); } } outStream.close(); File outputPath = TaskUtils.getSummaryOutputPath(); ZipFile zipFile = new ZipFile(file); Enumeration<? extends ZipEntry> zipEntries = zipFile.entries(); while (zipEntries.hasMoreElements()) { ZipEntry zipEntry = zipEntries.nextElement(); processedFilename = zipEntry.getName(); File f = new File(outputPath, zipEntry.getName()); // ensure that the parent path exists File parent = f.getParentFile(); if (parent.exists() || parent.mkdirs()) { FileCopyUtils.copy(zipFile.getInputStream(zipEntry), new BufferedOutputStream(new FileOutputStream(f))); } } }
From source file:com.joliciel.talismane.lexicon.LexiconDeserializer.java
public PosTaggerLexicon deserializeLexiconFile(ZipInputStream zis) { MONITOR.startTask("deserializeLexiconFile(ZipInputStream)"); try {//from w w w . j a va 2s .c om PosTaggerLexicon lexicon = null; try { ZipEntry zipEntry; if ((zipEntry = zis.getNextEntry()) != null) { LOG.debug("Scanning zip entry " + zipEntry.getName()); ObjectInputStream in = new ObjectInputStream(zis); lexicon = (PosTaggerLexicon) in.readObject(); zis.closeEntry(); in.close(); } else { throw new RuntimeException("No zip entry in input stream"); } } catch (IOException ioe) { throw new RuntimeException(ioe); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } return lexicon; } finally { MONITOR.endTask("deserializeLexiconFile(ZipInputStream)"); } }
From source file:de.shadowhunt.subversion.internal.AbstractHelper.java
private void extractArchive(final File zip, final File prefix) throws Exception { final ZipFile zipFile = new ZipFile(zip); final Enumeration<? extends ZipEntry> enu = zipFile.entries(); while (enu.hasMoreElements()) { final ZipEntry zipEntry = enu.nextElement(); final String name = zipEntry.getName(); final File file = new File(prefix, name); if (name.charAt(name.length() - 1) == Resource.SEPARATOR_CHAR) { if (!file.isDirectory() && !file.mkdirs()) { throw new IOException("can not create directory structure: " + file); }/* w ww .jav a 2 s . co m*/ continue; } final File parent = file.getParentFile(); if (parent != null) { if (!parent.isDirectory() && !parent.mkdirs()) { throw new IOException("can not create directory structure: " + parent); } } try (final InputStream is = zipFile.getInputStream(zipEntry)) { try (final OutputStream os = new FileOutputStream(file)) { IOUtils.copy(is, os); } } } zipFile.close(); }
From source file:com.sqli.liferay.imex.util.xml.ZipUtils.java
private void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException { if (entry.isDirectory()) { createDir(new File(outputDir, entry.getName())); return;//from w w w. jav a 2 s .com } File outputFile = new File(outputDir, entry.getName()); if (!outputFile.getParentFile().exists()) { createDir(outputFile.getParentFile()); } log.debug("Extracting: " + entry); BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry)); BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); try { IOUtils.copy(inputStream, outputStream); } finally { outputStream.close(); inputStream.close(); } }
From source file:coral.reef.web.FileUploadController.java
/** * Extracts a zip file specified by the zipFilePath to a directory specified * by destDirectory (will be created if does not exists) * /*w w w. j av a 2 s . c o m*/ * @param zipFilePath * @param destDirectory * @throws IOException */ public void unzip(InputStream zipFilePath, File destDir) throws IOException { if (!destDir.exists()) { destDir.mkdir(); } ZipInputStream zipIn = new ZipInputStream(zipFilePath); ZipEntry entry = zipIn.getNextEntry(); // iterates over entries in the zip file while (entry != null) { File filePath = new File(destDir, entry.getName()); if (!entry.isDirectory()) { // if the entry is a file, extracts it extractFile(zipIn, filePath); } else { // if the entry is a directory, make the directory filePath.mkdir(); } zipIn.closeEntry(); entry = zipIn.getNextEntry(); } zipIn.close(); }
From source file:com.izforge.izpack.compiler.helper.CompilerHelper.java
/** * Returns a list which contains the pathes of all files which are included in the given url. * This method expects as the url param a jar. * * @param url url of the jar file/*from www .j a v a 2s. c om*/ * @return full qualified paths of the contained files * @throws IOException if the jar cannot be read */ public List<String> getContainedFilePaths(URL url) throws IOException { JarInputStream jis = new JarInputStream(url.openStream()); ZipEntry zentry; ArrayList<String> fullNames = new ArrayList<String>(); while ((zentry = jis.getNextEntry()) != null) { String name = zentry.getName(); // Add only files, no directory entries. if (!zentry.isDirectory()) { fullNames.add(name); } } jis.close(); return (fullNames); }
From source file:com.camnter.patch.utils.classref.ClassReferenceListBuilder.java
public void run(String refClassName) throws IOException { classNames.add(refClassName);/*from www .j ava2 s .c om*/ while (true) { Set<String> temp = getUnAnalyzeClasses(); if (temp.isEmpty()) { break; } for (String tempName : temp) { alreadyAnalyzedClasses.add(tempName); refcname = tempName; // System.out.println("scan:---------->" + refcname); for (Enumeration<? extends ZipEntry> entries = jarOfRoots.entries(); entries.hasMoreElements();) { ZipEntry entry = entries.nextElement(); String name = entry.getName(); currentName = name; if (name.endsWith(CLASS_EXTENSION) && shouldScan(name)) { DirectClassFile classFile; try { classFile = path.getClass(name); } catch (FileNotFoundException e) { throw new IOException("Class " + name + " is missing form original class path " + path, e); } // System.out.println("=====classname:" + name); addDependencies(classFile.getConstantPool()); } } } } }
From source file:com.liferay.ide.server.remote.AbstractRemoteServerPublisher.java
protected void addRemoveProps(IPath deltaPath, IResource deltaResource, ZipOutputStream zip, Map<ZipEntry, String> deleteEntries, String deletePrefix) throws IOException { String archive = removeArchive(deltaPath.toPortableString()); ZipEntry zipEntry = null;//from w w w .j a v a 2 s . c o m // check to see if we already have an entry for this archive for (ZipEntry entry : deleteEntries.keySet()) { if (entry.getName().startsWith(archive)) { zipEntry = entry; } } if (zipEntry == null) { zipEntry = new ZipEntry(archive + "META-INF/" + deletePrefix + "-partialapp-delete.props"); //$NON-NLS-1$ //$NON-NLS-2$ } String existingFiles = deleteEntries.get(zipEntry); // String file = encodeRemovedPath(deltaPath.toPortableString().substring(archive.length())); String file = deltaPath.toPortableString().substring(archive.length()); if (deltaResource.getType() == IResource.FOLDER) { file += "/.*"; //$NON-NLS-1$ } deleteEntries.put(zipEntry, (existingFiles != null ? existingFiles : StringPool.EMPTY) + (file + "\n")); //$NON-NLS-1$ }
From source file:io.inkstand.deployment.staticcontent.ZipFileResource.java
@Override public List<Resource> list() { //this check is just for preventing the scan of the entire zip file //the method would return the same result without this check (equal_else mutant) //but without this check the list method could be an performance issue on zip //files with lots on entries if (!zipEntry.isDirectory()) { return Collections.emptyList(); }/*from www. ja v a 2s . c om*/ final List<Resource> resourceList = new ArrayList<>(); final Enumeration<? extends ZipEntry> entries = this.zipFile.entries(); final String rootEntryPath = zipEntry.getName(); while (entries.hasMoreElements()) { final ZipEntry entry = entries.nextElement(); final String entryPath = entry.getName(); //we make just a check for the base path. With this, all entries including those in the subdirectories //will be added too. One could consider this as a characteristic of a zip-file content store. If this //causes problems, this part should be improved with a more sophisticated logic if (!entryPath.equals(rootEntryPath) && entryPath.startsWith(rootEntryPath)) { resourceList.add(new ZipFileResource(this.zipFile, entry, entryPath)); } } return resourceList; }