Пример #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: protected Class fetchNextOrNull() throws java.io.IOException
            protected internal override Type fetchNextOrNull()
            {
                try
                {
                    while (true)
                    {
                        ZipEntry nextEntry = _zip.NextEntry;
                        if (nextEntry == null)
                        {
                            _zip.close();
                            return(null);
                        }

                        string name = nextEntry.Name;
                        if (name.EndsWith(".class", StringComparison.Ordinal))
                        {
                            string className = name.Substring(0, name.Length - ".class".Length).Replace('/', '.');

                            try
                            {
                                Type aClass = _loader.loadClass(className);
                                // We do getDeclaredMethods to trigger NoClassDefErrors, which loadClass above does
                                // not do.
                                // This way, even if some of the classes in a jar cannot be loaded, we still check
                                // the others.
                                aClass.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
                                return(aClass);
                            }
                            catch (Exception e) when(e is UnsatisfiedLinkError || e is NoClassDefFoundError || e is Exception)
                            {
                                _outerInstance.log.warn("Failed to load `%s` from plugin jar `%s`: %s", className, _jar.File, e.Message);
                            }
                        }
                    }
                }
                catch (Exception e) when(e is IOException || e is Exception)
                {
                    _zip.close();
                    throw e;
                }
            }
Пример #4
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();
                }
            }
        }