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();
            }
        }
Esempio n. 2
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();
                }
            }
        }
Esempio n. 3
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();
                }
            }
        }
        public void CacheClassBytes(FileInfo jar)
        {
            // experimental..
            try
            {
                Console.WriteLine(".cache: " + jar.FullName);

                var zip = default(ZipInputStream);


                zip = new ZipInputStream(new jvm::java.io.FileInputStream(jar.FullName));


                var Current = zip.getNextEntry();

                while (Current != null)
                {
                    var Name = Current.getName();

                    if (Name.EndsWith(".class"))
                    {
                        var TypeName = Name.Substring(0, Name.Length - ".class".Length).Replace("/", ".");

                        if (TypeName.StartsWith("java."))
                        {
                            // we cannot use ClassLoader to load such class anyhow..
                            // what we probably would need is a JVM parser now...
                        }
                        else
                        {
                            var Memory = zip.ReadToMemoryStream();

                            this.ClassBytes[TypeName] = Memory.ToArray();
                        }
                    }

                    Current = zip.getNextEntry();
                }
            }
            catch (jvm::csharp.ThrowableException cc)
            {
                Console.WriteLine("error @CacheClassBytes: " + cc);

                throw new InvalidOperationException();
            }
        }
        public void LoadFile(string path)
        {
            InternalEntries = null;

            var jar = new FileInfo(path);
            this.FileName = jar;

            #region clazzLoader
            this.clazzLoader = default(InternalURLClassLoader);

            try
            {
                //var filePath = "jar:file://" + jar.FullName + "!/";

                // http://download.oracle.com/javase/1.4.2/docs/api/java/io/File.html
                // file:///C:/util/aws-android-sdk-0.2.0/lib/aws-android-sdk-0.2.0-ec2.jar

                // error @URLClassLoader: java.net.MalformedURLException: unknown protocol: c
                var url = new jvm::java.io.File(jar.FullName).toURL();

                // http://www.javakb.com/Uwe/Forum.aspx/java-programmer/34778/URLClassLoader-ClassNotFoundException
                // http://www.chinaup.org/docs/reference/java/net/URLClassLoader.html
                // http://www.docjar.com/html/api/sun/applet/AppletClassLoader.java.html


                // http://www.docjar.com/html/api/java/net/URLClassLoader.java.html
                // http://www.docjar.com/html/api/java/security/SecureClassLoader.java.html

                clazzLoader = new InternalURLClassLoader(new URL[] { url }, null);

            }
            catch (jvm::csharp.ThrowableException ex)
            {
                Console.WriteLine("error @URLClassLoader: " + ex);
                throw new InvalidOperationException();
            }
            #endregion


            //clazzLoader.CacheClassBytes(jar);

            #region Resolve
            clazzLoader.Resolve =
                name =>
                {
                    var f = default(FileInfo);

                    if (this.JavaArchiveResolve != null)
                    {
                        f = this.JavaArchiveResolve(name);
                        //clazzLoader.CacheClassBytes(f);
                    }

                    return f;
                };
            #endregion




            #region GetDynamicEnumerator
            this.GetDynamicEnumerator = () =>
            {

                var zip = default(ZipInputStream);

                try
                {
                    zip = new ZipInputStream(new jvm::java.io.FileInputStream(jar.FullName));
                }
                catch
                {
                    Console.WriteLine("error @ ZipInputStream");
                    throw new InvalidOperationException();
                }

                return (GetNextEntry)
                    delegate
                    {
                        if (zip == null)
                            return null;

                        var e = default(ZipEntry);

                        try
                        {
                            e = zip.getNextEntry();
                        }
                        catch
                        {
                        }

                        if (e == null)
                            return null;



                        var n = new Entry { Name = e.getName() };

                        if (clazzLoader != null)
                            if (n.Name.EndsWith(".class"))
                            {
                                var TypeFullName = n.Name.Substring(0, n.Name.Length - ".class".Length).Replace("/", ".");

                                var NestedTypeName = TypeFullName.SkipUntilLastOrEmpty("$");

                                var NestedTypeNameStartsWithNumber = NestedTypeName.StartsWithNumber();

                                if (NestedTypeNameStartsWithNumber)
                                {
                                    // we should skip nested types with only numbers
                                    // as we might not be able to load them

                                }
                                else
                                {

                                    n.TypeFullName = TypeFullName;


                                    Console.WriteLine("JavaArchiveReflector.Loadfile.InternalGetType almost set for " + n.TypeFullName);

                                    n.InternalGetType = delegate
                                    {
                                        Console.WriteLine("JavaArchiveReflector.Loadfile.InternalGetType - " + n.TypeFullName);

                                        var c = default(jvm::java.lang.Class);


                                        try
                                        {
                                            //Console.WriteLine(".deprecated loadClass: " + n.TypeFullName);

                                            c = clazzLoader.loadClass(n.TypeFullName);
                                        }
                                        catch (jvm::csharp.ThrowableException cc)
                                        {
                                            Console.WriteLine("** JavaArchiveReflector.Loadfile - error loadClass: " + n.TypeFullName + "; " + cc);

                                            //throw new InvalidOperationException();
                                        }

                                        // what if we need javax.jms.MessageListener ?
                                        if (c == null)
                                        {
                                            return null;
                                        }

                                        // cant be more explicit:P
                                        return jvm::ScriptCoreLibJava.Extensions.BCLImplementationExtensions.ToType(c);
                                    };
                                }
                            }

                        return n;
                    };
            };
            #endregion
        }
        public void CacheClassBytes(FileInfo jar)
        {
            // experimental..
            try
            {
                Console.WriteLine(".cache: " + jar.FullName);

                var zip = default(ZipInputStream);


                zip = new ZipInputStream(new jvm::java.io.FileInputStream(jar.FullName));


                var Current = zip.getNextEntry();

                while (Current != null)
                {
                    var Name = Current.getName();

                    if (Name.EndsWith(".class"))
                    {
                        var TypeName = Name.Substring(0, Name.Length - ".class".Length).Replace("/", ".");

                        if (TypeName.StartsWith("java."))
                        {
                            // we cannot use ClassLoader to load such class anyhow..
                            // what we probably would need is a JVM parser now...
                        }
                        else
                        {
                            var Memory = zip.ReadToMemoryStream();

                            this.ClassBytes[TypeName] = Memory.ToArray();
                        }
                    }

                    Current = zip.getNextEntry();
                }

            }
            catch (jvm::csharp.ThrowableException cc)
            {
                Console.WriteLine("error @CacheClassBytes: " + cc);

                throw new InvalidOperationException();
            }
        }
        public void LoadFile(string path)
        {
            InternalEntries = null;

            var jar = new FileInfo(path);

            this.FileName = jar;

            #region clazzLoader
            this.clazzLoader = default(InternalURLClassLoader);

            try
            {
                //var filePath = "jar:file://" + jar.FullName + "!/";

                // http://download.oracle.com/javase/1.4.2/docs/api/java/io/File.html
                // file:///C:/util/aws-android-sdk-0.2.0/lib/aws-android-sdk-0.2.0-ec2.jar

                // error @URLClassLoader: java.net.MalformedURLException: unknown protocol: c
                var url = new jvm::java.io.File(jar.FullName).toURL();

                // http://www.javakb.com/Uwe/Forum.aspx/java-programmer/34778/URLClassLoader-ClassNotFoundException
                // http://www.chinaup.org/docs/reference/java/net/URLClassLoader.html
                // http://www.docjar.com/html/api/sun/applet/AppletClassLoader.java.html


                // http://www.docjar.com/html/api/java/net/URLClassLoader.java.html
                // http://www.docjar.com/html/api/java/security/SecureClassLoader.java.html

                clazzLoader = new InternalURLClassLoader(new URL[] { url }, null);
            }
            catch (jvm::csharp.ThrowableException ex)
            {
                Console.WriteLine("error @URLClassLoader: " + ex);
                throw new InvalidOperationException();
            }
            #endregion


            //clazzLoader.CacheClassBytes(jar);

            #region Resolve
            clazzLoader.Resolve =
                name =>
            {
                var f = default(FileInfo);

                if (this.JavaArchiveResolve != null)
                {
                    f = this.JavaArchiveResolve(name);
                    //clazzLoader.CacheClassBytes(f);
                }

                return(f);
            };
            #endregion



            #region GetDynamicEnumerator
            this.GetDynamicEnumerator = () =>
            {
                var zip = default(ZipInputStream);

                try
                {
                    zip = new ZipInputStream(new jvm::java.io.FileInputStream(jar.FullName));
                }
                catch
                {
                    Console.WriteLine("error @ ZipInputStream");
                    throw new InvalidOperationException();
                }

                return((GetNextEntry)
                       delegate
                {
                    if (zip == null)
                    {
                        return null;
                    }

                    var e = default(ZipEntry);

                    try
                    {
                        e = zip.getNextEntry();
                    }
                    catch
                    {
                    }

                    if (e == null)
                    {
                        return null;
                    }



                    var n = new Entry {
                        Name = e.getName()
                    };

                    if (clazzLoader != null)
                    {
                        if (n.Name.EndsWith(".class"))
                        {
                            var TypeFullName = n.Name.Substring(0, n.Name.Length - ".class".Length).Replace("/", ".");

                            var NestedTypeName = TypeFullName.SkipUntilLastOrEmpty("$");

                            var NestedTypeNameStartsWithNumber = NestedTypeName.StartsWithNumber();

                            if (NestedTypeNameStartsWithNumber)
                            {
                                // we should skip nested types with only numbers
                                // as we might not be able to load them
                            }
                            else
                            {
                                n.TypeFullName = TypeFullName;


                                Console.WriteLine("JavaArchiveReflector.Loadfile.InternalGetType almost set for " + n.TypeFullName);

                                n.InternalGetType = delegate
                                {
                                    Console.WriteLine("JavaArchiveReflector.Loadfile.InternalGetType - " + n.TypeFullName);

                                    var c = default(jvm::java.lang.Class);


                                    try
                                    {
                                        //Console.WriteLine(".deprecated loadClass: " + n.TypeFullName);

                                        c = clazzLoader.loadClass(n.TypeFullName);
                                    }
                                    catch (jvm::csharp.ThrowableException cc)
                                    {
                                        Console.WriteLine("** JavaArchiveReflector.Loadfile - error loadClass: " + n.TypeFullName + "; " + cc);

                                        //throw new InvalidOperationException();
                                    }

                                    // what if we need javax.jms.MessageListener ?
                                    if (c == null)
                                    {
                                        return null;
                                    }

                                    // cant be more explicit:P
                                    return jvm::ScriptCoreLibJava.Extensions.BCLImplementationExtensions.ToType(c);
                                };
                            }
                        }
                    }

                    return n;
                });
            };
            #endregion
        }
        /// <summary>
        /// Load Data into local _data
        /// </summary>
        /// <returns>bool type true if success</returns>
        private bool LoadLOBData()
        {
            //	Reset
            _items = new List <MAttachmentEntry>();
            // Get binaryData from DB
            byte[] data = GetBinaryData();

            // if no data, then return
            if (data == null)
            {
                return(true);
            }

            log.Fine("ZipSize=" + data.Length);
            if (data.Length == 0)
            {
                return(true);
            }

            //	Old Format - single file
            //here we store title in zip format
            //if (!ZIP.Equals(GetTitle()))
            //{
            //    _items.Add(new MAttachmentEntry(GetTitle(), data, 1));
            //    return true;
            //}
            // convert byte[] to byte[] data
            byte[] sdata = ConvertTobyte(data);
            try
            {
                ByteArrayInputStream inBt = new ByteArrayInputStream(sdata);
                // initialize zip
                ZipInputStream zip = new ZipInputStream(inBt);
                // get next entry i.e. 1st entry in zip
                ZipEntry entry = zip.getNextEntry();
                // for every entry in zip
                while (entry != null)
                {
                    // get file name
                    string name = entry.getName();
                    ByteArrayOutputStream outBt = new ByteArrayOutputStream();
                    byte[] buffer = new byte[2048];
                    int    length = zip.read(buffer);
                    while (length != -1)
                    {
                        // get data
                        outBt.write(buffer, 0, length);
                        length = zip.read(buffer);
                    }
                    //
                    byte[] sdataEntry = outBt.toByteArray();
                    byte[] dataEntry  = ConvertToByte(sdataEntry);

                    try
                    {
                        log.Fine(name
                                 + " - size=" + dataEntry.Length + " - zip="
                                 + entry.getCompressedSize() + "(" + entry.getSize() + ") "
                                 + (entry.getCompressedSize() * 100 / entry.getSize()) + "%");
                    }
                    catch { }


                    // add the entry into _items list
                    _items.Add(new MAttachmentEntry(name, dataEntry, _items.Count + 1));
                    // get next entry in zip
                    entry = zip.getNextEntry();
                }
            }
            catch (Exception ex)
            {
                log.Log(Level.SEVERE, "loadLOBData", ex);
                _items = null;
                return(false);
            }
            return(true);
        }
Esempio n. 9
0
		public static bool isZip(System.IO.Stream in_Renamed)
		{
			try
			{
				//UPGRADE_ISSUE: Class 'java.util.zip.ZipInputStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipZipInputStream'"
				//UPGRADE_ISSUE: Constructor 'java.util.zip.ZipInputStream.ZipInputStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipZipInputStream'"
				ZipInputStream swcZipInputStream = new ZipInputStream(in_Renamed);
				//UPGRADE_ISSUE: Method 'java.util.zip.ZipInputStream.getNextEntry' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipZipInputStream'"
				swcZipInputStream.getNextEntry();
				return true;
			}
			catch (System.IO.IOException e)
			{
				return false;
			}
		}
Esempio n. 10
0
		private static void  dumpZip(System.IO.StreamWriter out_Renamed, System.Uri url, System.String outfile)
		{
			System.IO.Stream in_Renamed = new System.IO.BufferedStream(System.Net.WebRequest.Create(url).GetResponse().GetResponseStream());
			try
			{
				//UPGRADE_ISSUE: Class 'java.util.zip.ZipInputStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipZipInputStream'"
				//UPGRADE_ISSUE: Constructor 'java.util.zip.ZipInputStream.ZipInputStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipZipInputStream'"
				ZipInputStream zipIn = new ZipInputStream(in_Renamed);
				//UPGRADE_ISSUE: Class 'java.util.zip.ZipEntry' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipZipEntry'"
				//UPGRADE_ISSUE: Method 'java.util.zip.ZipInputStream.getNextEntry' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipZipInputStream'"
				ZipEntry zipEntry = zipIn.getNextEntry();
				while ((zipEntry != null))
				{
					//UPGRADE_TODO: Class 'java.net.URL' was converted to a 'System.Uri' which does not throw an exception if a URL specifies an unknown protocol. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1132'"
					//UPGRADE_ISSUE: Method 'java.util.zip.ZipEntry.getName' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipZipEntry'"
					System.Uri fileUrl = new System.Uri("jar:" + url.ToString() + "!/" + zipEntry.getName());
					if (isSwf(fileUrl))
						dumpSwf(out_Renamed, fileUrl, outfile);
					//UPGRADE_ISSUE: Method 'java.util.zip.ZipInputStream.getNextEntry' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipZipInputStream'"
					zipEntry = zipIn.getNextEntry();
				}
			}
			finally
			{
				in_Renamed.Close();
			}
		}
Esempio n. 11
0
        public JavaArchiveReflector(FileInfo jar)
        {
            this.FileName = jar;

            var clazzLoader = default(URLClassLoader);

            try
            {
                var filePath = "jar:file://" + jar.FullName + "!/";
                var url      = new java.io.File(filePath).toURL();


                clazzLoader = new URLClassLoader(new URL[] { url });
            }
            catch
            {
            }



            this.GetDynamicEnumerator = () =>
            {
                var zip = default(ZipInputStream);

                try
                {
                    zip = new ZipInputStream(new FileInputStream(jar.FullName));
                }
                catch
                {
                }

                return((GetNextEntry)
                       delegate
                {
                    if (zip == null)
                    {
                        return null;
                    }

                    var e = default(ZipEntry);

                    try
                    {
                        e = zip.getNextEntry();
                    }
                    catch
                    {
                    }

                    if (e == null)
                    {
                        return null;
                    }



                    var n = new Entry {
                        Name = e.getName()
                    };

                    if (clazzLoader != null)
                    {
                        if (n.Name.EndsWith(".class"))
                        {
                            n.TypeFullName = n.Name.Substring(0, n.Name.Length - ".class".Length).Replace("/", ".");


                            n.InternalGetType = delegate
                            {
                                var c = default(java.lang.Class);

                                try
                                {
                                    c = clazzLoader.loadClass(n.TypeFullName.Replace(".", "/"));
                                }
                                catch (csharp.ThrowableException cc)
                                {
                                    System.Console.WriteLine("error: " + cc);
                                }

                                return c.ToType();
                            };
                        }
                    }

                    return n;
                });
            };
        }