List of usage examples for java.util.zip ZipInputStream closeEntry
public void closeEntry() throws IOException
From source file:com.joliciel.lefff.LefffMemoryLoader.java
public LefffMemoryBase deserializeMemoryBase(ZipInputStream zis) { LefffMemoryBase memoryBase = null;/* 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:com.hazelcast.stabilizer.Utils.java
public static void unzip(byte[] content, final File destinationDir) throws IOException { byte[] buffer = new byte[1024]; ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(content)); ZipEntry zipEntry = zis.getNextEntry(); while (zipEntry != null) { String fileName = zipEntry.getName(); File file = new File(destinationDir + File.separator + fileName); // log.finest("Unzipping: " + file.getAbsolutePath()); if (zipEntry.isDirectory()) { file.mkdirs();/*from w w w. j ava 2 s . c om*/ } else { file.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(file); try { int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } } finally { closeQuietly(fos); } } zipEntry = zis.getNextEntry(); } zis.closeEntry(); zis.close(); }
From source file:gov.va.chir.tagline.dao.FileDao.java
public static TagLineModel loadTagLineModel(final File file) throws Exception { final TagLineModel model = new TagLineModel(); // Unzip each file to temp final File temp = new File(System.getProperty("java.io.tmpdir")); byte[] buffer = new byte[BUFFER_SIZE]; final ZipInputStream zis = new ZipInputStream(new FileInputStream(file)); ZipEntry entry = zis.getNextEntry(); while (entry != null) { final String name = entry.getName(); File tempFile = new File(temp, name); // Write out file final FileOutputStream fos = new FileOutputStream(tempFile); int len;//from w w w. ja v a 2 s .c o m while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); // Determine which file was written if (name.equalsIgnoreCase(FILENAME_FEATURES)) { model.setFeatures(loadFeatures(tempFile)); } else if (name.equalsIgnoreCase(FILENAME_HEADER)) { model.setHeader(loadHeader(tempFile)); } else if (name.equalsIgnoreCase(FILENAME_MODEL)) { model.setModel(loadModel(tempFile)); } else { throw new IllegalStateException(String.format("Unknown file in TagLine model file (%s)", name)); } // Delete temp file tempFile.delete(); // Get next entry zis.closeEntry(); entry = zis.getNextEntry(); } zis.close(); return model; }
From source file:de.knowwe.revisions.upload.UploadRevisionZip.java
@SuppressWarnings("unchecked") @Override// ww w.jav a 2s. com public void execute(UserActionContext context) throws IOException { HashMap<String, String> pages = new HashMap<>(); List<FileItem> items = null; String zipname = null; try { items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(context.getRequest()); } catch (FileUploadException e) { throw new IOException("error during processing upload", e); } for (FileItem item : items) { zipname = item.getName(); InputStream filecontent = item.getInputStream(); ZipInputStream zin = new ZipInputStream(filecontent); ZipEntry ze; while ((ze = zin.getNextEntry()) != null) { String name = ze.getName(); if (!name.contains("/")) { // this is an article String title = Strings.decodeURL(name); title = title.substring(0, title.length() - 4); String content = IOUtils.toString(zin, "UTF-8"); zin.closeEntry(); pages.put(title, content); } else { // TODO: what to do here? // this is an attachment // String[] splittedName = name.split("/"); // String title = Strings.decodeURL(splittedName[0]); // String filename = Strings.decodeURL(splittedName[1]); // // System.out.println("Attachment: " + name); // String content = IOUtils.toString(zin, "UTF-8"); // Environment.getInstance().getWikiConnector().storeAttachment(title, // filename, // context.getUserName(), zin); zin.closeEntry(); } } zin.close(); filecontent.close(); } if (zipname != null) { UploadedRevision rev = new UploadedRevision(context.getWeb(), pages, zipname); RevisionManager.getRM(context).setUploadedRevision(rev); } context.sendRedirect("../Wiki.jsp?page=" + context.getTitle()); }
From source file:org.olat.ims.qti.qpool.ItemFileResourceValidator.java
public boolean validate(String filename, InputStream in) { boolean valid = false; if (filename.toLowerCase().endsWith(".xml")) { valid = validateXml(in);// w w w . j a v a2s . co m IOUtils.closeQuietly(in); } else if (filename.toLowerCase().endsWith(".zip")) { ZipInputStream oZip = new ZipInputStream(in); try { ZipEntry oEntr = oZip.getNextEntry(); while (oEntr != null) { if (!oEntr.isDirectory()) { if (validateXml(new ShieldInputStream(oZip))) { valid = true; } } oZip.closeEntry(); oEntr = oZip.getNextEntry(); } } catch (Exception e) { log.error("", e); valid = false; } finally { IOUtils.closeQuietly(oZip); IOUtils.closeQuietly(in); } } return valid; }
From source file:org.commonjava.indy.subsys.git.AbstractGitManagerTest.java
protected File unpackRepo(final String resource) throws Exception { final URL url = Thread.currentThread().getContextClassLoader().getResource(resource); final InputStream stream = url.openStream(); final ZipInputStream zstream = new ZipInputStream(stream); final File dir = temp.newFolder(); ZipEntry entry = null;/*from w ww. j a va2 s . c o m*/ while ((entry = zstream.getNextEntry()) != null) { final File f = new File(dir, entry.getName()); if (entry.isDirectory()) { f.mkdirs(); } else { f.getParentFile().mkdirs(); final OutputStream out = new FileOutputStream(f); copy(zstream, out); closeQuietly(out); } zstream.closeEntry(); } closeQuietly(zstream); final File root = new File(dir, "test-indy-data/.git"); assertThat(root.exists(), equalTo(true)); assertThat(root.isDirectory(), equalTo(true)); return root; }
From source file:com.joliciel.talismane.lexicon.LexiconDeserializer.java
public PosTaggerLexicon deserializeLexiconFile(ZipInputStream zis) { MONITOR.startTask("deserializeLexiconFile(ZipInputStream)"); try {/*from w ww . j a va2s.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:io.sledge.core.impl.extractor.SledgeApplicationPackageExtractor.java
@Override public String getEnvironmentFile(String environmentName, ApplicationPackage appPackage) { ZipInputStream zipStream = getNewUtf8ZipInputStream(appPackage); ByteArrayOutputStream output = new ByteArrayOutputStream(); try {/* ww w. j a va2 s .co m*/ byte[] buffer = new byte[2048]; ZipEntry zipEntry = null; while ((zipEntry = zipStream.getNextEntry()) != null) { if (zipEntry.isDirectory()) { zipStream.closeEntry(); continue; } if (getBaseName(zipEntry.getName()).equals(environmentName)) { int length; while ((length = zipStream.read(buffer, 0, buffer.length)) >= 0) { output.write(buffer, 0, length); } zipStream.closeEntry(); // Stop here because the file has been already read break; } } } catch (IOException e) { log.error(e.getMessage(), e); } finally { try { zipStream.close(); appPackage.getPackageFile().reset(); } catch (IOException e) { log.error(e.getMessage(), e); } } return output.toString(); }
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 a2 s.c om * @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:org.cloudfoundry.tools.io.zip.ZipArchiveTest.java
private List<String> getEntryNames(InputStream inputStream) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); FileCopyUtils.copy(inputStream, outputStream); ZipInputStream readInputStream = new ZipInputStream(new ByteArrayInputStream(outputStream.toByteArray())); List<String> entryNames = new ArrayList<String>(); ZipEntry entry = readInputStream.getNextEntry(); while (entry != null) { entryNames.add(entry.getName()); readInputStream.closeEntry(); entry = readInputStream.getNextEntry(); }// w ww . ja v a 2 s . c o m return entryNames; }