Example usage for java.util.zip ZipInputStream getNextEntry

List of usage examples for java.util.zip ZipInputStream getNextEntry

Introduction

In this page you can find the example usage for java.util.zip ZipInputStream getNextEntry.

Prototype

public ZipEntry getNextEntry() throws IOException 

Source Link

Document

Reads the next ZIP file entry and positions the stream at the beginning of the entry data.

Usage

From source file:functionalTests.vfsprovider.TestProActiveProvider.java

public static void extractZip(final ZipInputStream zipStream, final File dstFile) throws IOException {
    ZipEntry zipEntry;/*from ww  w . ja  va 2  s.c  om*/
    while ((zipEntry = zipStream.getNextEntry()) != null) {
        final File dstSubFile = new File(dstFile, zipEntry.getName());

        if (zipEntry.isDirectory()) {
            dstSubFile.mkdirs();
            if (!dstSubFile.exists() || !dstSubFile.isDirectory())
                throw new IOException("Could not create directory: " + dstSubFile);
        } else {
            final OutputStream os = new BufferedOutputStream(new FileOutputStream(dstSubFile));
            try {
                int data;
                while ((data = zipStream.read()) != -1)
                    os.write(data);
            } finally {
                os.close();
            }
        }
    }
}

From source file:ee.ria.xroad.common.asic.AsicHelper.java

static AsicContainer read(InputStream is) throws Exception {
    Map<String, String> entries = new HashMap<>();
    ZipInputStream zip = new ZipInputStream(is);
    ZipEntry zipEntry;//from   ww w .  ja v  a  2s.  co  m

    while ((zipEntry = zip.getNextEntry()) != null) {
        for (Object expectedEntry : AsicContainerEntries.getALL_ENTRIES()) {
            if (matches(expectedEntry, zipEntry.getName())) {
                String data;

                if (ENTRY_TIMESTAMP.equalsIgnoreCase(zipEntry.getName())) {
                    data = encodeBase64(getBinaryData(zip));
                } else {
                    data = getData(zip);
                }

                entries.put(zipEntry.getName(), data);

                break;
            }
        }
    }

    return new AsicContainer(entries);
}

From source file:Main.java

/**
 * //www  .jav  a2  s .  c  om
 * @param zipFile
 *            zip file
 * @param folderName
 *            folder to load
 * @return list of entry in the folder
 * @throws ZipException
 * @throws IOException
 */
public static List<ZipEntry> loadFiles(File zipFile, String folderName) throws ZipException, IOException {
    Log.d("loadFiles", folderName);
    long start = System.currentTimeMillis();
    FileInputStream fis = new FileInputStream(zipFile);
    BufferedInputStream bis = new BufferedInputStream(fis);
    ZipInputStream zis = new ZipInputStream(bis);

    ZipEntry zipEntry = null;
    List<ZipEntry> list = new LinkedList<ZipEntry>();
    String folderLowerCase = folderName.toLowerCase();
    int counter = 0;
    while ((zipEntry = zis.getNextEntry()) != null) {
        counter++;
        String zipEntryName = zipEntry.getName();
        Log.d("loadFiles.zipEntry.getName()", zipEntryName);
        if (zipEntryName.toLowerCase().startsWith(folderLowerCase) && !zipEntry.isDirectory()) {
            list.add(zipEntry);
        }
    }
    Log.d("Loaded 1", counter + " files, took: " + (System.currentTimeMillis() - start) + " milliseconds.");
    zis.close();
    bis.close();
    fis.close();
    return list;
}

From source file:Main.java

/** Returns an InputStream that will read a specific entry
 * from a zip file./*from   w  ww .  j a v a 2s  . c  om*/
 * @param file the zip file.
 * @param entryName the name of the entry.
 * @return an InputStream that reads that entry.
 * @throws IOException
 */
public static InputStream getZipEntry(File file, String entryName) throws IOException {
    FileInputStream in = new FileInputStream(file);
    ZipInputStream zipIn = new ZipInputStream(in);
    ZipEntry e = zipIn.getNextEntry();
    while (e != null) {
        if (e.getName().equals(entryName))
            return zipIn;
        e = zipIn.getNextEntry();
    }
    return null;
}

From source file:com.ikon.util.ArchiveUtils.java

/**
 * Read file from ZIP//from  w  w w .  j av a2  s. c  om
 */
public static byte[] readFileFromZip(ZipInputStream zis, String filename) throws IOException {
    ZipEntry zi = null;
    byte content[] = null;

    while ((zi = zis.getNextEntry()) != null) {
        if (filename.equals(zi.getName())) {
            IOUtils.toByteArray(zis);
            break;
        }
    }

    return content;
}

From source file:com.ikon.util.ArchiveUtils.java

/**
 * Read file from ZIP//from  w  w  w . jav a2 s  .com
 */
public static InputStream getInputStreamFromZip(ZipInputStream zis, String filename) throws IOException {
    ZipEntry zi = null;
    InputStream is = null;

    while ((zi = zis.getNextEntry()) != null) {
        if (filename.equals(zi.getName())) {
            is = zis;
            break;
        }
    }

    return is;
}

From source file:be.fedict.eid.applet.service.signer.odf.ODFSignatureVerifier.java

/**
 * return list of signers for the document available via the given
 * URL.//from   w  w w .  j a  va 2s. c om
 *
 * @param odfUrl
 * @return list of X509 certificates
 * @throws IOException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws MarshalException
 * @throws XMLSignatureException
 */
public static List<X509Certificate> getSigners(URL odfUrl) throws IOException, ParserConfigurationException,
        SAXException, MarshalException, XMLSignatureException {
    List<X509Certificate> signers = new LinkedList<X509Certificate>();
    if (null == odfUrl) {
        throw new IllegalArgumentException("odfUrl is null");
    }
    ZipInputStream odfZipInputStream = new ZipInputStream(odfUrl.openStream());
    ZipEntry zipEntry;

    while (null != (zipEntry = odfZipInputStream.getNextEntry())) {
        if (ODFUtil.isSignatureFile(zipEntry)) {
            Document documentSignatures = ODFUtil.loadDocument(odfZipInputStream);
            NodeList signatureNodeList = documentSignatures.getElementsByTagNameNS(XMLSignature.XMLNS,
                    "Signature");

            for (int idx = 0; idx < signatureNodeList.getLength(); idx++) {
                Node signatureNode = signatureNodeList.item(idx);
                X509Certificate signer = getVerifiedSignatureSigner(odfUrl, signatureNode);
                if (null == signer) {
                    LOG.debug("JSR105 says invalid signature");
                } else {
                    signers.add(signer);
                }
            }
            return signers;
        }
    }
    LOG.debug("no signature file present");
    return signers;
}

From source file:com.termmed.utils.ResourceUtils.java

/**
 * Gets the resource scripts.// w w  w  .  j  av a  2 s.  co m
 *
 * @param path the path
 * @return the resource scripts
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static Collection<String> getResourceScripts(String path) throws IOException {
    System.out.println("getting files from " + path);
    List<String> strFiles = new ArrayList<String>();

    //      InputStream is=ResourceUtils.class.getResourceAsStream("/" + path);
    //      InputStreamReader risr = new InputStreamReader(is);
    //      BufferedReader br=new BufferedReader(risr);
    //      String line;
    //      while((line=br.readLine())!=null){
    //         strFiles.add(line);
    //      }

    String file = null;
    if (new File("stats-build.jar").exists()) {
        file = "stats-build.jar";
    } else {
        file = "target/stats-build.jar";
    }
    ZipInputStream zip = new ZipInputStream(new FileInputStream(file));
    while (true) {
        ZipEntry e = zip.getNextEntry();
        if (e == null)
            break;
        String name = e.getName();
        if (name.startsWith(path) && !name.endsWith("/")) {
            //            if (!name.startsWith("/")){
            //               name="/" + name;
            //            }
            strFiles.add(name);
        }
    }

    System.out.println("files:" + strFiles.toString());
    return strFiles;
}

From source file:org.cloudfoundry.tools.io.zip.ZipArchive.java

/**
 * Unzip the specified input stream into a folder.
 * //from w  ww.ja v a 2  s. c  om
 * @param inputStream the input stream to unzip (this must contain zip contents)
 * @param destination the destination folder
 * @see #unpack(File, Folder)
 */
public static void unpack(InputStream inputStream, Folder destination) {
    Assert.notNull(inputStream, "InputStream must not be null");
    Assert.notNull(destination, "Destination must not be null");
    destination.createIfMissing();
    ZipInputStream zip = new ZipInputStream(new BufferedInputStream(inputStream));
    try {
        InputStream noCloseZip = new NoCloseInputStream(zip);
        ZipEntry entry = zip.getNextEntry();
        while (entry != null) {
            if (entry.isDirectory()) {
                destination.getFolder(entry.getName()).createIfMissing();
            } else {
                destination.getFile(entry.getName()).getContent().write(noCloseZip);
            }
            entry = zip.getNextEntry();
        }
    } catch (IOException e) {
        throw new ResourceException(e);
    } finally {
        try {
            zip.close();
        } catch (IOException e) {
        }
    }
}

From source file:com.thinkbiganalytics.feedmgr.util.ImportUtil.java

public static Set<ImportComponentOption> inspectZipComponents(InputStream inputStream, ImportType importType)
        throws IOException {
    Set<ImportComponentOption> options = new HashSet<>();
    ZipInputStream zis = new ZipInputStream(inputStream);
    ZipEntry entry;//  w w w  .java  2s. c om
    while ((entry = zis.getNextEntry()) != null) {
        if (entry.getName().startsWith(ExportImportTemplateService.NIFI_TEMPLATE_XML_FILE)) {
            options.add(new ImportComponentOption(ImportComponent.NIFI_TEMPLATE,
                    importType.equals(ImportType.TEMPLATE) ? true : false));
        } else if (entry.getName().startsWith(ExportImportTemplateService.TEMPLATE_JSON_FILE)) {
            options.add(new ImportComponentOption(ImportComponent.TEMPLATE_DATA,
                    importType.equals(ImportType.TEMPLATE) ? true : false));
        } else if (entry.getName()
                .startsWith(ExportImportTemplateService.NIFI_CONNECTING_REUSABLE_TEMPLATE_XML_FILE)) {
            options.add(new ImportComponentOption(ImportComponent.REUSABLE_TEMPLATE, false));
        } else if (importType.equals(ImportType.FEED)
                && entry.getName().startsWith(ExportImportFeedService.FEED_JSON_FILE)) {
            options.add(new ImportComponentOption(ImportComponent.FEED_DATA, true));
            options.add(new ImportComponentOption(ImportComponent.USER_DATASOURCES, true));
        }
    }
    zis.closeEntry();
    zis.close();

    return options;
}