Example usage for java.util.zip ZipFile getInputStream

List of usage examples for java.util.zip ZipFile getInputStream

Introduction

In this page you can find the example usage for java.util.zip ZipFile getInputStream.

Prototype

public InputStream getInputStream(ZipEntry entry) throws IOException 

Source Link

Document

Returns an input stream for reading the contents of the specified zip file entry.

Usage

From source file:com.microsoft.intellij.helpers.IDEHelperImpl.java

private static void copyJarFiles(@NotNull final Module module, @NotNull VirtualFile baseDir,
        @NotNull File zipFile, @NotNull String zipPath) throws IOException {
    if (baseDir.isDirectory()) {
        final ZipFile zip = new ZipFile(zipFile);
        Enumeration<? extends ZipEntry> entries = zip.entries();

        while (entries.hasMoreElements()) {
            final ZipEntry zipEntry = entries.nextElement();

            if (!zipEntry.isDirectory() && zipEntry.getName().startsWith(zipPath)
                    && zipEntry.getName().endsWith(".jar") && !(zipEntry.getName().endsWith("-sources.jar")
                            || zipEntry.getName().endsWith("-javadoc.jar"))) {
                VirtualFile libsVf = null;

                for (VirtualFile vf : baseDir.getChildren()) {
                    if (vf.getName().equals("libs")) {
                        libsVf = vf;// w w w.ja va 2 s.  c o  m
                        break;
                    }
                }

                if (libsVf == null) {
                    libsVf = baseDir.createChildDirectory(module.getProject(), "libs");
                }

                final VirtualFile libs = libsVf;
                final String fileName = zipEntry.getName().split("/")[1];

                if (libs.findChild(fileName) == null) {
                    ApplicationManager.getApplication().invokeAndWait(new Runnable() {
                        @Override
                        public void run() {
                            ApplicationManager.getApplication().runWriteAction(new Runnable() {
                                @Override
                                public void run() {
                                    try {
                                        InputStream mobileserviceInputStream = zip.getInputStream(zipEntry);
                                        VirtualFile msVF = libs.createChildData(module.getProject(), fileName);
                                        msVF.setBinaryContent(getArray(mobileserviceInputStream));
                                    } catch (Throwable ex) {
                                        DefaultLoader.getUIHelper().showException(
                                                "An error occurred while attempting "
                                                        + "to configure Azure Mobile Services.",
                                                ex,
                                                "Azure Services Explorer - Error Configuring Mobile Services",
                                                false, true);
                                    }
                                }
                            });
                        }
                    }, ModalityState.defaultModalityState());
                }
            }
        }
    }
}

From source file:it.greenvulcano.util.zip.ZipHelper.java

/**
 * Performs the uncompression of a <code>zip</code> file, whose name and
 * parent directory are passed as arguments, on the local filesystem. The
 * content of the <code>zip</code> file will be uncompressed within a
 * specified target directory.<br>
 *
 * @param srcDirectory/* w w w. ja  v a  2  s  .c om*/
 *            the source parent directory of the file/s to be unzipped. Must
 *            be an absolute pathname.
 * @param zipFilename
 *            the name of the file to be unzipped. Cannot contain wildcards.
 * @param targetDirectory
 *            the target directory in which the content of the
 *            <code>zip</code> file will be unzipped. Must be an absolute
 *            pathname.
 * @throws IOException
 *             If any error occurs during file uncompression.
 * @throws IllegalArgumentException
 *             if the arguments are invalid.
 */
public void unzipFile(String srcDirectory, String zipFilename, String targetDirectory) throws IOException {

    File srcDir = new File(srcDirectory);

    if (!srcDir.isAbsolute()) {
        throw new IllegalArgumentException(
                "The pathname of the source parent directory is NOT absolute: " + srcDirectory);
    }

    if (!srcDir.exists()) {
        throw new IllegalArgumentException(
                "Source parent directory " + srcDirectory + " NOT found on local filesystem.");
    }

    if (!srcDir.isDirectory()) {
        throw new IllegalArgumentException("Source parent directory " + srcDirectory + " is NOT a directory.");
    }

    File srcZipFile = new File(srcDirectory, zipFilename);
    if (!srcZipFile.exists()) {
        throw new IllegalArgumentException(
                "File to be unzipped (" + srcZipFile.getAbsolutePath() + ") NOT found on local filesystem.");
    }

    ZipFile zipFile = null;
    try {
        zipFile = new ZipFile(srcZipFile);
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry currEntry = entries.nextElement();
            if (currEntry.isDirectory()) {
                String targetSubdirPathname = currEntry.getName();
                File dir = new File(targetDirectory, targetSubdirPathname);
                FileUtils.forceMkdir(dir);
                dir.setLastModified(currEntry.getTime());
            } else {
                InputStream is = null;
                OutputStream os = null;
                File file = null;
                try {
                    is = zipFile.getInputStream(currEntry);
                    FileUtils.forceMkdir(new File(targetDirectory, currEntry.getName()).getParentFile());
                    file = new File(targetDirectory, currEntry.getName());
                    os = new FileOutputStream(file);
                    IOUtils.copy(is, os);
                } finally {
                    try {
                        if (is != null) {
                            is.close();
                        }

                        if (os != null) {
                            os.close();
                        }
                    } catch (IOException exc) {
                        // Do nothing
                    }

                    if (file != null) {
                        file.setLastModified(currEntry.getTime());
                    }
                }
            }
        }
    } finally {
        try {
            if (zipFile != null) {
                zipFile.close();
            }
        } catch (Exception exc) {
            // do nothing
        }
    }
}

From source file:org.dbgl.util.FileUtils.java

public static void extractEntry(final ZipFile zf, final ZipEntry srcEntry, final File dstFile,
        final ProgressNotifyable prog) throws IOException {
    File foundDstFile = null, temporarilyRenamedFile = null;
    if (PlatformUtils.IS_WINDOWS && dstFile.getName().contains("~")) {
        foundDstFile = dstFile.getCanonicalFile();
        if (!foundDstFile.getName().equals(dstFile.getName()) && foundDstFile.exists()) {
            temporarilyRenamedFile = getUniqueFileName(foundDstFile);
            foundDstFile.renameTo(temporarilyRenamedFile);
        }/*from www  .j  av a 2  s  . c o m*/
    }

    if (dstFile.exists())
        throw new IOException(
                Settings.getInstance().msg("general.error.filetobeextractedexists", new Object[] { dstFile }));
    if (srcEntry.isDirectory()) {
        if (!dstFile.exists())
            createDir(dstFile);
    } else {
        if (dstFile.getParentFile() != null)
            createDir(dstFile.getParentFile());
        FileOutputStream fos = new FileOutputStream(dstFile);
        InputStream is = zf.getInputStream(srcEntry);
        byte[] readBuffer = new byte[ZIP_BUFFER];
        int bytesIn;
        while ((bytesIn = is.read(readBuffer)) != -1)
            fos.write(readBuffer, 0, bytesIn);
        fos.flush();
        fos.close();
        is.close();
        byte[] extra = srcEntry.getExtra();
        if ((extra != null) && (extra.length == 1) && (extra[0] == 1))
            fileSetReadOnly(dstFile);
    }
    fileSetLastModified(dstFile, srcEntry.getTime());

    if (foundDstFile != null && temporarilyRenamedFile != null)
        temporarilyRenamedFile.renameTo(foundDstFile);

    prog.incrProgress((int) (srcEntry.getSize() / 1024));
}

From source file:org.ambraproject.article.service.IngesterImpl.java

/**
 * Process files from the archive and store them to the {@link FileStoreService}
 *
 * @param archive - the archive being ingested
 * @param doi/*  w w  w  . j  a  v  a2  s.  c o m*/
 * @throws java.io.IOException - if there's a problem reading from the zip file
 * @throws org.ambraproject.filestore.FileStoreException
 *                             - if there's a problem writing files to the file store
 */
private void storeFiles(final ZipFile archive, String doi) throws IOException, FileStoreException {
    log.info("Removing existing files (if any) for {}", doi);

    try {
        documentManagementService.removeFromFileSystem(doi);
    } catch (Exception e) {
        throw new FileStoreException("Error removing existing files from the file store", e);
    }

    log.info("Storing files from archive {} to the file store", archive.getName());
    Enumeration<? extends ZipEntry> entries = archive.entries();

    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        if (!entry.getName().equalsIgnoreCase("manifest.dtd")) {
            InputStream inputStream = null;
            OutputStream outputStream = null;
            try {
                inputStream = archive.getInputStream(entry);
                outputStream = fileStoreService.getFileOutStream(FSIDMapper.zipToFSID(doi, entry.getName()),
                        entry.getSize());
                fileStoreService.copy(inputStream, outputStream);
            } finally {
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException e) {
                        log.warn("Error closing input stream while writing files", e);
                    }
                }
                if (outputStream != null) {
                    try {
                        outputStream.close();
                    } catch (IOException e) {
                        log.warn("Error closing output stream while writing files", e);
                    }
                }
            }
        }
    }
    log.info("Finished storing files from archive {}", archive.getName());
}

From source file:com.edgenius.wiki.service.impl.ThemeServiceImpl.java

private String getMetafile(File zipFile, String fileName) {
    String content = "";
    ZipFile zip = null;
    try {/*from ww  w  .  j  a  va  2  s .  c  om*/
        zip = new ZipFile(zipFile);
        ZipEntry entry = zip.getEntry(fileName);
        if (entry != null) {
            content = IOUtils.toString(zip.getInputStream(entry));
        }
    } catch (Exception e) {
        log.info("backup/restore file comment not available:" + zipFile.getAbsolutePath());
    } finally {
        if (zip != null)
            try {
                zip.close();
            } catch (Exception e) {
            }
    }

    return content;
}

From source file:dalma.container.ClassLoaderImpl.java

/**
 * Add a file to the path. This classloader reads the manifest, if
 * available, and adds any additional class path jars specified in the
 * manifest.//ww w. j a v  a2s  .co  m
 *
 * @param pathComponent the file which is to be added to the path for
 *                      this class loader
 *
 * @throws IOException if data needed from the file cannot be read.
 */
public void addPathFile(File pathComponent) throws IOException {
    pathComponents.addElement(pathComponent);

    if (pathComponent.isDirectory()) {
        return;
    }

    String absPathPlusTimeAndLength = pathComponent.getAbsolutePath() + pathComponent.lastModified() + "-"
            + pathComponent.length();
    String classpath = pathMap.get(absPathPlusTimeAndLength);
    if (classpath == null) {
        ZipFile jarFile = null;
        InputStream manifestStream = null;
        try {
            jarFile = new ZipFile(pathComponent);
            manifestStream = jarFile.getInputStream(new ZipEntry("META-INF/MANIFEST.MF"));

            if (manifestStream == null) {
                return;
            }
            Manifest manifest = new Manifest(manifestStream);
            classpath = manifest.getMainAttributes().getValue("Class-Path");

        } finally {
            if (manifestStream != null) {
                manifestStream.close();
            }
            if (jarFile != null) {
                jarFile.close();
            }
        }
        if (classpath == null) {
            classpath = "";
        }
        pathMap.put(absPathPlusTimeAndLength, classpath);
    }

    if (!"".equals(classpath)) {
        URL baseURL = pathComponent.toURL();
        StringTokenizer st = new StringTokenizer(classpath);
        while (st.hasMoreTokens()) {
            String classpathElement = st.nextToken();
            URL libraryURL = new URL(baseURL, classpathElement);
            if (!libraryURL.getProtocol().equals("file")) {
                logger.fine("Skipping jar library " + classpathElement
                        + " since only relative URLs are supported by this" + " loader");
                continue;
            }
            File libraryFile = new File(libraryURL.getFile());
            if (libraryFile.exists() && !isInPath(libraryFile)) {
                addPathFile(libraryFile);
            }
        }
    }
}

From source file:net.morematerials.manager.UpdateManager.java

private void updateSmp(File file) throws Exception {
    ZipFile smpFile = new ZipFile(file);
    Enumeration<? extends ZipEntry> entries = smpFile.entries();
    String smpName = file.getName().substring(0, file.getName().lastIndexOf("."));

    // First we need to know what files are in this .smp file, because the old format uses magic filename matching.
    ArrayList<String> containedFiles = new ArrayList<String>();
    HashMap<String, YamlConfiguration> materials = new HashMap<String, YamlConfiguration>();

    // Now we walk through the file once and store every file.
    ZipEntry entry;// w w  w. j a v  a 2 s.  co m
    YamlConfiguration yaml;
    while (entries.hasMoreElements()) {
        entry = entries.nextElement();

        // Only if its a .yml file
        if (entry.getName().endsWith(".yml")) {
            // Load the .yml file
            yaml = new YamlConfiguration();
            yaml.load(smpFile.getInputStream(entry));

            // Texture is required for new package format.
            if (!yaml.contains("Texture")) {
                materials.put(entry.getName().substring(0, entry.getName().lastIndexOf(".")), yaml);
            } else {
                containedFiles.add(entry.getName());
            }
        } else {
            containedFiles.add(entry.getName());
        }
    }

    // If this map contains any entry, we need to convert something.
    if (materials.size() > 0) {
        this.plugin.getUtilsManager().log("Deprecated .smp found: " + file.getName() + ". Updating...");

        // We need a temporary directory to update the .smp in.
        this.tempDir.mkdir();

        // First extract all untouched assets:
        for (String filename : containedFiles) {
            InputStream in = smpFile.getInputStream(smpFile.getEntry(filename));
            OutputStream out = new FileOutputStream(new File(this.tempDir, filename));
            int read;
            byte[] bytes = new byte[1024];
            while ((read = in.read(bytes)) != -1) {
                out.write(bytes, 0, read);
            }
            out.flush();
            out.close();
            in.close();
        }

        // Now convert each .yml file in this archive.
        YamlConfiguration oldYaml;
        YamlConfiguration newYaml;
        for (String materialName : materials.keySet()) {
            oldYaml = materials.get(materialName);
            newYaml = new YamlConfiguration();

            // Required "Type" which is Block or Item. Old format didnt support Tools anyway.
            newYaml.set("Type", oldYaml.getString("Type"));
            // Title is now required and falls back to filename.
            newYaml.set("Title", oldYaml.getString("Title", materialName));

            // Now call the converter methods.
            if (newYaml.getString("Type").equals("Block")) {
                this.convertBlock(oldYaml, newYaml, materialName, containedFiles);
                this.convertBlockHandlers(oldYaml, newYaml);
            } else if (newYaml.getString("Type").equals("Item")) {
                this.convertItem(oldYaml, newYaml, materialName, containedFiles);
                this.convertItemHandlers(oldYaml, newYaml);
            }

            // Copy over recipes - nothing changed here!
            if (oldYaml.contains("Recipes")) {
                newYaml.set("Recipes", oldYaml.getList("Recipes"));
            }

            // Finally store the new .yml file.
            String yamlString = newYaml.saveToString();
            BufferedWriter out = new BufferedWriter(
                    new FileWriter(new File(this.tempDir, materialName + ".yml")));
            out.write(this.fixYamlProblems(yamlString));
            out.close();

            // Also update itemmap entry!
            for (Integer i = 0; i < this.itemMap.size(); i++) {
                String oldMaterial = this.itemMap.get(i).replaceAll("^[0-9]+:MoreMaterials.", "");
                if (oldMaterial.equals(newYaml.getString("Title"))) {
                    this.itemMap.set(i, this.itemMap.get(i).replaceAll("^([0-9]+:MoreMaterials.).+$",
                            "$1" + smpName + "." + materialName));
                    break;
                }
            }

            // And we need to tell SpoutPlugin that this material must be renamed!
            SpoutManager.getMaterialManager().renameMaterialKey(this.plugin, newYaml.getString("Title"),
                    smpName + "." + materialName);
        }

        // First remove old .smp file
        smpFile.close();
        file.delete();

        // Then repack the new .smp file
        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file));
        for (File entryFile : this.tempDir.listFiles()) {
            FileInputStream in = new FileInputStream(entryFile);
            out.putNextEntry(new ZipEntry(entryFile.getName()));
            Integer len;
            byte[] buf = new byte[1024];
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            out.closeEntry();
            in.close();
        }
        out.close();

        // At last remove the temp directory.
        FileUtils.deleteDirectory(this.tempDir);
    } else {
        // At last, close the file handle.
        smpFile.close();
    }
}

From source file:net.firejack.platform.installation.processor.OFRInstallProcessor.java

private void installOFR(File ofr) throws IOException {
    ZipFile zipFile = null;
    try {/*w w  w. j av a 2s.  c om*/
        zipFile = new ZipFile(ofr);

        String packageXmlUploadedFile = null;
        String resourceZipUploadedFile = null;
        String codeWarUploadedFile = null;
        Enumeration entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) entries.nextElement();

            if (PackageFileType.PACKAGE_XML.getOfrFileName().equals(entry.getName())) {
                packageXmlUploadedFile = SecurityHelper.generateRandomSequence(16)
                        + PackageFileType.PACKAGE_XML.getDotExtension();
                OPFEngine.FileStoreService.upload(OpenFlame.FILESTORE_BASE, packageXmlUploadedFile,
                        zipFile.getInputStream(entry), helper.getTemp());
            } else if (PackageFileType.RESOURCE_ZIP.getOfrFileName().equals(entry.getName())) {
                resourceZipUploadedFile = SecurityHelper.generateRandomSequence(16)
                        + PackageFileType.RESOURCE_ZIP.getDotExtension();
                OPFEngine.FileStoreService.upload(OpenFlame.FILESTORE_BASE, resourceZipUploadedFile,
                        zipFile.getInputStream(entry), helper.getTemp());
            } else if (PackageFileType.APP_WAR.getOfrFileName().equals(entry.getName())) {
                codeWarUploadedFile = SecurityHelper.generateRandomSequence(16)
                        + PackageFileType.APP_WAR.getDotExtension();
                OPFEngine.FileStoreService.upload(OpenFlame.FILESTORE_BASE, codeWarUploadedFile,
                        zipFile.getInputStream(entry), helper.getTemp());
            }
        }

        InputStream packageXml = OPFEngine.FileStoreService.download(OpenFlame.FILESTORE_BASE,
                packageXmlUploadedFile, helper.getTemp());
        InputStream resourceZip = OPFEngine.FileStoreService.download(OpenFlame.FILESTORE_BASE,
                resourceZipUploadedFile, helper.getTemp());
        StatusProviderTranslationResult statusResult = packageInstallationService.activatePackage(packageXml,
                resourceZip);
        IOUtils.closeQuietly(packageXml);
        IOUtils.closeQuietly(resourceZip);

        if (statusResult.getResult() && statusResult.getPackage() != null) {
            PackageModel packageRN = statusResult.getPackage();
            if (packageRN != null) {
                Integer oldVersion = packageRN.getVersion();
                packageRN = packageStore.updatePackageVersion(packageRN.getId(),
                        statusResult.getVersionNumber());

                if (statusResult.getOldPackageXml() != null) {
                    packageVersionHelper.archiveVersion(packageRN, oldVersion, statusResult.getOldPackageXml());
                }

                String packageXmlName = packageRN.getName() + PackageFileType.PACKAGE_XML.getDotExtension();
                packageXml = OPFEngine.FileStoreService.download(OpenFlame.FILESTORE_BASE,
                        packageXmlUploadedFile, helper.getTemp());
                OPFEngine.FileStoreService.upload(OpenFlame.FILESTORE_BASE, packageXmlName, packageXml,
                        helper.getVersion(), String.valueOf(packageRN.getId()),
                        String.valueOf(packageRN.getVersion()));
                IOUtils.closeQuietly(packageXml);

                if (resourceZipUploadedFile != null) {
                    String resourceZipName = packageRN.getName()
                            + PackageFileType.RESOURCE_ZIP.getDotExtension();
                    resourceZip = OPFEngine.FileStoreService.download(OpenFlame.FILESTORE_BASE,
                            resourceZipUploadedFile, helper.getTemp());
                    OPFEngine.FileStoreService.upload(OpenFlame.FILESTORE_BASE, resourceZipName, resourceZip,
                            helper.getVersion(), String.valueOf(packageRN.getId()),
                            String.valueOf(packageRN.getVersion()));
                    IOUtils.closeQuietly(resourceZip);
                }

                //                    File webapps = new File(Env.CATALINA_BASE.getValue(), "webapps");
                //                    if (codeWarUploadedFile != null && webapps.exists()) {
                //                        FileUtils.copyFile(codeWarUploadedFile, new File(webapps, packageRN.getName() + PackageFileType.APP_WAR.getDotExtension()));
                //                    }

                if (codeWarUploadedFile != null) {
                    String codeWarName = packageRN.getName() + PackageFileType.APP_WAR.getDotExtension();
                    InputStream warstream = OPFEngine.FileStoreService.download(OpenFlame.FILESTORE_BASE,
                            codeWarUploadedFile, helper.getTemp());
                    OPFEngine.FileStoreService.upload(OpenFlame.FILESTORE_BASE, codeWarName, warstream,
                            helper.getVersion(), String.valueOf(packageRN.getId()),
                            String.valueOf(packageRN.getVersion()));
                    IOUtils.closeQuietly(warstream);
                }

                String packageFilename = packageRN.getName() + PackageFileType.PACKAGE_OFR.getDotExtension();
                FileInputStream stream = new FileInputStream(ofr);
                OPFEngine.FileStoreService.upload(OpenFlame.FILESTORE_BASE, packageFilename, stream,
                        helper.getVersion(), String.valueOf(packageRN.getId()),
                        String.valueOf(packageRN.getVersion()));
                IOUtils.closeQuietly(stream);
            } else {
                throw new BusinessFunctionException("Package archive has not created.");
            }
        }
    } finally {
        if (zipFile != null)
            zipFile.close();
    }
}

From source file:fll.subjective.SubjectiveFrame.java

/**
 * Load data. Meant for testing. Most users should use #promptForFile().
 * //w w  w  . ja v a 2 s . co  m
 * @param file where to read the data in from and where to save data to
 * @throws IOException
 */
public void load(final File file) throws IOException {
    _file = file;

    ZipFile zipfile = null;
    try {
        zipfile = new ZipFile(file);

        final ZipEntry challengeEntry = zipfile.getEntry(DownloadSubjectiveData.CHALLENGE_ENTRY_NAME);
        if (null == challengeEntry) {
            throw new FLLRuntimeException(
                    "Unable to find challenge descriptor in file, you probably choose the wrong file or it is corrupted");
        }
        final InputStream challengeStream = zipfile.getInputStream(challengeEntry);
        _challengeDocument = ChallengeParser
                .parse(new InputStreamReader(challengeStream, Utilities.DEFAULT_CHARSET));
        challengeStream.close();

        _challengeDescription = new ChallengeDescription(_challengeDocument.getDocumentElement());

        final ZipEntry scoreEntry = zipfile.getEntry(DownloadSubjectiveData.SCORE_ENTRY_NAME);
        if (null == scoreEntry) {
            throw new FLLRuntimeException(
                    "Unable to find score data in file, you probably choose the wrong file or it is corrupted");
        }
        final InputStream scoreStream = zipfile.getInputStream(scoreEntry);
        _scoreDocument = XMLUtils.parseXMLDocument(scoreStream);
        scoreStream.close();

        final ZipEntry scheduleEntry = zipfile.getEntry(DownloadSubjectiveData.SCHEDULE_ENTRY_NAME);
        if (null != scheduleEntry) {
            ObjectInputStream scheduleStream = null;
            try {
                scheduleStream = new ObjectInputStream(zipfile.getInputStream(scheduleEntry));
                _schedule = (TournamentSchedule) scheduleStream.readObject();
            } finally {
                IOUtils.closeQuietly(scheduleStream);
            }
        } else {
            _schedule = null;
        }

        final ZipEntry mappingEntry = zipfile.getEntry(DownloadSubjectiveData.MAPPING_ENTRY_NAME);
        if (null != mappingEntry) {
            ObjectInputStream mappingStream = null;
            try {
                mappingStream = new ObjectInputStream(zipfile.getInputStream(mappingEntry));
                // ObjectStream isn't type safe
                @SuppressWarnings("unchecked")
                final Collection<CategoryColumnMapping> mappings = (Collection<CategoryColumnMapping>) mappingStream
                        .readObject();
                _scheduleColumnMappings = mappings;
            } finally {
                IOUtils.closeQuietly(mappingStream);
            }
        } else {
            _scheduleColumnMappings = null;
        }

    } catch (final ClassNotFoundException e) {
        throw new FLLInternalException("Internal error loading schedule from data file", e);
    } catch (final SAXParseException spe) {
        final String errorMessage = String.format(
                "Error parsing file line: %d column: %d%n Message: %s%n This may be caused by using the wrong version of the software attempting to parse a file that is not subjective data.",
                spe.getLineNumber(), spe.getColumnNumber(), spe.getMessage());
        throw new FLLRuntimeException(errorMessage, spe);
    } catch (final SAXException se) {
        final String errorMessage = "The subjective scores file was found to be invalid, check that you are parsing a subjective scores file and not something else";
        throw new FLLRuntimeException(errorMessage, se);
    } finally {
        if (null != zipfile) {
            try {
                zipfile.close();
            } catch (final IOException e) {
                LOGGER.debug("Error closing zipfile", e);
            }
        }
    }

    for (final ScoreCategory subjectiveCategory : getChallengeDescription().getSubjectiveCategories()) {
        createSubjectiveTable(tabbedPane, subjectiveCategory);
    }

    // get the name and location of the tournament
    final Element top = _scoreDocument.getDocumentElement();
    final String tournamentName = top.getAttribute("tournamentName");
    if (top.hasAttribute("tournamentLocation")) {
        final String tournamentLocation = top.getAttribute("tournamentName");
        setTitle(String.format("Subjective Score Entry - %s @ %s", tournamentName, tournamentLocation));
    } else {
        setTitle(String.format("Subjective Score Entry - %s", tournamentName));
    }

    pack();
}

From source file:com.live.aac_jenius.globalgroupmute.utilities.Updater.java

/**
 * Part of Zip-File-Extractor, modified by Gravity for use with Updater.
 *
 * @param file the location of the file to extract.
 *///from   ww w . ja v  a 2s.c om
private void unzip(String file) {
    final File fSourceZip = new File(file);
    try {
        final String zipPath = file.substring(0, file.length() - 4);
        ZipFile zipFile = new ZipFile(fSourceZip);
        Enumeration<? extends ZipEntry> e = zipFile.entries();
        while (e.hasMoreElements()) {
            ZipEntry entry = e.nextElement();
            File destinationFilePath = new File(zipPath, entry.getName());
            this.fileIOOrError(destinationFilePath.getParentFile(),
                    destinationFilePath.getParentFile().mkdirs(), true);
            if (!entry.isDirectory()) {
                final BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));
                int b;
                final byte[] buffer = new byte[Updater.BYTE_SIZE];
                final FileOutputStream fos = new FileOutputStream(destinationFilePath);
                final BufferedOutputStream bos = new BufferedOutputStream(fos, Updater.BYTE_SIZE);
                while ((b = bis.read(buffer, 0, Updater.BYTE_SIZE)) != -1) {
                    bos.write(buffer, 0, b);
                }
                bos.flush();
                bos.close();
                bis.close();
                final String name = destinationFilePath.getName();
                if (name.endsWith(".jar") && this.pluginExists(name)) {
                    File output = new File(updateFolder, name);
                    this.fileIOOrError(output, destinationFilePath.renameTo(output), true);
                }
            }
        }
        zipFile.close();

        // Move any plugin data folders that were included to the right place, Bukkit won't do this for us.
        moveNewZipFiles(zipPath);

    } catch (final IOException ex) {
        this.sender.sendMessage(
                this.prefix + "The auto-updater tried to unzip a new update file, but was unsuccessful.");
        this.result = Updater.UpdateResult.FAIL_DOWNLOAD;
        this.plugin.getLogger().log(Level.SEVERE, null, ex);
    } finally {
        this.fileIOOrError(fSourceZip, fSourceZip.delete(), false);
    }
}