List of usage examples for java.util.zip ZipFile getInputStream
public InputStream getInputStream(ZipEntry entry) throws IOException
From source file:de.dfki.km.perspecting.obie.corpus.BBCMusicCorpus.java
public Reader getGroundTruth(final URI uri) throws Exception { if (labelFileMediaType == MediaType.DIRECTORY) { return new StringReader(FileUtils.readFileToString(new File(uri))); } else if (labelFileMediaType == MediaType.ZIP) { ZipFile zipFile = new ZipFile(labelFolder); String[] entryName = uri.toURL().getFile().split("/"); ZipEntry entry = zipFile.getEntry( URLDecoder.decode(entryName[entryName.length - 1], "utf-8").replace("txt", "dumps") + ".rdf"); if (entry != null) { log.info("found labels for: " + uri.toString()); } else {//from ww w.j a v a 2 s . c o m throw new Exception("did not found labels for: " + uri.toString()); } return new InputStreamReader(zipFile.getInputStream(entry)); } else { throw new Exception("Unsupported media format for labels: " + labelFileMediaType + ". " + "Please use zip or plain directories instead."); } }
From source file:org.jboss.dashboard.factory.Factory.java
protected List<DescriptorFile> initModuleFromZip(File moduleZip) throws IOException { List<DescriptorFile> descriptorFiles = new ArrayList<DescriptorFile>(); ZipFile zf = new ZipFile(moduleZip); for (Enumeration en = zf.entries(); en.hasMoreElements();) { ZipEntry entry = (ZipEntry) en.nextElement(); if (entry.getName().endsWith(FACTORY_EXTENSION) && !entry.isDirectory()) { InputStream is = zf.getInputStream(entry); String componentName = entry.getName(); componentName = componentName.substring(0, componentName.length() - 1 - FACTORY_EXTENSION.length()); componentName = componentName.replace('/', '.'); componentName = componentName.replace('\\', '.'); Properties prop = new Properties(); try { prop.load(is);/* ww w .ja v a 2 s. com*/ is.close(); descriptorFiles.add(new DescriptorFile(componentName, prop, moduleZip + "!" + entry.getName())); } catch (IOException e) { log.error("Error processing file " + entry.getName() + " inside " + moduleZip + ". It will be ignored.", e); continue; } } } return descriptorFiles; }
From source file:com.sqli.liferay.imex.util.xml.ZipUtils.java
private void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException { if (entry.isDirectory()) { createDir(new File(outputDir, entry.getName())); return;/* ww w. java 2 s .c o m*/ } File outputFile = new File(outputDir, entry.getName()); if (!outputFile.getParentFile().exists()) { createDir(outputFile.getParentFile()); } log.debug("Extracting: " + entry); BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry)); BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); try { IOUtils.copy(inputStream, outputStream); } finally { outputStream.close(); inputStream.close(); } }
From source file:de.tudarmstadt.ukp.clarin.webanno.project.page.ImportUtil.java
/** * copy source document files from the exported source documents * @param zip the ZIP file.// ww w .j av a2 s.c om * @param aProject the project. * @param aRepository the repository service. * @throws IOException if an I/O error occurs. */ @SuppressWarnings("rawtypes") public static void createSourceDocumentContent(ZipFile zip, Project aProject, RepositoryService aRepository) throws IOException { for (Enumeration zipEnumerate = zip.entries(); zipEnumerate.hasMoreElements();) { ZipEntry entry = (ZipEntry) zipEnumerate.nextElement(); // Strip leading "/" that we had in ZIP files prior to 2.0.8 (bug #985) String entryName = normalizeEntryName(entry); if (entryName.startsWith(SOURCE)) { String fileName = FilenameUtils.getName(entryName); de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument sourceDocument = aRepository .getSourceDocument(aProject, fileName); File sourceFilePath = aRepository.getSourceDocumentFile(sourceDocument); FileUtils.copyInputStreamToFile(zip.getInputStream(entry), sourceFilePath); LOG.info("Imported source document content for source document [" + sourceDocument.getId() + "] in project [" + aProject.getName() + "] with id [" + aProject.getId() + "]"); } } }
From source file:cpw.mods.fml.server.FMLServerHandler.java
private void searchZipForENUSLanguage(File source) throws IOException { ZipFile zf = new ZipFile(source); for (ZipEntry ze : Collections.list(zf.entries())) { Matcher matcher = assetENUSLang.matcher(ze.getName()); if (matcher.matches()) { FMLLog.fine("Injecting found translation data in zip file %s at %s into language system", source.getName(), ze.getName()); StringTranslate.inject(zf.getInputStream(ze)); }//w w w. jav a 2 s . c om } zf.close(); }
From source file:com.ibm.amc.FileManager.java
public static File decompress(URI temporaryFileUri) { final File destination = new File(getUploadDirectory(), temporaryFileUri.getSchemeSpecificPart()); if (!destination.mkdirs()) { throw new AmcRuntimeException(Status.INTERNAL_SERVER_ERROR, "CWZBA2001E_DIRECTORY_CREATION_FAILED", destination.getPath());/* ww w . j a v a 2 s. c om*/ } ZipFile zipFile = null; try { zipFile = new ZipFile(getFileForUri(temporaryFileUri)); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File newDirOrFile = new File(destination, entry.getName()); if (newDirOrFile.getParentFile() != null && !newDirOrFile.getParentFile().exists()) { if (!newDirOrFile.getParentFile().mkdirs()) { throw new AmcRuntimeException(Status.INTERNAL_SERVER_ERROR, "CWZBA2001E_DIRECTORY_CREATION_FAILED", newDirOrFile.getParentFile().getPath()); } } if (entry.isDirectory()) { if (!newDirOrFile.mkdir()) { throw new AmcRuntimeException(Status.INTERNAL_SERVER_ERROR, "CWZBA2001E_DIRECTORY_CREATION_FAILED", newDirOrFile.getPath()); } } else { BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry)); int size; byte[] buffer = new byte[ZIP_BUFFER]; BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newDirOrFile), ZIP_BUFFER); while ((size = bis.read(buffer, 0, ZIP_BUFFER)) != -1) { bos.write(buffer, 0, size); } bos.flush(); bos.close(); bis.close(); } } } catch (Exception e) { throw new AmcRuntimeException(e); } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException e) { logger.debug("decompress", "close failed with " + e); } } } return destination; }
From source file:com.thruzero.common.core.utils.FileUtilsExt.java
public static final boolean unzipArchive(final File fromFile, final File toDir) throws IOException { boolean result = false; // assumes error logHelper.logBeginUnzip(fromFile, toDir); ZipFile zipFile = new ZipFile(fromFile); Enumeration<? extends ZipEntry> entries = zipFile.entries(); if (!toDir.exists()) { toDir.mkdirs();//from w w w .ja va 2 s . c o m logHelper.logProgressCreatedToDir(toDir); } logHelper.logProgressToDirIsWritable(toDir); if (toDir.canWrite()) { while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.isDirectory()) { File dir = new File( toDir.getAbsolutePath() + EnvironmentHelper.FILE_PATH_SEPARATOR + entry.getName()); if (!dir.exists()) { dir.mkdirs(); logHelper.logProgressFilePathCreated(dir); } } else { File fosz = new File( toDir.getAbsolutePath() + EnvironmentHelper.FILE_PATH_SEPARATOR + entry.getName()); logHelper.logProgressCopyEntry(fosz); File parent = fosz.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fosz)); IOUtils.copy(zipFile.getInputStream(entry), bos); bos.flush(); } } zipFile.close(); result = true; // success } else { logHelper.logFileWriteError(fromFile, null); zipFile.close(); } return result; }
From source file:de.onyxbits.raccoon.ptools.ToolSupport.java
private void unzip(File file) throws IOException { ZipFile zipFile = new ZipFile(file); try {//w w w . jav a2 s . c o m Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File entryDestination = new File(binDir, entry.getName()); if (entry.isDirectory()) entryDestination.mkdirs(); else { entryDestination.getParentFile().mkdirs(); InputStream in = zipFile.getInputStream(entry); OutputStream out = new FileOutputStream(entryDestination); IOUtils.copy(in, out); IOUtils.closeQuietly(in); out.close(); } } } finally { zipFile.close(); } }
From source file:org.jboss.web.tomcat.tc5.TomcatDeployer.java
private String findConfig(URL warURL) throws IOException { String result = null;//from w w w . ja v a 2 s . com // See if the warUrl is a dir or a file File warFile = new File(warURL.getFile()); if (warURL.getProtocol().equals("file") && warFile.isDirectory() == true) { File webDD = new File(warFile, CONTEXT_CONFIG_FILE); if (webDD.exists() == true) result = webDD.getAbsolutePath(); } else { ZipFile zipFile = new ZipFile(warFile); ZipEntry entry = zipFile.getEntry(CONTEXT_CONFIG_FILE); if (entry != null) { InputStream zipIS = zipFile.getInputStream(entry); byte[] buffer = new byte[512]; int bytes; result = warFile.getAbsolutePath() + "-context.xml"; FileOutputStream fos = new FileOutputStream(result); while ((bytes = zipIS.read(buffer)) > 0) { fos.write(buffer, 0, bytes); } zipIS.close(); fos.close(); } zipFile.close(); } return result; }
From source file:com.sshtools.j2ssh.util.DynamicClassLoader.java
private InputStream loadResourceFromZipfile(File file, String name) { try {/* w w w . j a v a 2s. c o m*/ ZipFile zipfile = new ZipFile(file); ZipEntry entry = zipfile.getEntry(name); if (entry != null) { return zipfile.getInputStream(entry); } else { return null; } } catch (IOException e) { return null; } }