Example usage for java.util.zip ZipEntry getName

List of usage examples for java.util.zip ZipEntry getName

Introduction

In this page you can find the example usage for java.util.zip ZipEntry getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of the entry.

Usage

From source file:Main.java

public static void unZip(InputStream zipFileIS, String outputFolder) throws IOException {

    byte[] buffer = new byte[1024];

    //create output directory is not exists
    File folder = new File(outputFolder);
    if (!folder.exists()) {
        folder.mkdir();/*from  w ww  . j a  v  a 2  s  .c o m*/
    }

    //get the zip file content
    ZipInputStream zis = new ZipInputStream(zipFileIS);
    //get the zipped file list entry
    ZipEntry ze = zis.getNextEntry();

    while (ze != null) {

        String fileName = ze.getName();
        File newFile = new File(outputFolder + File.separator + fileName);

        if (ze.isDirectory()) {
            newFile.mkdirs();
        } else {

            FileOutputStream fos = new FileOutputStream(newFile);

            int len;
            while ((len = zis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }

            fos.flush();
            fos.close();
        }
        ze = zis.getNextEntry();
    }

    zis.closeEntry();
    zis.close();
}

From source file:Main.java

public static String readChannelString(String path, String prefixString) {
    String ret = null;/* w  ww.  j  a va  2s .  c  o m*/
    ZipFile zipfile = null;
    try {
        zipfile = new ZipFile(path);
        Enumeration<?> entries = zipfile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = ((ZipEntry) entries.nextElement());
            String entryName = entry.getName();
            if (debug) {
                System.out.println(entryName);
            }
            if (entryName.contains(prefixString)) {
                ret = entryName;

                break;
            }
        }

        if (ret != null) {
            String[] split = ret.split("_");
            if (split != null && split.length >= 2) {
                String substring = ret.substring(split[0].length() + 1);
                if (debug) {
                    System.out.println(String.format("find channel string:%s", substring));
                }
                return substring;

            }
        } else {
            if (debug) {
                System.out.println("not find channel");
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (zipfile != null) {
            try {
                zipfile.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    return ret;

}

From source file:cc.recommenders.utils.Zips.java

public static ICoReTypeName type(ZipEntry entry, @Nullable String suffix) {
    String name = StringUtils.removeEnd(entry.getName(), suffix);
    return CoReTypeName.get("L" + name);
}

From source file:eu.freme.eservices.epublishing.Unzipper.java

public static void unzip(ZipInputStream zis, File outputFolder) throws IOException {
    //create output directory is not exists

    if (!outputFolder.exists() && !outputFolder.mkdirs()) {
        throw new IOException("Cannot create directory " + outputFolder);
    }//from w ww.  j a va2s  .com

    //get the zipped file list entry
    ZipEntry ze = zis.getNextEntry();

    while (ze != null) {
        String fileName = ze.getName();
        File newFile = new File(outputFolder, fileName);

        logger.debug("file unzip : " + newFile.getAbsoluteFile());

        //create all non exists folders
        //else you will hit FileNotFoundException for compressed folder
        File parentDir = newFile.getParentFile();
        if (!parentDir.exists() && !parentDir.mkdirs()) {
            throw new IOException("Cannot create directory " + newFile.getParent());
        }

        if (ze.isDirectory()) {
            newFile.mkdirs();
        } else {
            try (FileOutputStream fos = new FileOutputStream(newFile)) {
                IOUtils.copyLarge(zis, fos);
            }
        }
        ze = zis.getNextEntry();
    }
    zis.closeEntry();
}

From source file:cc.recommenders.utils.Zips.java

public static ICoReMethodName method(ZipEntry e, String suffix) {
    String name = "L" + StringUtils.substringBefore(e.getName(), suffix);
    int start = name.lastIndexOf('/');
    char[] chars = name.toCharArray();
    chars[start] = '.';
    for (int i = start + 1; i < chars.length; i++) {
        if (chars[i] == '.')
            chars[i] = '/';
    }/*from  w w  w .  jav  a 2 s .co  m*/
    return CoReMethodName.get(new String(chars));
}

From source file:Main.java

public static void unZip(String zipFile, String outputFolder) throws IOException {

    byte[] buffer = new byte[1024];

    //create output directory is not exists
    File folder = new File(outputFolder);
    if (!folder.exists()) {
        folder.mkdir();/*w  w  w  .  j a va  2  s. c om*/
    }

    //get the zip file content
    ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile));
    //get the zipped file list entry
    ZipEntry ze = zis.getNextEntry();

    while (ze != null) {

        String fileName = ze.getName();
        File newFile = new File(outputFolder + File.separator + fileName);

        //create all non exists folders
        //else you will hit FileNotFoundException for compressed folder
        if (ze.isDirectory())
            newFile.mkdirs();
        else {
            newFile.getParentFile().mkdirs();

            FileOutputStream fos = new FileOutputStream(newFile);

            int len;
            while ((len = zis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }

            fos.close();
        }
        ze = zis.getNextEntry();
    }

    zis.closeEntry();
    zis.close();

}

From source file:ZipHandler.java

private static void ExtractZip(ZipInputStream zis, FileOutputStream fos, FileOutputStream fosBLOB,
        FileOutputStream fosCLOB, ZipEntry ze) throws IOException {
    if (ze.getName().equalsIgnoreCase("blob.lob"))
        writeInOutputStream(zis, fosBLOB);
    else if (ze.getName().equalsIgnoreCase("clob.lob"))
        writeInOutputStream(zis, fosCLOB);
    else/*from  w ww.j  av  a2s . com*/
        writeInOutputStream(zis, fos);
}

From source file:eu.openanalytics.rsb.AbstractITCase.java

public static void validateZipResult(final InputStream responseStream) throws IOException {
    final ZipInputStream result = new ZipInputStream(responseStream);
    ZipEntry ze = null;

    while ((ze = result.getNextEntry()) != null) {
        if (ze.getName().endsWith(".pdf")) {
            return;
        }//  w w  w  .j  a v a  2 s.c  om
    }

    fail("No PDF file found in Zip result");
}

From source file:com.opoopress.maven.plugins.plugin.zip.ZipUtils.java

public static void unzipFileToDirectory(File file, File destDir, boolean keepTimestamp) throws IOException {
    // create output directory if it doesn't exist
    if (!destDir.exists())
        destDir.mkdirs();/*from w  w w .  jav  a2  s  .co  m*/

    ZipFile zipFile = new ZipFile(file);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        if (entry.isDirectory()) {
            new File(destDir, entry.getName()).mkdirs();
            continue;
        }

        InputStream inputStream = zipFile.getInputStream(entry);
        File destFile = new File(destDir, entry.getName());

        System.out.println("Unzipping to " + destFile.getAbsolutePath());
        FileUtils.copyInputStreamToFile(inputStream, destFile);
        IOUtils.closeQuietly(inputStream);

        if (keepTimestamp) {
            long time = entry.getTime();
            if (time > 0) {
                destFile.setLastModified(time);
            }
        }
    }

    zipFile.close();
}

From source file:gov.va.oia.terminology.converters.sharedUtils.Unzip.java

public final static void unzip(File zipFile, File rootDir) throws IOException {
    ZipFile zip = new ZipFile(zipFile);
    @SuppressWarnings("unchecked")
    Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zip.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        java.io.File f = new java.io.File(rootDir, entry.getName());
        if (entry.isDirectory()) {
            f.mkdirs();//from  w  w w .  j a  v a  2  s  .  co  m
            continue;
        } else {
            f.createNewFile();
        }
        InputStream is = null;
        OutputStream os = null;
        try {
            is = zip.getInputStream(entry);
            os = new FileOutputStream(f);
            IOUtils.copy(is, os);
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (Exception e) {
                    // noop
                }
            }
            if (os != null) {
                try {
                    os.close();
                } catch (Exception e) {
                    // noop
                }
            }
        }
    }
    zip.close();
}