List of usage examples for java.util.zip ZipInputStream ZipInputStream
public ZipInputStream(InputStream in)
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// w w w .j av a 2 s. c o m * @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:com.thoughtworks.go.server.initializers.PluginsInitializer.java
ZipInputStream getPluginsZipStream() {
return new ZipInputStream(this.getClass().getResourceAsStream(systemEnvironment.get(DEFAULT_PLUGINS_ZIP)));
}
From source file:com.joliciel.talismane.lexicon.LexiconDeserializer.java
public PosTaggerLexicon deserializeLexiconFile(File lexiconFile) { MONITOR.startTask("deserializeLexiconFile(File)"); try {// w w w . j a va 2s .c o m LOG.debug("deserializing " + lexiconFile.getName()); boolean isZip = false; if (lexiconFile.getName().endsWith(".zip")) isZip = true; PosTaggerLexicon lexicon = null; ZipInputStream zis = null; FileInputStream fis = null; ObjectInputStream in = null; try { fis = new FileInputStream(lexiconFile); if (isZip) { zis = new ZipInputStream(fis); lexicon = this.deserializeLexiconFile(zis); } else { in = new ObjectInputStream(fis); lexicon = (PosTaggerLexicon) in.readObject(); in.close(); } } catch (IOException ioe) { throw new RuntimeException(ioe); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } return lexicon; } finally { MONITOR.endTask("deserializeLexiconFile(File)"); } }
From source file:com.marklogic.contentpump.CompressedDelimitedTextReader.java
protected void initStream(InputSplit inSplit) throws IOException { setFile(((FileSplit) inSplit).getPath()); FSDataInputStream fileIn = fs.open(file); String codecString = conf.get(ConfigConstants.CONF_INPUT_COMPRESSION_CODEC, CompressionCodec.ZIP.toString()); if (codecString.equalsIgnoreCase(CompressionCodec.ZIP.toString())) { zipIn = new ZipInputStream(fileIn); codec = CompressionCodec.ZIP;/* w w w.j a v a 2s . c o m*/ } else if (codecString.equalsIgnoreCase(CompressionCodec.GZIP.toString())) { zipIn = new GZIPInputStream(fileIn); codec = CompressionCodec.GZIP; } if (uriName == null) { generateId = conf.getBoolean(CONF_INPUT_GENERATE_URI, false); if (generateId) { idGen = new IdGenerator(file.toUri().getPath() + "-" + ((FileSplit) inSplit).getStart()); } else { uriId = 0; } } }
From source file:net.firejack.platform.service.content.broker.collection.ImportCollectionArchiveFileBroker.java
@Override protected ServiceResponse perform(ServiceRequest<NamedValues<InputStream>> request) throws Exception { InputStream inputStream = request.getData().get("inputStream"); try {//from w ww . j a v a 2 s . c o m Long uploadFileTime = new Date().getTime(); String randomName = SecurityHelper.generateRandomSequence(16); String temporaryUploadFileName = randomName + "." + uploadFileTime; OPFEngine.FileStoreService.upload(OpenFlame.FILESTORE_BASE, temporaryUploadFileName, inputStream, helper.getTemp()); String contentXmlUploadedFile = null; String resourceZipUploadedFile = null; ZipInputStream zipFile = new ZipInputStream(OPFEngine.FileStoreService .download(OpenFlame.FILESTORE_BASE, temporaryUploadFileName, helper.getTemp())); try { ZipEntry entry; while ((entry = zipFile.getNextEntry()) != null) { if (PackageFileType.CONTENT_XML.getOfrFileName().equals(entry.getName())) { contentXmlUploadedFile = PackageFileType.CONTENT_XML.name() + randomName + "." + uploadFileTime; OPFEngine.FileStoreService.upload(OpenFlame.FILESTORE_BASE, contentXmlUploadedFile, zipFile, helper.getTemp()); } else if (PackageFileType.RESOURCE_ZIP.getOfrFileName().equals(entry.getName())) { resourceZipUploadedFile = PackageFileType.RESOURCE_ZIP.name() + randomName + "." + uploadFileTime; OPFEngine.FileStoreService.upload(OpenFlame.FILESTORE_BASE, resourceZipUploadedFile, zipFile, helper.getTemp()); } } } catch (IOException e) { throw new BusinessFunctionException(e.getMessage()); } finally { zipFile.close(); } InputStream contentXml = OPFEngine.FileStoreService.download(OpenFlame.FILESTORE_BASE, contentXmlUploadedFile, helper.getTemp()); InputStream resourceZip = OPFEngine.FileStoreService.download(OpenFlame.FILESTORE_BASE, resourceZipUploadedFile, helper.getTemp()); importContentProcessor.importContent(contentXml, resourceZip); IOUtils.closeQuietly(contentXml); IOUtils.closeQuietly(resourceZip); } catch (IOException e) { throw new BusinessFunctionException(e.getMessage()); } catch (JAXBException e) { throw new BusinessFunctionException(e.getMessage()); } return new ServiceResponse("Content Archive has uploaded successfully.", true); }
From source file:com.thoughtworks.go.server.initializers.CommandRepositoryInitializerIntegrationTest.java
@Test public void shouldNotDeleteCustomCommandRepositoryWhenUpdatingDefaultCommandRepository() throws Exception { File versionFile = TestFileUtil.writeStringToTempFileInFolder("default", "version.txt", "10.1=10"); File randomFile = TestFileUtil.createTestFile(versionFile.getParentFile(), "random"); File defaultCommandRepoDir = versionFile.getParentFile(); File customCommandRepoDir = TestFileUtil.createTestFolder(new File(defaultCommandRepoDir.getParent()), "customDir"); File userFile = TestFileUtil.createTestFile(customCommandRepoDir, "userFile"); initializer.usePackagedCommandRepository( new ZipInputStream(new FileInputStream(getZippedCommandRepo("12.4=12"))), defaultCommandRepoDir); assertThat(defaultCommandRepoDir.exists(), is(true)); assertThat(FileUtils.readFileToString(new File(defaultCommandRepoDir, "version.txt"), UTF_8), is("12.4=12")); assertThat(new File(defaultCommandRepoDir, "snippet.xml").exists(), is(true)); assertThat(new File(defaultCommandRepoDir, randomFile.getName()).exists(), is(false)); assertThat(customCommandRepoDir.exists(), is(true)); assertThat(new File(customCommandRepoDir, userFile.getName()).exists(), is(true)); }
From source file:com.wso2mobile.mam.packageExtractor.ZipFileReading.java
public String readiOSManifestFile(String filePath, String name) { String plist = ""; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try {/* w ww. ja va2 s .c om*/ File file = new File(filePath); ZipInputStream stream = new ZipInputStream(new FileInputStream(file)); try { ZipEntry entry; while ((entry = stream.getNextEntry()) != null) { if (entry.getName().equals("Payload/" + name + ".app/Info.plist")) { InputStream is = stream; int nRead; byte[] data = new byte[16384]; while ((nRead = is.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } buffer.flush(); } } } catch (Exception e) { e.printStackTrace(); } finally { stream.close(); } NSDictionary rootDict = (NSDictionary) BinaryPropertyListParser.parse(buffer.toByteArray()); JSONObject obj = new JSONObject(); obj.put("version", rootDict.objectForKey("CFBundleVersion").toString()); obj.put("name", rootDict.objectForKey("CFBundleName").toString()); obj.put("package", rootDict.objectForKey("CFBundleIdentifier").toString()); plist = obj.toJSONString(); } catch (Exception e) { plist = "Exception occured " + e; e.printStackTrace(); } return plist; }
From source file:com.marklogic.contentpump.CompressedRDFReader.java
@Override protected void initStream(InputSplit inSplit) throws IOException, InterruptedException { setFile(((FileSplit) inSplit).getPath()); FSDataInputStream fileIn = fs.open(file); URI zipURI = file.toUri();// www . ja v a2 s . co m String codecString = conf.get(ConfigConstants.CONF_INPUT_COMPRESSION_CODEC, CompressionCodec.ZIP.toString()); if (codecString.equalsIgnoreCase(CompressionCodec.ZIP.toString())) { zipIn = new ZipInputStream(fileIn); codec = CompressionCodec.ZIP; while (true) { try { currZipEntry = ((ZipInputStream) zipIn).getNextEntry(); if (currZipEntry == null) { break; } if (currZipEntry.getSize() != 0) { subId = currZipEntry.getName(); break; } } catch (IllegalArgumentException e) { LOG.warn("Skipped a zip entry in : " + file.toUri() + ", reason: " + e.getMessage()); } } if (currZipEntry == null) { // no entry in zip LOG.warn("No valid entry in zip:" + file.toUri()); return; } ByteArrayOutputStream baos; long size = currZipEntry.getSize(); if (size == -1) { baos = new ByteArrayOutputStream(); // if we don't know the size, assume it's big! initParser(zipURI.toASCIIString() + "/" + subId, INMEMORYTHRESHOLD); } else { baos = new ByteArrayOutputStream((int) size); initParser(zipURI.toASCIIString() + "/" + subId, size); } int nb; while ((nb = zipIn.read(buf, 0, buf.length)) != -1) { baos.write(buf, 0, nb); } parse(subId, new ByteArrayInputStream(baos.toByteArray())); } else if (codecString.equalsIgnoreCase(CompressionCodec.GZIP.toString())) { long size = inSplit.getLength(); zipIn = new GZIPInputStream(fileIn); codec = CompressionCodec.GZIP; initParser(zipURI.toASCIIString(), size * COMPRESSIONFACTOR); parse(file.getName(), zipIn); } else { throw new UnsupportedOperationException("Unsupported codec: " + codec.name()); } }
From source file:com.anhth12.lambda.app.serving.AbstractLambdaResource.java
protected static InputStream maybeDecompress(String contentType, InputStream in) throws IOException { if (contentType != null) { switch (contentType) { case "application/zip": in = new ZipInputStream(in); break; case "application/gzip": case "application/x-gzip": in = new GZIPInputStream(in); break; }//from ww w .ja v a2s. c o m } return in; }
From source file:com.sqli.liferay.imex.util.xml.ZipUtils.java
public void _unzipArchive(File archive, File outputDir) throws IOException { BufferedOutputStream dest = null; FileInputStream fis = new FileInputStream(archive); CheckedInputStream checksum = new CheckedInputStream(fis, new Adler32()); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(checksum)); ZipEntry entry;//from ww w .j a va 2 s.c o m while ((entry = zis.getNextEntry()) != null) { log.debug("Extracting: " + entry); int count; byte data[] = new byte[BUFFER]; // write the files to the disk FileOutputStream fos = new FileOutputStream(entry.getName()); dest = new BufferedOutputStream(fos, BUFFER); while ((count = zis.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); } zis.close(); log.debug("Checksum:" + checksum.getChecksum().getValue()); }