コード例 #1
0
        /// <summary>
        /// Reads the zip stream.
        /// </summary>
        /// <param name="jInputStream">The j input stream.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="rock">The rock.</param>
        public static void ReadZipStream(java.io.InputStream jInputStream, CallbackZip callback, object rock)
        {
            ZipInputStream zis = null;

            try
            {
                zis = new ZipInputStream(jInputStream);

                ZipEntry  entry;
                ZipEntryE extendedEntry;
                while ((entry = zis.getNextEntry()) != null)
                {
                    extendedEntry = new ZipEntryE(entry);
                    callback(extendedEntry, new ZipEntryInputStream(zis), rock);

                    // Close the entry that we read
                    zis.closeEntry();
                }
            }
            finally
            {
                if (zis != null)
                {
                    zis.close();
                }
            }
        }
コード例 #2
0
        public void unZipIt(File folder, File zipFile)
        {
            //        List<File> files = new ArrayList<>();

            byte[] buffer = new byte[1024];

            try
            {
                //create output directory is not exists
                if (!folder.exists())
                {
                    folder.mkdir();
                }
                folder.deleteOnExit();

                //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(folder + File.separator + fileName);
                    newFile.deleteOnExit();
                    //                files.add(newFile);

                    //                logger.info("file unzip : " + newFile.getAbsoluteFile());
                    //create all non exists folders
                    //else you will hit FileNotFoundException for compressed folder
                    new File(newFile.getParent()).mkdirs();

                    FileOutputStream fos = new FileOutputStream(newFile);

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

                    //                files.add(newFile);
                    fos.close();
                    ze = zis.getNextEntry();
                }

                zis.closeEntry();
                zis.close();
            }
            catch (IOException ex)
            {
                ex.printStackTrace();
            }
        }
コード例 #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static java.io.File unzip(Class testClass, String resource, java.io.File targetDirectory) throws java.io.IOException
//JAVA TO C# CONVERTER NOTE: Members cannot have the same name as their enclosing type:
        public static File UnzipConflict(Type testClass, string resource, File targetDirectory)
        {
            Stream source = testClass.getResourceAsStream(resource);

            if (source == null)
            {
                throw new FileNotFoundException("Could not find resource '" + resource + "' to unzip");
            }

            try
            {
                using (ZipInputStream zipStream = new ZipInputStream(source))
                {
                    ZipEntry entry;
                    sbyte[]  scratch = new sbyte[8096];
                    while ((entry = zipStream.NextEntry) != null)
                    {
                        if (entry.Directory)
                        {
                            (new File(targetDirectory, entry.Name)).mkdirs();
                        }
                        else
                        {
                            using (Stream file = new BufferedOutputStream(new FileStream(targetDirectory, entry.Name, FileMode.Create, FileAccess.Write)))
                            {
                                long toCopy = entry.Size;
                                while (toCopy > 0)
                                {
                                    int read = zipStream.read(scratch);
                                    file.Write(scratch, 0, read);
                                    toCopy -= read;
                                }
                            }
                        }
                        zipStream.closeEntry();
                    }
                }
            }
            finally
            {
                source.Close();
            }
            return(targetDirectory);
        }
コード例 #4
0
ファイル: Archiver.cs プロジェクト: Yitzchok/PublicDomain
        /// <summary>
        /// Reads the zip stream.
        /// </summary>
        /// <param name="jInputStream">The j input stream.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="rock">The rock.</param>
        public static void ReadZipStream(java.io.InputStream jInputStream, CallbackZip callback, object rock)
        {
            ZipInputStream zis = null;
            try
            {
                zis = new ZipInputStream(jInputStream);

                ZipEntry entry;
                ZipEntryE extendedEntry;
                while ((entry = zis.getNextEntry()) != null)
                {
                    extendedEntry = new ZipEntryE(entry);
                    callback(extendedEntry, new ZipEntryInputStream(zis), rock);

                    // Close the entry that we read
                    zis.closeEntry();
                }
            }
            finally
            {
                if (zis != null)
                {
                    zis.close();
                }
            }
        }