List of usage examples for java.util.zip ZipInputStream close
public void close() throws IOException
From source file:org.apache.atlas.repository.impexp.ZipSource.java
private void updateGuidZipEntryMap() throws IOException { ZipInputStream zipInputStream = new ZipInputStream(inputStream); ZipEntry zipEntry = zipInputStream.getNextEntry(); while (zipEntry != null) { String entryName = zipEntry.getName().replace(".json", ""); if (guidEntityJsonMap.containsKey(entryName)) continue; byte[] buf = new byte[1024]; int n = 0; ByteArrayOutputStream bos = new ByteArrayOutputStream(); while ((n = zipInputStream.read(buf, 0, 1024)) > -1) { bos.write(buf, 0, n);//from w ww . j a v a 2 s .c o m } guidEntityJsonMap.put(entryName, bos.toString()); zipEntry = zipInputStream.getNextEntry(); } zipInputStream.close(); }
From source file:org.jahia.utils.maven.plugin.CopyJahiaWarMojo.java
@SuppressWarnings("unchecked") public void execute() throws MojoExecutionException, MojoFailureException { for (Artifact dependencyFile : (Iterable<Artifact>) project.getDependencyArtifacts()) { if ("org.jahia.server".equals(dependencyFile.getGroupId()) && "jahia-war".equals(dependencyFile.getArtifactId())) { try { File webappDir = new File(output, "config/WEB-INF/jahia"); ZipInputStream z = new ZipInputStream(new FileInputStream(dependencyFile.getFile())); ZipEntry entry;/*from w ww .ja v a 2 s.co m*/ int cnt = 0; while ((entry = z.getNextEntry()) != null) { if (!entry.isDirectory()) { File target = new File(webappDir, entry.getName()); if (entry.getTime() > target.lastModified()) { target.getParentFile().mkdirs(); FileOutputStream fileOutputStream = new FileOutputStream(target); IOUtils.copy(z, fileOutputStream); fileOutputStream.close(); cnt++; } } } z.close(); getLog().info("Copied " + cnt + " files."); } catch (IOException e) { getLog().error("Error when copying file"); } } } }
From source file:org.eclipse.data.sampledb.SampledbActivator.java
/** * Initialization for first time startup in this instance of JVM *///ww w . j a va 2 s .co m private void init() throws IOException { assert dbDir == null; // Create and remember our private directory under system temp // Name it "BIRTSampleDB_$timestamp$_$classinstanceid$" String tempDir = System.getProperty("java.io.tmpdir"); String timeStamp = String.valueOf(System.currentTimeMillis()); String instanceId = Integer.toHexString(hashCode()); dbDir = tempDir + "/BIRTSampleDB_" + timeStamp + "_" + instanceId; LOGGER.debug("Creating Sampledb database at location " + dbDir); (new File(dbDir)).mkdir(); // Set up private copy of Sample DB in system temp directory // Get an input stream to read DB Jar file // handle getting db jar file on both OSGi and OSGi-less platforms String dbEntryName = SAMPLE_DB_HOME_DIR + FILE_DELIM + SAMPLE_DB_JAR_FILE; URL fileURL = SampledbActivator.class.getResource(dbEntryName); if (fileURL == null) { fileURL = this.getClass().getClassLoader().getResource(dbEntryName); if (fileURL == null) { String errMsg = "INTERNAL ERROR: SampleDB DB file not found: " + dbEntryName; LOGGER.error(errMsg); throw new RuntimeException(errMsg); } } // Copy entries in the DB jar file to corresponding location in db dir InputStream dbFileStream = new BufferedInputStream(fileURL.openStream()); ZipInputStream zipStream = new ZipInputStream(dbFileStream); ZipEntry entry; while ((entry = zipStream.getNextEntry()) != null) { File entryFile = new File(dbDir, entry.getName()); if (entry.isDirectory()) { entryFile.mkdir(); } else { // Copy zip entry to local file OutputStream os = new FileOutputStream(entryFile); byte[] buf = new byte[4000]; int len; while ((len = zipStream.read(buf)) > 0) { os.write(buf, 0, len); } os.close(); } } zipStream.close(); dbFileStream.close(); }
From source file:com.moss.fskit.Unzipper.java
public boolean isDirectoryWrapper(File zipFile) throws UnzipException { try {// ww w .j a v a 2 s . com ZipInputStream in = new ZipInputStream(new FileInputStream(zipFile)); boolean firstEntryWasDirectory = false; int numEntries = 0; for (ZipEntry entry = in.getNextEntry(); entry != null; entry = in.getNextEntry()) { String name = entry.getName().trim(); if (name.startsWith("/")) name = name.substring(1); if (name.endsWith("/")) name = name.substring(0, name.length() - 2); if (name.indexOf('/') == -1) { // This is at the 'root' level. numEntries++; if (numEntries == 1 && entry.isDirectory()) { firstEntryWasDirectory = true; } } } in.close(); return (numEntries == 1) && firstEntryWasDirectory; } catch (IOException e) { throw new UnzipException("Error processing " + zipFile.getAbsolutePath(), e); } }
From source file:net.famzangl.minecraft.minebot.settings.MinebotDirectoryCreator.java
public File createDirectory(File dir) throws IOException { CodeSource src = MinebotDirectoryCreator.class.getProtectionDomain().getCodeSource(); if (src != null) { URL jar = src.getLocation(); if (jar.getFile().endsWith("class") && !jar.getFile().contains(".jar!")) { System.out.println("WARNING: Using the dev directory for settings."); // We are in a dev enviroment. return new File(new File(jar.getFile()).getParentFile(), "minebot"); }/*from w w w .j a va 2 s . c o m*/ if (dir.isFile()) { dir.delete(); } dir.mkdirs(); ZipInputStream zip = new ZipInputStream(jar.openStream()); try { ZipEntry zipEntry; while ((zipEntry = zip.getNextEntry()) != null) { String name = zipEntry.getName(); if (name.startsWith(BASE)) { String[] localName = name.substring(BASE.length()).split("/"); File currentDir = dir; for (int i = 0; i < localName.length; i++) { currentDir = new File(currentDir, localName[i]); currentDir.mkdir(); } File copyTo = new File(currentDir, localName[localName.length - 1]); extract(zip, copyTo); } } } finally { zip.close(); } return dir; } else { throw new IOException("Could not find minebot directory to extract."); } }
From source file:org.flowable.ui.admin.service.engine.DeploymentService.java
protected JsonNode getAppDefinitionJson(ByteArrayInputStream bais) throws IOException { ZipInputStream zipIS = new ZipInputStream(bais); ZipEntry entry;/*from w ww.ja va 2s . c o m*/ JsonNode appDefinitionJson = null; while ((entry = zipIS.getNextEntry()) != null) { // check if entry is app definition if (entry.getName() != null && entry.getName().endsWith(".app")) { BufferedReader reader = new BufferedReader(new InputStreamReader(zipIS)); String line = ""; StringBuilder js = new StringBuilder(); while ((line = reader.readLine()) != null) { js.append(line).append("\n"); } String json = js.toString(); appDefinitionJson = objectMapper.readTree(json); reader.close(); break; } } zipIS.close(); return appDefinitionJson; }
From source file:org.eclipse.swordfish.p2.internal.deploy.server.RepositoryManager.java
private final File unzip(String iu, InputStream repoZipStream) throws IOException { File tempDir = new File(System.getProperty("java.io.tmpdir"), iu + "_" + new java.util.Random().nextInt()); tempDir.mkdir();/*from w w w. ja va 2 s. c om*/ tempDir.deleteOnExit(); ZipInputStream zin = new ZipInputStream(repoZipStream); ZipEntry ze = null; int extracted = 0; while ((ze = zin.getNextEntry()) != null) { File outFile = new File(tempDir.getCanonicalPath(), ze.getName()); if (ze.isDirectory()) { if (!outFile.exists()) { outFile.mkdir(); outFile.deleteOnExit(); extracted++; } } else { FileOutputStream fout = new FileOutputStream(outFile); outFile.deleteOnExit(); for (int c = zin.read(); c != -1; c = zin.read()) { fout.write(c); } fout.close(); extracted++; } zin.closeEntry(); } zin.close(); if (extracted == 0) { throw new IOException("Empty or invalid archive."); } return tempDir; }
From source file:io.sledge.core.impl.extractor.SledgeApplicationPackageExtractor.java
@Override public List<String> getEnvironmentNames(ApplicationPackage appPackage) { List<String> envFiles = new ArrayList<>(); ZipInputStream zipStream = getNewUtf8ZipInputStream(appPackage); try {/*ww w . j a v a 2 s .c o m*/ ZipEntry zipEntry = null; while ((zipEntry = zipStream.getNextEntry()) != null) { if (zipEntry.isDirectory()) { zipStream.closeEntry(); continue; } if (zipEntry.getName().startsWith("environments/")) { // test-publish.properties -> test-publish envFiles.add(getBaseName(zipEntry.getName())); zipStream.closeEntry(); } } } catch (IOException e) { log.error(e.getMessage(), e); } finally { try { zipStream.close(); appPackage.getPackageFile().reset(); } catch (IOException e) { log.error(e.getMessage(), e); } } return envFiles; }
From source file:org.adl.samplerte.server.LMSPackageHandler.java
/**************************************************************************** ** ** Method: extract()//from ww w.j a v a 2s .c o m ** Input: String zipFileName -- The name of the zip file to be used ** Sting extractedFile -- The name of the file to be extracted ** from the zip ** Output: none ** ** Description: This method takes in the name of a zip file and a file to ** be extracted from the zip format. The method locates the ** file and extracts into the '.' directory. ** *****************************************************************************/ public static String extract(String zipFileName, String extractedFile, String pathOfExtract) { if (_Debug) { System.out.println("***********************"); System.out.println("in extract() "); System.out.println("***********************"); System.out.println("zip file: " + zipFileName); System.out.println("file to extract: " + extractedFile); } String nameOfExtractedFile = new String(""); System.out.println("-----LMSPackageHandler-extract()----"); System.out.println("zipFileName=" + zipFileName); System.out.println("extractedFile=" + extractedFile); System.out.println("pathOfExtract=" + pathOfExtract); try { String pathAndName = new String(""); int index = zipFileName.lastIndexOf("\\") + 1; zipFileName = zipFileName.substring(index); System.out.println("---zipFileName=" + zipFileName); // Input stream for the zip file (package) ZipInputStream in = new ZipInputStream(new FileInputStream(pathOfExtract + "\\" + zipFileName)); // Cut the path off of the name of the file. (for writing the file) int indexOfFileBeginning = extractedFile.lastIndexOf("/") + 1; System.out.println("---indexOfFileBeginning=" + indexOfFileBeginning); nameOfExtractedFile = extractedFile.substring(indexOfFileBeginning); System.out.println("---nameOfExtractedFile=" + nameOfExtractedFile); pathAndName = pathOfExtract + "\\" + nameOfExtractedFile; System.out.println("pathAndName=" + pathAndName); // Ouput stream for the extracted file //************************************* //************************************* OutputStream out = new FileOutputStream(pathAndName); //OutputStream out = new FileOutputStream(nameOfExtractedFile); ZipEntry entry; byte[] buf = new byte[1024]; int len; int flag = 0; while (flag != 1) { entry = in.getNextEntry(); if ((entry.getName()).equalsIgnoreCase(extractedFile)) { if (_Debug) { System.out.println("Found file to extract... extracting to " + pathOfExtract); } flag = 1; } } while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.close(); in.close(); } catch (IOException e) { if (_Debug) { System.out.println("IO Exception Caught: " + e); } e.printStackTrace(); } return nameOfExtractedFile; }