List of usage examples for java.util.zip ZipInputStream ZipInputStream
public ZipInputStream(InputStream in)
From source file:ZipTest.java
/** * Loads a file from the ZIP archive into the text area * @param name the name of the file in the archive */// www . java2 s. com public void loadZipFile(final String name) { fileCombo.setEnabled(false); fileText.setText(""); new SwingWorker<Void, Void>() { protected Void doInBackground() throws Exception { try { ZipInputStream zin = new ZipInputStream(new FileInputStream(zipname)); ZipEntry entry; // find entry with matching name in archive while ((entry = zin.getNextEntry()) != null) { if (entry.getName().equals(name)) { // read entry into text area Scanner in = new Scanner(zin); while (in.hasNextLine()) { fileText.append(in.nextLine()); fileText.append("\n"); } } zin.closeEntry(); } zin.close(); } catch (IOException e) { e.printStackTrace(); } return null; } protected void done() { fileCombo.setEnabled(true); } }.execute(); }
From source file:com.thoughtworks.go.util.ZipUtil.java
public void unzip(File zip, File destDir) throws IOException { unzip(new ZipInputStream(new BufferedInputStream(new FileInputStream(zip))), destDir); }
From source file:com.thoughtworks.go.server.service.plugins.AnalyticsPluginAssetsService.java
private void cacheStaticAssets(String pluginId) { LOGGER.info("Caching static assets for plugin: {}", pluginId); String data = this.analyticsExtension.getStaticAssets(pluginId); if (StringUtils.isBlank(data)) { LOGGER.info("No static assets found for plugin: {}", pluginId); return;//from w w w. jav a2 s . c om } try { byte[] payload = Base64.getDecoder().decode(data.getBytes()); byte[] pluginEndpointJsContent = IOUtils .toByteArray(getClass().getResourceAsStream("/" + PLUGIN_ENDPOINT_JS)); ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(payload)); String assetsHash = calculateHash(payload, pluginEndpointJsContent); String pluginAssetsRoot = currentAssetPath(pluginId, assetsHash); zipUtil.unzip(zipInputStream, new File(pluginAssetsRoot)); Files.write(Paths.get(pluginAssetsRoot, DESTINATION_JS), pluginEndpointJsContent); pluginAssetPaths.put(pluginId, Paths.get(pluginStaticAssetsPathRelativeToRailsPublicFolder(pluginId), assetsHash).toString()); } catch (Exception e) { LOGGER.error("Failed to extract static assets from plugin: {}", pluginId, e); ExceptionUtils.bomb(e); } }
From source file:at.ac.tuwien.auto.iotsys.gateway.connectors.knx.KNXDeviceLoaderETSImpl.java
public void unZip(String zipFile, String outputFolder) { byte[] buffer = new byte[1024]; try {// w w w. j av a2 s . co m File folder = new File(outputFolder); if (!folder.exists()) { folder.mkdir(); } ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile)); ZipEntry ze = zis.getNextEntry(); while (ze != null) { String fileName = ze.getName(); File newFile = new File(outputFolder + File.separator + fileName); log.info("file unzip : " + newFile.getAbsoluteFile()); new File(newFile.getParent()).mkdirs(); FileOutputStream fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:org.activiti.engine.impl.cfg.spring.ProcessEngineFactoryBean.java
private void deploy(DeploymentBuilder deploymentBuilder, Resource resource, String name) throws IOException { if (name.endsWith(".zip") || name.endsWith(".jar")) { deploymentBuilder.addZipInputStream(new ZipInputStream(resource.getInputStream())); } else {/*w w w . j a v a 2 s . co m*/ deploymentBuilder.addInputStream(name, resource.getInputStream()); } deploymentBuilder.deploy(); }
From source file:com.ikon.servlet.WorkflowRegisterServlet.java
@SuppressWarnings("unchecked") private String handleRequest(HttpServletRequest request) throws FileUploadException, IOException, Exception { log.debug("handleRequest({})", request); if (ServletFileUpload.isMultipartContent(request)) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = upload.parseRequest(request); if (items.isEmpty()) { String msg = "No process file in the request"; log.warn(msg);//from www. java 2 s.c o m return msg; } else { FileItem fileItem = (FileItem) items.get(0); if (fileItem.getContentType().indexOf("application/x-zip-compressed") == -1) { String msg = "Not a process archive"; log.warn(msg); throw new Exception(msg); } else { log.info("Deploying process archive: {}", fileItem.getName()); JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext(); InputStream isForms = null; ZipInputStream zis = null; try { zis = new ZipInputStream(fileItem.getInputStream()); ProcessDefinition processDefinition = ProcessDefinition.parseParZipInputStream(zis); // Check XML form definition FileDefinition fileDef = processDefinition.getFileDefinition(); isForms = fileDef.getInputStream("forms.xml"); FormUtils.parseWorkflowForms(isForms); log.debug("Created a processdefinition: {}", processDefinition.getName()); jbpmContext.deployProcessDefinition(processDefinition); return "Process " + processDefinition.getName() + " deployed successfully"; } finally { IOUtils.closeQuietly(isForms); IOUtils.closeQuietly(zis); jbpmContext.close(); } } } } else { log.warn("Not a multipart request"); return "Not a multipart request"; } }
From source file:com.adobe.aem.demomachine.communities.Loader.java
public static void main(String[] args) { String hostname = null;/*from www .ja va 2 s.c o m*/ String port = null; String altport = null; String csvfile = null; String analytics = null; String adminPassword = "admin"; boolean reset = false; boolean configure = false; boolean minimize = false; boolean noenablement = true; int maxretries = MAXRETRIES; // Command line options for this tool Options options = new Options(); options.addOption("h", true, "Hostname"); options.addOption("p", true, "Port"); options.addOption("a", true, "Alternate Port"); options.addOption("f", true, "CSV file"); options.addOption("r", false, "Reset"); options.addOption("u", true, "Admin Password"); options.addOption("c", false, "Configure"); options.addOption("m", false, "Minimize"); options.addOption("e", false, "No Enablement"); options.addOption("s", true, "Analytics Endpoint"); options.addOption("t", false, "Analytics"); options.addOption("w", false, "Retry"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { hostname = cmd.getOptionValue("h"); } if (cmd.hasOption("p")) { port = cmd.getOptionValue("p"); } if (cmd.hasOption("a")) { altport = cmd.getOptionValue("a"); } if (cmd.hasOption("f")) { csvfile = cmd.getOptionValue("f"); } if (cmd.hasOption("u")) { adminPassword = cmd.getOptionValue("u"); } if (cmd.hasOption("t")) { if (cmd.hasOption("s")) { analytics = cmd.getOptionValue("s"); } } if (cmd.hasOption("r")) { reset = true; } if (cmd.hasOption("w")) { maxretries = Integer.parseInt(cmd.getOptionValue("w")); } if (cmd.hasOption("c")) { configure = true; } if (cmd.hasOption("m")) { minimize = true; } if (cmd.hasOption("e")) { noenablement = false; } if (csvfile == null || port == null || hostname == null) { System.out.println( "Request parameters: -h hostname -p port -a alternateport -u adminPassword -f path_to_CSV_file -r (true|false, delete content before import) -c (true|false, post additional properties)"); System.exit(-1); } } catch (ParseException ex) { logger.error(ex.getMessage()); } logger.debug("AEM Demo Loader: Processing file " + csvfile); try { // Reading and processing the CSV file, stand alone or as part of a ZIP file if (csvfile != null && csvfile.toLowerCase().endsWith(".zip")) { ZipFile zipFile = new ZipFile(csvfile); ZipInputStream stream = new ZipInputStream(new FileInputStream(csvfile)); ZipEntry zipEntry; while ((zipEntry = stream.getNextEntry()) != null) { if (!zipEntry.isDirectory() && zipEntry.getName().toLowerCase().endsWith(".csv")) { InputStream is = zipFile.getInputStream(zipEntry); BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8")); processLoading(null, in, hostname, port, altport, adminPassword, analytics, reset, configure, minimize, noenablement, csvfile, maxretries); } } try { stream.close(); zipFile.close(); } catch (IOException ioex) { //omitted. } } else if (csvfile.toLowerCase().endsWith(".csv")) { Reader in = new FileReader(csvfile); processLoading(null, in, hostname, port, altport, adminPassword, analytics, reset, configure, minimize, noenablement, csvfile, maxretries); } } catch (IOException e) { logger.error(e.getMessage()); } }
From source file:aurelienribon.gdxsetupui.ProjectSetup.java
/** * The raw structure of all projects is contained in a zip file. This * method inflates this file in a temporary folder. * @throws IOException// w w w. ja va 2 s .co m */ public void inflateProjects() throws IOException { FileUtils.forceMkdir(tmpDst); FileUtils.cleanDirectory(tmpDst); InputStream is = Res.getStream("projects.zip"); ZipInputStream zis = new ZipInputStream(is); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { File file = new File(tmpDst, entry.getName()); if (entry.isDirectory()) { FileUtils.forceMkdir(file); } else { OutputStream os = new FileOutputStream(file); IOUtils.copy(zis, os); os.close(); } } zis.close(); }
From source file:it.geosolutions.tools.compress.file.Extractor.java
public static void unZip(File inputZipFile, File outputDir) throws IOException, CompressorException { if (inputZipFile == null || outputDir == null) { throw new CompressorException("Unzip: with null parameters"); }/*from ww w. java 2 s. c om*/ if (!outputDir.exists()) { if (!outputDir.mkdirs()) { throw new CompressorException("Unzip: Unable to create directory structure: " + outputDir); } } final int BUFFER = Conf.getBufferSize(); ZipInputStream zipInputStream = null; try { // Open Zip file for reading zipInputStream = new ZipInputStream(new FileInputStream(inputZipFile)); } catch (FileNotFoundException fnf) { throw new CompressorException("Unzip: Unable to find the input zip file named: " + inputZipFile); } // extract file if not a directory BufferedInputStream bis = new BufferedInputStream(zipInputStream); // grab a zip file entry ZipEntry entry = null; while ((entry = zipInputStream.getNextEntry()) != null) { // Process each entry File currentFile = new File(outputDir, entry.getName()); FileOutputStream fos = null; BufferedOutputStream dest = null; try { int currentByte; // establish buffer for writing file byte data[] = new byte[BUFFER]; // write the current file to disk fos = new FileOutputStream(currentFile); dest = new BufferedOutputStream(fos, BUFFER); // read and write until last byte is encountered while ((currentByte = bis.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, currentByte); } } catch (IOException ioe) { } finally { try { if (dest != null) { dest.flush(); dest.close(); } if (fos != null) fos.close(); } catch (IOException ioe) { throw new CompressorException( "Unzip: unable to close the zipInputStream: " + ioe.getLocalizedMessage()); } } } try { if (zipInputStream != null) zipInputStream.close(); } catch (IOException ioe) { throw new CompressorException( "Unzip: unable to close the zipInputStream: " + ioe.getLocalizedMessage()); } try { if (bis != null) bis.close(); } catch (IOException ioe) { throw new CompressorException( "Unzip: unable to close the Buffered zipInputStream: " + ioe.getLocalizedMessage()); } }
From source file:de.uni_hildesheim.sse.ant.versionReplacement.PluginVersionReplacer.java
/** * Unpacks an existing JAR/Zip archive./*from w w w . java 2 s .c om*/ * * @param zipFile The Archive file to unzip. * @param outputFolder The destination folder where the unzipped content shall be saved. * @see <a href="http://www.mkyong.com/java/how-to-decompress-files-from-a-zip-file/"> * http://www.mkyong.com/java/how-to-decompress-files-from-a-zip-file/</a> */ private static void unZipIt(File zipFile, File outputFolder) { byte[] buffer = new byte[1024]; try { // create output directory is not exists File folder = outputFolder; if (folder.exists()) { FileUtils.deleteDirectory(folder); } folder.mkdir(); // get the zip file content ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile)); // get the zipped file list entry ZipEntry ze = zis.getNextEntry(); while (ze != null) { String fileName = ze.getName(); File newFile = new File(outputFolder, fileName); // create all non exists folders // else you will hit FileNotFoundException for compressed folder new File(newFile.getParent()).mkdirs(); if (!ze.isDirectory()) { FileOutputStream fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); } ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); } catch (IOException ex) { ex.printStackTrace(); } }