List of usage examples for java.util.zip ZipInputStream read
public int read(byte b[]) throws IOException
b.length
bytes of data from this input stream into an array of bytes. From source file:com.yifanlu.PSXperiaTool.Extractor.CrashBandicootExtractor.java
private void extractZip(File zipFile, File output, FileFilter filter) throws IOException { Logger.info("Extracting ZIP file: %s to: %s", zipFile.getPath(), output.getPath()); if (!output.exists()) output.mkdirs();/*from w w w. ja va 2 s.co m*/ ZipInputStream zip = new ZipInputStream(new FileInputStream(zipFile)); ZipEntry entry; while ((entry = zip.getNextEntry()) != null) { File file = new File(output, entry.getName()); if (file.isDirectory()) continue; if (filter != null && !filter.accept(file)) continue; Logger.verbose("Unzipping %s", entry.getName()); FileUtils.touch(file); FileOutputStream out = new FileOutputStream(file.getPath()); int n; byte[] buffer = new byte[BLOCK_SIZE]; while ((n = zip.read(buffer)) != -1) { out.write(buffer, 0, n); } out.close(); zip.closeEntry(); Logger.verbose("Done extracting %s", entry.getName()); } zip.close(); Logger.debug("Done extracting ZIP."); }
From source file:org.openbaton.tosca.parser.CSARParser.java
private void readFiles(InputStream csar_file) throws IOException, NotFoundException { ZipInputStream zipStream = new ZipInputStream(csar_file); ZipEntry entry;//from www . jav a 2 s . c o m this.scripts.clear(); this.folderNames.clear(); this.template = new ByteArrayOutputStream(); this.metadata = new ByteArrayOutputStream(); while ((entry = zipStream.getNextEntry()) != null) { if (!entry.isDirectory()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int count; byte[] buffer = new byte[1024]; while ((count = zipStream.read(buffer)) != -1) { baos.write(buffer, 0, count); } String fileName = entry.getName(); if (fileName.toLowerCase().endsWith(".meta")) { this.metadata = baos; } else if (fileName.toLowerCase().endsWith(".yaml")) { if (fileName.toLowerCase().endsWith("metadata.yaml")) { this.vnfMetadata = baos; } else { this.template = baos; } } else { Script script = new Script(); String[] splittedName = fileName.split("/"); if (splittedName.length > 2) { String scriptName = splittedName[1] + "!_!" + splittedName[splittedName.length - 1]; folderNames.add(splittedName[1]); script.setName(scriptName); } else script.setName(splittedName[splittedName.length - 1]); script.setPayload(baos.toByteArray()); this.scripts.add(script); } } } if (this.metadata == null) { throw new NotFoundException("CSARParser: Not found TOSCA.meta"); } if (this.vnfMetadata == null) { throw new NotFoundException("CSARParser: Not found Metadata.yaml"); } if (this.template == null) { throw new NotFoundException("CSARParser: Not found VNFD / NSD Template"); } //zipStream.close(); }
From source file:org.martin.ftp.net.FTPLinker.java
private void extractFile(FileOutputStream fos, ZipEntry entry, int ready, byte[] buffer, ZipInputStream zis) throws FileNotFoundException, IOException { fos = new FileOutputStream(entry.getName()); ready = 0;//from w w w .j a va2 s.c o m buffer = new byte[1024]; while ((ready = zis.read(buffer)) > 0) fos.write(buffer, 0, ready); fos.close(); zis.closeEntry(); }
From source file:gov.pnnl.goss.gridappsd.app.AppManagerImpl.java
private void extractFile(ZipInputStream zipIn, String filePath) throws IOException { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); byte[] bytesIn = new byte[BUFFER_SIZE]; int read = 0; while ((read = zipIn.read(bytesIn)) != -1) { bos.write(bytesIn, 0, read);//from www.j a v a2s.co m } bos.close(); }
From source file:dpfmanager.shell.modules.report.core.ReportGenerator.java
/** * Extracts a zip entry (file entry).//w w w . ja v a 2 s . c o m * * @param zipIn the zip input stream * @param filePath the file path * @throws IOException exception */ private void extractFile(ZipInputStream zipIn, String filePath) throws IOException { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); byte[] bytesIn = new byte[4096]; int read = 0; while ((read = zipIn.read(bytesIn)) != -1) { bos.write(bytesIn, 0, read); } bos.close(); }
From source file:org.pentaho.di.core.market.Market.java
/** * Unzips the plugin to the file system The passed MarkeyEntry has the URL of the zip file. * /* w w w . j a v a2 s. c o m*/ * @param folderName * @param marketEntry * @throws KettleException */ private static void unzipMarketEntry(String folderName, String packageUrl) throws KettleException { // Copy the file locally first // File tmpFile = null; InputStream inputStream = null; ZipInputStream zis = null; try { tmpFile = File.createTempFile("plugin", ".zip"); org.apache.commons.io.FileUtils.copyURLToFile(new URL(packageUrl), tmpFile); // Read the package, extract in folder // inputStream = new FileInputStream(tmpFile); zis = new ZipInputStream(inputStream); ZipEntry zipEntry = null; try { zipEntry = zis.getNextEntry(); } catch (IOException ioe) { throw new KettleException(ioe); } byte[] buffer = new byte[1024]; int bytesRead = 0; FileOutputStream fos = null; while (zipEntry != null) { try { File file = new File(folderName + File.separator + zipEntry.getName()); if (zipEntry.isDirectory()) { file.mkdirs(); } else { file.getParentFile().mkdirs(); fos = new FileOutputStream(file); while ((bytesRead = zis.read(buffer)) != -1) { fos.write(buffer, 0, bytesRead); } } zipEntry = zis.getNextEntry(); } catch (FileNotFoundException fnfe) { throw new KettleException(fnfe); } catch (IOException ioe) { throw new KettleException(ioe); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { // Ignore. } } } } } catch (IOException e) { throw new KettleException("Unable to unzip file " + packageUrl, e); } finally { if (zis != null) { tmpFile.delete(); try { zis.close(); } catch (Exception e) { throw new KettleException("Unable to close zip file stream (corrupt file?) of file " + tmpFile, e); } } } }
From source file:com.nkapps.billing.services.BankStatementServiceImpl.java
@Override public File extractedFile(File file) throws Exception { File extractedFile = null;//from w w w .j a v a 2s .co m byte[] buffer = new byte[1024]; ZipInputStream zis = new ZipInputStream(new FileInputStream(file)); ZipEntry ze = zis.getNextEntry(); while (ze != null) { String extFileName = ze.getName(); extractedFile = new File(getUploadDir() + File.separator + extFileName); if (!extractedFile.exists()) { extractedFile.createNewFile(); } FileOutputStream fos = new FileOutputStream(extractedFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); return extractedFile; }
From source file:com.taobao.android.tpatch.utils.JarSplitUtils.java
/** * 2jar?,??jar//w ww . ja v a 2 s. c o m * @param baseJar * @param diffJar * @param outJar */ public static void unionJar(File baseJar, File diffJar, File outJar) throws IOException { File outParentFolder = outJar.getParentFile(); if (!outParentFolder.exists()) { outParentFolder.mkdirs(); } List<String> diffEntries = getZipEntries(diffJar); FileOutputStream fos = new FileOutputStream(outJar); ZipOutputStream jos = new ZipOutputStream(fos); final byte[] buffer = new byte[8192]; FileInputStream fis = new FileInputStream(baseJar); ZipInputStream zis = new ZipInputStream(fis); try { // loop on the entries of the jar file package and put them in the final jar ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { // do not take directories or anything inside a potential META-INF folder. if (entry.isDirectory()) { continue; } String name = entry.getName(); if (diffEntries.contains(name)) { continue; } JarEntry newEntry; // Preserve the STORED method of the input entry. if (entry.getMethod() == JarEntry.STORED) { newEntry = new JarEntry(entry); } else { // Create a new entry so that the compressed len is recomputed. newEntry = new JarEntry(name); } // add the entry to the jar archive jos.putNextEntry(newEntry); // read the content of the entry from the input stream, and write it into the archive. int count; while ((count = zis.read(buffer)) != -1) { jos.write(buffer, 0, count); } // close the entries for this file jos.closeEntry(); zis.closeEntry(); } } finally { zis.close(); } fis.close(); jos.close(); }
From source file:com.taobao.android.tpatch.utils.JarSplitUtils.java
public static void splitZip(File inputFile, File outputFile, Set<String> includeEnties) throws IOException { if (outputFile.exists()) { FileUtils.deleteQuietly(outputFile); }//from www. jav a 2 s . c o m if (null == includeEnties || includeEnties.size() < 1) { return; } FileOutputStream fos = new FileOutputStream(outputFile); ZipOutputStream jos = new ZipOutputStream(fos); final byte[] buffer = new byte[8192]; FileInputStream fis = new FileInputStream(inputFile); ZipInputStream zis = new ZipInputStream(fis); try { // loop on the entries of the jar file package and put them in the final jar ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { // do not take directories or anything inside a potential META-INF folder. if (entry.isDirectory()) { continue; } String name = entry.getName(); if (!includeEnties.contains(name)) { continue; } JarEntry newEntry; // Preserve the STORED method of the input entry. if (entry.getMethod() == JarEntry.STORED) { newEntry = new JarEntry(entry); } else { // Create a new entry so that the compressed len is recomputed. newEntry = new JarEntry(name); } // add the entry to the jar archive jos.putNextEntry(newEntry); // read the content of the entry from the input stream, and write it into the archive. int count; while ((count = zis.read(buffer)) != -1) { jos.write(buffer, 0, count); } // close the entries for this file jos.closeEntry(); zis.closeEntry(); } } finally { zis.close(); } fis.close(); jos.close(); }
From source file:fridgegameinstaller.installation.java
private void extractFile(ZipInputStream zipIn, String filePath) throws IOException { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); byte[] bytesIn = new byte[BUFFER_SIZE]; int read = 0; while ((read = zipIn.read(bytesIn)) != -1) { bos.write(bytesIn, 0, read);//from w w w .j a va2 s. co m } bos.close(); }