Esempio n. 1
0
        public void Load(string jarFile)
        {
            if (!IsJarFile(jarFile))
            {
                throw new ArgumentException("'jarFile' is not a valid .jar file.", "jarFile");
            }

            using (var jar = CreateZipArchive(jarFile)) {
                foreach (var entry in jar.Entries)
                {
                    if (entry.Length == 0)
                    {
                        continue;
                    }
                    using (var s = entry.Open()) {
                        if (!ClassFile.IsClassFile(s))
                        {
                            continue;
                        }
                    }
                    using (var s = entry.Open()) {
                        try {
                            var c = new ClassFile(s);
                            Add(c);
                        } catch (Exception e) {
                            Log.Warning(0, "class-parse: warning: Could not load .jar entry '{0}': {1}",
                                        entry.Name, e);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void Load(Stream jarStream, bool leaveOpen = false)
        {
            if (jarStream == null)
            {
                throw new ArgumentNullException(nameof(jarStream));
            }

            using (var jar = CreateZipArchive(jarStream, leaveOpen)) {
                foreach (var entry in jar.Entries)
                {
                    if (entry.Length == 0)
                    {
                        continue;
                    }
                    using (var s = entry.Open()) {
                        if (!ClassFile.IsClassFile(s) || entry.Name.EndsWith(".jnilib", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }
                    }
                    using (var s = entry.Open()) {
                        try {
                            var c = new ClassFile(s);
                            Add(c);
                        } catch (Exception e) {
                            Log.Warning(0, "class-parse: warning: Could not load .jar entry '{0}': {1}",
                                        entry.Name, e);
                        }
                    }
                }
            }
        }