Example usage for java.util.zip ZipFile entries

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

Introduction

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

Prototype

public Enumeration<? extends ZipEntry> entries() 

Source Link

Document

Returns an enumeration of the ZIP file entries.

Usage

From source file:com.pari.nm.utils.backup.BackupRestore.java

public boolean unzip(File zipFile) {
    ZipFile zf = null;
    FileOutputStream fout = null;
    // File zipFile = new File(localDir, zipFileName);

    try {//from   w  ww. j  a  v  a2s.  c om
        zf = new ZipFile(zipFile);

        Enumeration en = zf.entries();

        while (en.hasMoreElements()) {
            ZipEntry ze = (ZipEntry) en.nextElement();
            String currentEntry = ze.getName();
            File destFile = new File(zipFile.getParent(), currentEntry);
            File destinationParent = destFile.getParentFile();
            if (!destinationParent.exists()) {
                destinationParent.mkdirs();
                destinationParent.setWritable(true, false);
            }
            System.err.println("ZIP ENTRY NAME:" + currentEntry);
            if (!ze.isDirectory()) {
                InputStream in = zf.getInputStream(ze);
                byte[] data = new byte[4096];
                int read = 0;

                File extractFile = new File(zipFile.getParent(), ze.getName());
                fout = new FileOutputStream(extractFile);

                while ((read = in.read(data)) != -1) {
                    fout.write(data, 0, read);
                }

                fout.close();
            }
        }
        return true;
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (zf != null) {
                zf.close();
            }
        } catch (Exception ex) {
        }

        try {
            if (fout != null) {
                fout.close();
            }
        } catch (Exception ex) {
        }
    }

    return false;
}

From source file:org.bdval.BDVModel.java

/**
 * Load the BDVModel training platform from the specified zip file.
 *
 * @param zipFile The file to read the platform from
 * @return A populated platform object//from w w  w.  j  a v  a  2  s  . c o m
 * @throws IOException if there is a problem reading from the file
 */
private GEOPlatformIndexed loadPlatform(final ZipFile zipFile) throws IOException {
    final String platformEntryName = FilenameUtils.getName(platformFilename);
    final Map<String, java.util.Properties> propertyMap = new HashMap<String, java.util.Properties>();
    final Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements()) {
        final ZipEntry entry = entries.nextElement();
        final String entryName = entry.getName();
        if (entryName.startsWith(platformEntryName)) {
            // we have a platform entry
            final String propertyName = StringUtils.substringBetween(entryName, platformEntryName + ".",
                    "." + ModelFileExtension.properties.toString());
            final java.util.Properties properties = new java.util.Properties();
            properties.load(zipFile.getInputStream(entry));
            propertyMap.put(propertyName, properties);
        }
    }

    return new GEOPlatformIndexed(propertyMap);
}

From source file:com.ichi2.libanki.Media.java

/**
 * Extract zip data; return the number of files extracted. Unlike the python version, this method consumes a
 * ZipFile stored on disk instead of a String buffer. Holding the entire downloaded data in memory is not feasible
 * since some devices can have very limited heap space.
 *
 * This method closes the file before it returns.
 */// www.  j  a  v  a 2  s  .c o  m
public int addFilesFromZip(ZipFile z) throws IOException {
    try {
        List<Object[]> media = new ArrayList<Object[]>();
        // get meta info first
        JSONObject meta = new JSONObject(Utils.convertStreamToString(z.getInputStream(z.getEntry("_meta"))));
        // then loop through all files
        int cnt = 0;
        for (ZipEntry i : Collections.list(z.entries())) {
            if (i.getName().equals("_meta")) {
                // ignore previously-retrieved meta
                continue;
            } else {
                String name = meta.getString(i.getName());
                // normalize name for platform
                name = HtmlUtil.nfcNormalized(name);
                // save file
                String destPath = dir().concat(File.separator).concat(name);
                Utils.writeToFile(z.getInputStream(i), destPath);
                String csum = Utils.fileChecksum(destPath);
                // update db
                media.add(new Object[] { name, csum, _mtime(destPath), 0 });
                cnt += 1;
            }
        }
        if (media.size() > 0) {
            mDb.executeMany("insert or replace into media values (?,?,?,?)", media);
        }
        return cnt;
    } catch (JSONException e) {
        throw new RuntimeException(e);
    } finally {
        z.close();
    }
}

From source file:com.taobao.android.tools.TPatchTool.java

/**
 * ?patchpatchInfo//from  w  w  w . ja va 2 s  . co  m
 *
 * @param fileName
 * @return
 */
public PatchInfo createBasePatchInfo(File file) {
    PatchInfo patchInfo = new PatchInfo();
    patchInfo.setPatchVersion(input.newApkBo.getVersionName());
    patchInfo.setTargetVersion(input.baseApkBo.getVersionName());
    patchInfo.setFileName(file.getName());
    Set<String> modifyBundles = new HashSet<>();
    ZipFile zipFile = newZipFile(file);
    Enumeration<? extends ZipEntry> enumeration = zipFile.entries();
    while (enumeration.hasMoreElements()) {
        ZipEntry zipEntry = enumeration.nextElement();
        if (zipEntry.getName().startsWith("lib") && zipEntry.getName().indexOf("/") != -1) {
            modifyBundles
                    .add(zipEntry.getName().substring(3, zipEntry.getName().indexOf("/")).replace("_", "."));
        } else if (zipEntry.getName().endsWith(".so") && zipEntry.getName().indexOf("/") == -1) {
            modifyBundles.add(
                    zipEntry.getName().substring(3, zipEntry.getName().lastIndexOf(".")).replace("_", "."));
        }

    }

    for (ArtifactBundleInfo artifactBundleInfo : input.artifactBundleInfos) {
        if (artifactBundleInfo.getMainBundle()) {
            if (DiffType.MODIFY.equals(artifactBundleInfo.getDiffType()) || hasMainBundle) {
                PatchBundleInfo patchBundleInfo = new PatchBundleInfo();
                patchBundleInfo.setNewBundle(DiffType.ADD.equals(artifactBundleInfo.getDiffType()));
                patchBundleInfo.setMainBundle(true);
                patchBundleInfo.setVersion(artifactBundleInfo.getVersion());
                patchBundleInfo.setName(((TpatchInput) input).mainBundleName);
                patchBundleInfo.setSrcUnitTag(artifactBundleInfo.getSrcUnitTag());
                patchBundleInfo.setUnitTag(artifactBundleInfo.getUnitTag());
                patchBundleInfo.setPatchType(bundleTypes.get(((TpatchInput) input).mainBundleName) == null ? 0
                        : bundleTypes.get(((TpatchInput) input).mainBundleName));
                patchBundleInfo.setApplicationName(artifactBundleInfo.getApplicationName());
                patchBundleInfo.setArtifactId(artifactBundleInfo.getArtifactId());
                patchBundleInfo.setPkgName(artifactBundleInfo.getPkgName());
                patchBundleInfo.setDependency(artifactBundleInfo.getDependency());
                patchBundleInfo.setBaseVersion(artifactBundleInfo.getBaseVersion());
                patchInfo.getBundles().add(patchBundleInfo);
                continue;
            }
        } else if (DiffType.MODIFY.equals(artifactBundleInfo.getDiffType())
                || DiffType.ADD.equals(artifactBundleInfo.getDiffType())) {
            PatchBundleInfo patchBundleInfo = new PatchBundleInfo();
            patchBundleInfo.setNewBundle(DiffType.ADD.equals(artifactBundleInfo.getDiffType()));
            patchBundleInfo.setMainBundle(false);
            patchBundleInfo.setSrcUnitTag(artifactBundleInfo.getSrcUnitTag());
            patchBundleInfo.setUnitTag(artifactBundleInfo.getUnitTag());
            patchBundleInfo.setVersion(artifactBundleInfo.getVersion());
            patchBundleInfo.setPatchType(bundleTypes.get(artifactBundleInfo.getPkgName()) == null ? 0
                    : bundleTypes.get(artifactBundleInfo.getPkgName()));
            patchBundleInfo.setName(artifactBundleInfo.getPkgName());
            if (!modifyBundles.contains(artifactBundleInfo.getPkgName().replace("_", "."))) {
                patchBundleInfo.setInherit(true);
            }
            patchBundleInfo.setApplicationName(artifactBundleInfo.getApplicationName());
            patchBundleInfo.setArtifactId(artifactBundleInfo.getArtifactId());
            patchBundleInfo.setPkgName(artifactBundleInfo.getPkgName());
            patchBundleInfo.setDependency(artifactBundleInfo.getDependency());
            patchBundleInfo.setBaseVersion(artifactBundleInfo.getBaseVersion());
            patchInfo.getBundles().add(patchBundleInfo);
        } else if (modifyBundles.contains(artifactBundleInfo.getPkgName().replace("_", "."))) {
            PatchBundleInfo patchBundleInfo = new PatchBundleInfo();
            patchBundleInfo.setNewBundle(false);
            patchBundleInfo.setMainBundle(false);
            patchBundleInfo.setPatchType(bundleTypes.get(artifactBundleInfo.getPkgName()) == null ? 0
                    : bundleTypes.get(artifactBundleInfo.getPkgName()));
            patchBundleInfo.setSrcUnitTag(artifactBundleInfo.getSrcUnitTag());
            patchBundleInfo.setUnitTag(artifactBundleInfo.getUnitTag());
            patchBundleInfo.setVersion(artifactBundleInfo.getVersion());
            patchBundleInfo.setName(artifactBundleInfo.getName());
            patchBundleInfo.setApplicationName(artifactBundleInfo.getApplicationName());
            patchBundleInfo.setArtifactId(artifactBundleInfo.getArtifactId());
            patchBundleInfo.setPkgName(artifactBundleInfo.getPkgName());
            patchBundleInfo.setDependency(artifactBundleInfo.getDependency());
            patchBundleInfo.setBaseVersion(artifactBundleInfo.getBaseVersion());
            patchInfo.getBundles().add(patchBundleInfo);
            if (artifactBundleInfo.getUnitTag().equals(artifactBundleInfo.getSrcUnitTag())) {
                throw new RuntimeException(artifactBundleInfo.getPkgName()
                        + "has contents change,but unitTag equals srcUnitTag" + artifactBundleInfo.getUnitTag()
                        + ",please upgrade bundle version and reintegration");
            }
        }
    }

    try {
        zipFile.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return patchInfo;
}

From source file:com.esd.ps.EmployerController.java

/**
 * ? zip/* w w w.jav a2 s.c  o m*/
 * 
 * @param packName
 * @param taskLvl
 */
public void storeDataZIP(String packName, int taskLvl, String url, int userId, Date date) {
    InputStream in = null;
    String zipEntryName = null;
    int packId = 0;
    try {
        ZipFile zip = new ZipFile(url + Constants.SLASH + packName);
        for (Enumeration<?> entries = zip.entries(); entries.hasMoreElements();) {
            ZipEntry entry = (ZipEntry) entries.nextElement();
            String taskDir = Constants.EMPTY;
            if (entry.isDirectory()) {// ?
                continue;
            }
            zipEntryName = entry.getName();
            if (zipEntryName.indexOf(Constants.SLASH) < zipEntryName.lastIndexOf(Constants.SLASH)) {
                String str[] = zipEntryName.split(Constants.SLASH);
                // (zipEntryName.indexOf("/") + 1)
                taskDir = zipEntryName.substring((zipEntryName.indexOf(Constants.SLASH) + 1),
                        zipEntryName.lastIndexOf(Constants.SLASH));
                zipEntryName = str[(str.length - 1)];
            }
            zipEntryName = zipEntryName.substring(zipEntryName.indexOf(Constants.SLASH) + 1,
                    zipEntryName.length());
            // ?
            if (zipEntryName.substring((zipEntryName.length() - 3), zipEntryName.length())
                    .equals(Constants.WAV) == false) {
                // String noMatch = zipEntryName;
                continue;
            }
            in = zip.getInputStream(entry);
            // inputstrem?byte[]
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            byte[] data = new byte[4096];
            int count = -1;
            while ((count = in.read(data, 0, 4096)) != -1)
                outStream.write(data, 0, count);
            data = null;
            byte[] wav = outStream.toByteArray();

            taskWithBLOBs taskWithBLOBs = new taskWithBLOBs();
            packId = packService.getPackIdByPackName(packName);
            // wav?0kb
            if (outStream.size() == 0) {
                taskWithBLOBs.setWorkerId(0);
            }
            taskWithBLOBs.setTaskWav(wav);
            taskWithBLOBs.setTaskLvl(taskLvl);
            // ?
            taskWithBLOBs.setPackId(packId);
            taskWithBLOBs.setTaskName(zipEntryName);
            // 
            if (taskDir.trim().length() > 0) {
                taskDir = packName.substring(0, (packName.length() - 4)) + Constants.SLASH + taskDir;
            } else {
                taskDir = packName.substring(0, (packName.length() - 4));
            }
            taskWithBLOBs.setTaskDir(taskDir);
            taskWithBLOBs.setCreateId(userId);
            taskWithBLOBs.setCreateTime(date);
            // ?
            taskWithBLOBs.setTaskUpload(false);
            StackTraceElement[] items = Thread.currentThread().getStackTrace();
            taskWithBLOBs.setCreateMethod(items[1].toString());
            taskWithBLOBs.setVersion(1);
            taskService.insert(taskWithBLOBs);
        }
        zip.close();
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    File fd = new File(packName);
    fd.delete();
    packWithBLOBs pack = new packWithBLOBs();
    pack.setPackId(packId);
    pack.setUnzip(2);// ??
    StackTraceElement[] items = Thread.currentThread().getStackTrace();
    pack.setUpdateMethod(items[1].toString());
    packService.updateByPrimaryKeySelective(pack);
}

From source file:org.openmrs.module.dhisconnector.api.impl.DHISConnectorServiceImpl.java

@SuppressWarnings("rawtypes")
@Override//from  w  ww .  j a v  a2  s .  c o  m
public String uploadMappings(MultipartFile mapping) {
    String msg = "";
    String tempFolderName = OpenmrsUtil.getApplicationDataDirectory() + DHISCONNECTOR_TEMP_FOLDER
            + File.separator;
    String mappingFolderName = OpenmrsUtil.getApplicationDataDirectory() + DHISCONNECTOR_MAPPINGS_FOLDER
            + File.separator;
    String mappingName = mapping.getOriginalFilename();

    if (mappingName.endsWith(".zip")) {
        boolean allFailed = true;
        File tempMappings = new File(tempFolderName + mappingName);

        (new File(tempFolderName)).mkdirs();
        try {
            mapping.transferTo(tempMappings);

            try {
                ZipFile zipfile = new ZipFile(tempMappings);

                for (Enumeration e = zipfile.entries(); e.hasMoreElements();) {
                    ZipEntry entry = (ZipEntry) e.nextElement();

                    if (entry.isDirectory()) {
                        System.out.println("Incorrect file (Can't be a folder instead): " + entry.getName()
                                + " has been ignored");
                    } else if (entry.getName().endsWith(DHISCONNECTOR_MAPPING_FILE_SUFFIX)) {
                        File outputFile = new File(mappingFolderName, entry.getName());

                        if (outputFile.exists()) {
                            System.out.println(
                                    "File: " + outputFile.getName() + " already exists and has been ignored");
                        } else {
                            BufferedInputStream inputStream = new BufferedInputStream(
                                    zipfile.getInputStream(entry));
                            BufferedOutputStream outputStream = new BufferedOutputStream(
                                    new FileOutputStream(outputFile));

                            try {
                                System.out.println("Extracting: " + entry);
                                IOUtils.copy(inputStream, outputStream);
                                allFailed = false;
                            } finally {
                                outputStream.close();
                                inputStream.close();
                            }
                        }
                    } else {
                        System.out.println("Incorrect file: " + entry.getName() + " has been ignored");
                    }
                }
                if (!allFailed) {
                    msg = Context.getMessageSourceService()
                            .getMessage("dhisconnector.uploadMapping.groupSuccess");
                } else {
                    msg = Context.getMessageSourceService().getMessage("dhisconnector.uploadMapping.allFailed");
                }
                FileUtils.deleteDirectory(new File(tempFolderName));
            } catch (Exception e) {
                System.out.println("Error while extracting file:" + mapping.getName() + " ; " + e);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else if (mappingName.endsWith(DHISCONNECTOR_MAPPING_FILE_SUFFIX)) {
        try {
            File uploadedMapping = new File(mappingFolderName + mappingName);
            if (uploadedMapping.exists()) {
                msg = Context.getMessageSourceService().getMessage("dhisconnector.uploadMapping.exists");
            } else {
                mapping.transferTo(uploadedMapping);
                msg = Context.getMessageSourceService().getMessage("dhisconnector.uploadMapping.singleSuccess");
            }

        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        msg = Context.getMessageSourceService().getMessage("dhisconnector.uploadMapping.wrongType");
    }

    return msg;
}

From source file:com.meltmedia.cadmium.core.util.WarUtils.java

/**
 * <p>This method updates a template war with the following settings.</p>
 * @param templateWar The name of the template war to pull from the classpath.
 * @param war The path of an external war to update (optional).
 * @param newWarNames The name to give the new war. (note: only the first element of this list is used.)
 * @param repoUri The uri to a github repo to pull content from.
 * @param branch The branch of the github repo to pull content from.
 * @param configRepoUri The uri to a github repo to pull config from.
 * @param configBranch The branch of the github repo to pull config from.
 * @param domain The domain to bind a vHost to.
 * @param context The context root that this war will deploy to.
 * @param secure A flag to set if this war needs to have its contents password protected.
 * @throws Exception//w  w  w  .  j  ava  2 s  . co  m
 */
public static void updateWar(String templateWar, String war, List<String> newWarNames, String repoUri,
        String branch, String configRepoUri, String configBranch, String domain, String context, boolean secure,
        Logger log) throws Exception {
    ZipFile inZip = null;
    ZipOutputStream outZip = null;
    InputStream in = null;
    OutputStream out = null;
    try {
        if (war != null) {
            if (war.equals(newWarNames.get(0))) {
                File tmpZip = File.createTempFile(war, null);
                tmpZip.delete();
                tmpZip.deleteOnExit();
                new File(war).renameTo(tmpZip);
                war = tmpZip.getAbsolutePath();
            }
            inZip = new ZipFile(war);
        } else {
            File tmpZip = File.createTempFile("cadmium-war", "war");
            tmpZip.delete();
            tmpZip.deleteOnExit();
            in = WarUtils.class.getClassLoader().getResourceAsStream(templateWar);
            out = new FileOutputStream(tmpZip);
            FileSystemManager.streamCopy(in, out);
            inZip = new ZipFile(tmpZip);
        }
        outZip = new ZipOutputStream(new FileOutputStream(newWarNames.get(0)));

        ZipEntry cadmiumPropertiesEntry = null;
        cadmiumPropertiesEntry = inZip.getEntry("WEB-INF/cadmium.properties");

        Properties cadmiumProps = updateProperties(inZip, cadmiumPropertiesEntry, repoUri, branch,
                configRepoUri, configBranch);

        ZipEntry jbossWeb = null;
        jbossWeb = inZip.getEntry("WEB-INF/jboss-web.xml");

        Enumeration<? extends ZipEntry> entries = inZip.entries();
        while (entries.hasMoreElements()) {
            ZipEntry e = entries.nextElement();
            if (e.getName().equals(cadmiumPropertiesEntry.getName())) {
                storeProperties(outZip, cadmiumPropertiesEntry, cadmiumProps, newWarNames);
            } else if (((domain != null && domain.length() > 0) || (context != null && context.length() > 0))
                    && e.getName().equals(jbossWeb.getName())) {
                updateDomain(inZip, outZip, jbossWeb, domain, context);
            } else if (secure && e.getName().equals("WEB-INF/web.xml")) {
                addSecurity(inZip, outZip, e);
            } else {
                outZip.putNextEntry(e);
                if (!e.isDirectory()) {
                    FileSystemManager.streamCopy(inZip.getInputStream(e), outZip, true);
                }
                outZip.closeEntry();
            }
        }
    } finally {
        if (FileSystemManager.exists("tmp_cadmium-war.war")) {
            new File("tmp_cadmium-war.war").delete();
        }
        try {
            if (inZip != null) {
                inZip.close();
            }
        } catch (Exception e) {
            if (log != null) {
                log.error("Failed to close " + war);
            }
        }
        try {
            if (outZip != null) {
                outZip.close();
            }
        } catch (Exception e) {
            if (log != null) {
                log.error("Failed to close " + newWarNames.get(0));
            }
        }
        try {
            if (out != null) {
                out.close();
            }
        } catch (Exception e) {
        }
        try {
            if (in != null) {
                in.close();
            }
        } catch (Exception e) {
        }
    }

}

From source file:org.geosdi.geoplatform.services.GPPublisherBasicServiceImpl.java

/**
 * ************//from   w w w.  ja  v a2  s .  co m
 *
 * @param file the ZIP file from where extracting the info
 * @return the information of the shapefile this method extracts from a zip
 * file containing the shape files, the name, the CRS and the geometry types
 */
private List<LayerInfo> getInfoFromCompressedFile(String userName, File file, String tempUserDir,
        String tempUserZipDir, String tempUserTifDir, String workspace) throws ResourceNotFoundFault {
    logger.debug("Call to getInfoFromCompressedShape");
    System.setProperty("org.geotools.referencing.forceXY", "true");
    List<String> shpEntryNameList = Lists.<String>newArrayList();
    List<String> tifEntryNameList = Lists.<String>newArrayList();
    List<ZipEntry> sldEntryList = Lists.<ZipEntry>newArrayList();
    List<ZipEntry> prjEntryList = Lists.<ZipEntry>newArrayList();
    List<LayerInfo> infoShapeList = Lists.<LayerInfo>newArrayList();
    ZipFile zipSrc = null;
    try {
        // decomprime il contenuto di file nella cartella <tmp>/geoportal/shp
        zipSrc = new ZipFile(file);
        Enumeration<? extends ZipEntry> entries = zipSrc.entries();
        String destinationDir;
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            String entryName = entry.getName();
            File newFile = new File(entryName);
            if (newFile.isDirectory()) {
                continue;
            }
            //   entryName = entryName.replaceAll("/", "_");
            //    logger.info("\n ********** INFO:"+entryName);

            int lastIndex = entryName.lastIndexOf('/');
            entryName = entryName.substring(lastIndex + 1).toLowerCase();
            destinationDir = tempUserDir;
            if (GPSharedUtils.isEmpty(entryName) || entryName.startsWith(".")
                    || entryName.equalsIgnoreCase("__MACOSX")) {
                continue;
            } else if (entryName.endsWith(".tif") || entryName.endsWith(".tiff")) {
                logger.info("INFO: Found geotiff file " + entryName);
                tifEntryNameList.add(entryName);
                destinationDir = tempUserTifDir;
            } else if (entryName.endsWith(".shp")) {
                logger.info("INFO: Found shape file " + entryName);
                shpEntryNameList.add(entryName);
            } else if (entryName.endsWith(".sld")) {
                logger.info("Adding sld to entry list: " + entryName);
                sldEntryList.add(entry);
                continue;
            } else if (entryName.endsWith(".prj")) {
                logger.info("Adding prj to entry list: " + entryName);
                prjEntryList.add(entry);
                continue;
            } else if (entryName.endsWith(".tfw")) {
                destinationDir = tempUserTifDir;
            }
            PublishUtility.extractEntryToFile(entry, zipSrc, destinationDir);
        }
        //Verificare presenza file sld associato a geotiff oppure a shp file
        this.putEntryInTheRightDir(sldEntryList, zipSrc, tempUserTifDir, tempUserDir, tifEntryNameList);
        this.putEntryInTheRightDir(prjEntryList, zipSrc, tempUserTifDir, tempUserDir, tifEntryNameList);
        // fine decompressione
    } catch (Exception e) {
        logger.error("ERROR: " + e);
        throw new IllegalArgumentException("ERROR: " + e);
    } finally {
        try {
            zipSrc.close();
        } catch (IOException ex) {
        }
    }
    infoShapeList
            .addAll(this.analyzeShpList(shpEntryNameList, userName, tempUserDir, tempUserZipDir, workspace));
    infoShapeList.addAll(this.analyzeTifList(tifEntryNameList, userName, tempUserTifDir, workspace));
    // svuota la cartella degli shape <tmp>/geoportal/UserDir
    File directory = new File(tempUserDir);
    File[] files = directory.listFiles();
    for (File f : files) {
        f.delete();
    }
    return infoShapeList;
}

From source file:com.ephesoft.dcma.webservice.service.EphesoftWebService.java

private void renameZipFileEntries(final File oldZipFile, final BatchClass batchClass,
        final String oldBatchInstanceIdentifier, final String newBatchInstanceIdentfier) {
    LOGGER.info("Zip files to be modified " + oldZipFile.getAbsolutePath());
    String finalZipPath = oldZipFile.getAbsolutePath();
    File finalZipFile = new File(finalZipPath);

    String destDirectory = finalZipFile.getParent();
    String unzippedFilePath = finalZipFile.getAbsolutePath();
    LOGGER.info("Unziping the " + unzippedFilePath + CONSTANT_TO + destDirectory);

    FileUtils.unzip(finalZipFile, destDirectory);
    ZipFile zipFile = null;
    try {/*from w  w  w  . java2 s.  co m*/
        zipFile = new ZipFile(finalZipFile);

        // Only 1st entry picked. Considering that our zip file contains only a single file.
        String xmlFileName = zipFile.entries().nextElement().getName();

        StringBuilder xmlFileNameBuilder = new StringBuilder();
        xmlFileNameBuilder.append(destDirectory);
        xmlFileNameBuilder.append(File.separator);
        xmlFileNameBuilder.append(xmlFileName);
        String xmlFilePath = xmlFileNameBuilder.toString();
        File xmlFile = new File(xmlFilePath);

        xmlFileName = xmlFileName.replaceAll(oldBatchInstanceIdentifier, newBatchInstanceIdentfier);
        StringBuilder newXmlFileNameBuilder = new StringBuilder();
        newXmlFileNameBuilder.append(destDirectory);
        newXmlFileNameBuilder.append(File.separator);
        newXmlFileNameBuilder.append(xmlFileName);
        String newXmlFilePath = newXmlFileNameBuilder.toString();
        File newXmlFile = new File(newXmlFilePath);

        LOGGER.info("Renaming " + unzippedFilePath + CONSTANT_TO + xmlFileName);

        xmlFile.renameTo(newXmlFile);

        List<String> fileNames = new ArrayList<String>();
        fileNames.add(newXmlFile.getAbsolutePath());

        LOGGER.info("Zipping the altered files to " + finalZipPath);

        FileUtils.zipMultipleFiles(fileNames, finalZipPath);
        updateTranferredBatch(newBatchInstanceIdentfier, batchClass, oldBatchInstanceIdentifier);
        newXmlFile.delete();
    } catch (ZipException e) {
        LOGGER.error("Error Creating zip file " + e.getMessage(), e);
    } catch (IOException e) {
        LOGGER.error("I/O Error while Creating zip file " + e.getMessage(), e);
    }

}