List of usage examples for java.util.zip ZipInputStream getNextEntry
public ZipEntry getNextEntry() throws IOException
From source file:gdt.data.entity.ArchiveHandler.java
private static boolean hasEntitiesDirInZipStream(ZipInputStream zis) { try {/*from ww w .java 2s . co m*/ ZipEntry entry = null; String entryName$; while ((entry = zis.getNextEntry()) != null) { entryName$ = entry.getName(); if (entryName$.startsWith(Entigrator.ENTITY_BASE)) { zis.close(); return true; } } zis.close(); return false; } catch (Exception e) { Logger.getLogger(ArchiveHandler.class.getName()).severe(e.toString()); return false; } }
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) * /*from w w w . ja v 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:jeffaschenk.tomcat.instance.generator.builders.TomcatInstanceBuilderHelper.java
/** * unZip Archive/*from ww w . j av a2 s. c o m*/ * * @param zipFilePath input zip file * @param outputFolder zip file output folder */ protected static void unZipArchive(GenerationLogger GENERATION_LOGGER, String zipFilePath, String outputFolder) throws IOException { /** * Create Output Directory, but should already Exist. */ File folder = new File(outputFolder); if (!folder.exists()) { folder.mkdir(); } ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath)); ZipEntry entry = zipIn.getNextEntry(); // iterates over entries in the zip file while (entry != null) { String filePath = outputFolder + File.separator + entry.getName(); if (!entry.isDirectory()) { // if the entry is a file, extracts it extractFile(GENERATION_LOGGER, zipIn, filePath); } else { // if the entry is a directory, make the directory File dir = new File(filePath); dir.mkdir(); } zipIn.closeEntry(); entry = zipIn.getNextEntry(); } zipIn.close(); }
From source file:com.thoughtworks.go.util.validators.ZipValidator.java
protected void unzip(ZipInputStream zipInputStream, File destDir) throws IOException { destDir.mkdirs();/*from w ww . ja va 2 s . co m*/ try { ZipEntry zipEntry = zipInputStream.getNextEntry(); while (zipEntry != null) { extractTo(zipEntry, zipInputStream, destDir); zipEntry = zipInputStream.getNextEntry(); } } finally { IOUtils.closeQuietly(zipInputStream); } }
From source file:com.joliciel.talismane.machineLearning.ExternalResourceFinderImpl.java
@Override public void addExternalResources(File externalResourceFile) { try {/* w w w . j a v a2 s .com*/ if (externalResourceFile.isDirectory()) { File[] files = externalResourceFile.listFiles(); for (File resourceFile : files) { LOG.debug("Reading " + resourceFile.getName()); if (resourceFile.getName().endsWith(".zip")) { ZipInputStream zis = new ZipInputStream(new FileInputStream(resourceFile)); zis.getNextEntry(); ObjectInputStream ois = new ObjectInputStream(zis); ExternalResource<?> externalResource = (ExternalResource<?>) ois.readObject(); this.addExternalResource(externalResource); } else { TextFileResource textFileResource = new TextFileResource(resourceFile); this.addExternalResource(textFileResource); } } } else { LOG.debug("Reading " + externalResourceFile.getName()); if (externalResourceFile.getName().endsWith(".zip")) { ZipInputStream zis = new ZipInputStream(new FileInputStream(externalResourceFile)); zis.getNextEntry(); ObjectInputStream ois = new ObjectInputStream(zis); ExternalResource<?> externalResource = (ExternalResource<?>) ois.readObject(); this.addExternalResource(externalResource); } else { TextFileResource textFileResource = new TextFileResource(externalResourceFile); this.addExternalResource(textFileResource); } } } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } catch (ClassNotFoundException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } }
From source file:com.engine.biomine.indexing.tasks.IndexDocsTask.java
private void processZipFile(File archiveFile, ZipInputStream zis) { try {/*www.ja v a 2s .c om*/ for (ZipEntry entry = zis.getNextEntry(); entry != null;) { if (!entry.isDirectory()) { File currentfile = IOUtil.getINSTANCE().retrieveCompressedFile(zis, entry.getName()); if (currentfile != null) { Runnable docThread = new DocThread(indexManager, monitor, currentfile, collection); exec.execute(docThread); } } entry = zis.getNextEntry(); } zis.close(); } catch (IOException e) { e.printStackTrace(); } logger.warn("Done reading file {}: . Sent to process.", archiveFile, monitor.getNbDocsToProcess()); }
From source file:com.marklogic.contentpump.ZipDelimitedJSONReader.java
protected boolean hasMoreEntryInZip() throws IOException { ByteArrayOutputStream byteArrayOStream; ZipInputStream zipIStream = (ZipInputStream) zipIn; while ((currZipEntry = zipIStream.getNextEntry()) != null) { if (LOG.isDebugEnabled()) { LOG.debug("ZipEntry: " + currZipEntry.getName()); }/*from w w w .j a v a 2 s. co m*/ if (currZipEntry.getSize() == 0) { continue; } subId = currZipEntry.getName(); long size = currZipEntry.getSize(); if (size == -1) { byteArrayOStream = new ByteArrayOutputStream(); } else { byteArrayOStream = new ByteArrayOutputStream((int) size); } int numOfBytes = -1; while ((numOfBytes = zipIStream.read(buf, 0, buf.length)) != -1) { byteArrayOStream.write(buf, 0, numOfBytes); } configFileNameAsCollection(conf, file); instream = new InputStreamReader(new ByteArrayInputStream(byteArrayOStream.toByteArray()), encoding); byteArrayOStream.close(); reader = new LineNumberReader(instream); return true; } return false; }
From source file:com.intuit.tank.agent.AgentStartup.java
public void run() { logger.info("Starting up..."); if (AmazonUtil.usingEip()) { try {/* ww w . j a va 2 s.c om*/ logger.info("Using EIP. Sleeping for " + WAIT_FOR_RESTART_TIME + " ms."); Thread.sleep(WAIT_FOR_RESTART_TIME); } catch (InterruptedException e1) { logger.info("Exception waiting."); System.exit(0); } } try { if (controllerBase == null) { controllerBase = AmazonUtil.getControllerBaseUrl(); } logger.info("Starting up: ControllerBaseUrl=" + controllerBase); URL url = new URL(controllerBase + SERVICE_RELATIVE_PATH + METHOD_SETTINGS); logger.info("Starting up: making call to tank service url to get settings.xml " + url.toExternalForm()); InputStream settingsStream = url.openStream(); try { String settings = IOUtils.toString(settingsStream); FileUtils.writeStringToFile(new File("settings.xml"), settings); logger.info("got settings file..."); } finally { IOUtils.closeQuietly(settingsStream); } url = new URL(controllerBase + SERVICE_RELATIVE_PATH + METHOD_SUPPORT); logger.info("Making call to tank service url to get support files " + url.toExternalForm()); ZipInputStream zip = new ZipInputStream(url.openStream()); try { ZipEntry entry = zip.getNextEntry(); while (entry != null) { String name = entry.getName(); logger.info("Got file from controller: " + name); File f = new File(name); FileOutputStream fout = FileUtils.openOutputStream(f); try { IOUtils.copy(zip, fout); } finally { IOUtils.closeQuietly(fout); } entry = zip.getNextEntry(); } } finally { IOUtils.closeQuietly(zip); } // now start the harness String jvmArgs = AmazonUtil.getUserDataAsMap().get(TankConstants.KEY_JVM_ARGS); logger.info("Starting apiharness with command: " + API_HARNESS_COMMAND + " -http=" + controllerBase + " " + jvmArgs); Runtime.getRuntime().exec(API_HARNESS_COMMAND + " -http=" + controllerBase + " " + jvmArgs); } catch (Exception e) { logger.error("Error in AgentStartup " + e, e); } }
From source file:eu.scape_project.up2ti.container.ZipContainer.java
/** * Extracts a zip file specified by the zipFilePath to a directory specified by * destDirectory (will be created if does not exists) * @param containerFileName// www . ja va2 s. c om * @param destDirectory * @throws IOException */ public void unzip(String containerFileName, InputStream containerFileStream) throws IOException { extractDirectoryName = "/tmp/up2ti_" + RandomStringUtils.randomAlphabetic(10) + "/"; File destDir = new File(extractDirectoryName); destDir.mkdir(); String subDestDirStr = extractDirectoryName + containerFileName + "/"; File subDestDir = new File(subDestDirStr); subDestDir.mkdir(); ZipInputStream zipIn = new ZipInputStream(containerFileStream); ZipEntry entry = zipIn.getNextEntry(); while (entry != null) { String filePath = subDestDirStr + entry.getName(); if (!entry.isDirectory()) { extractFile(zipIn, filePath); } else { File dir = new File(filePath); dir.mkdir(); } zipIn.closeEntry(); entry = zipIn.getNextEntry(); } zipIn.close(); }
From source file:be.fedict.eid.dss.document.zip.ZIPResourceResolver.java
private InputStream findZIPEntry(Attr dsReferenceUri) throws IOException { String entryName = dsReferenceUri.getValue(); ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(this.document)); ZipEntry zipEntry;/* ww w . ja v a 2 s. co m*/ while (null != (zipEntry = zipInputStream.getNextEntry())) { if (entryName.equals(zipEntry.getName())) { return zipInputStream; } } return null; }